diff --git a/app/api/storage/files/content/route.ts b/app/api/storage/files/content/route.ts index d3beb241..7d037897 100644 --- a/app/api/storage/files/content/route.ts +++ b/app/api/storage/files/content/route.ts @@ -60,6 +60,7 @@ export async function GET(request: Request) { else if (path.includes('/Contacts/')) folder = 'contacts'; else if (path.includes('/Health/')) folder = 'health'; + // Use direct user path without pages prefix key = `user-${userId}/${folder}/${file}`; console.log('Converted NextCloud path to S3 key:', { path, key }); } else { diff --git a/app/api/storage/files/route.ts b/app/api/storage/files/route.ts index 5b519ed1..45b0f0db 100644 --- a/app/api/storage/files/route.ts +++ b/app/api/storage/files/route.ts @@ -73,7 +73,8 @@ export async function POST(request: Request) { const normalizedFolder = folder.toLowerCase(); // Create the full key (path) for the S3 object - const key = `pages/user-${userId}/${normalizedFolder}/${title}${title.endsWith('.md') ? '' : '.md'}`; + // Remove 'pages/' prefix since it's already the bucket name + const key = `user-${userId}/${normalizedFolder}/${title}${title.endsWith('.md') ? '' : '.md'}`; console.log('Creating file in S3:', { key, contentLength: content.length }); @@ -113,7 +114,8 @@ export async function PUT(request: Request) { return NextResponse.json({ error: 'Missing required fields', received: { title: !!title, folder: !!folder } }, { status: 400 }); } const normalizedFolder = folder.toLowerCase(); - key = `pages/user-${userId}/${normalizedFolder}/${title}${title.endsWith('.md') ? '' : '.md'}`; + // Remove 'pages/' prefix since it's already the bucket name + key = `user-${userId}/${normalizedFolder}/${title}${title.endsWith('.md') ? '' : '.md'}`; } console.log('Updating file in S3:', { key, contentLength: content?.length }); diff --git a/app/api/storage/init/folder/route.ts b/app/api/storage/init/folder/route.ts index 16fdb4f2..d7840766 100644 --- a/app/api/storage/init/folder/route.ts +++ b/app/api/storage/init/folder/route.ts @@ -38,11 +38,11 @@ export async function POST(request: Request) { try { // Create the folder path (just a prefix in S3) - const key = `pages/user-${userId}/${folderLowercase}/`; + const key = `user-${userId}/${folderLowercase}/`; await putObject(key, '', 'application/x-directory'); // Create a placeholder file to ensure the folder exists and is visible - const placeholderKey = `pages/user-${userId}/${folderLowercase}/.placeholder`; + const placeholderKey = `user-${userId}/${folderLowercase}/.placeholder`; await putObject(placeholderKey, 'Folder placeholder', 'text/plain'); console.log(`Successfully created folder: ${key}`); diff --git a/app/api/storage/status/route.ts b/app/api/storage/status/route.ts index c62c3910..05099bf9 100644 --- a/app/api/storage/status/route.ts +++ b/app/api/storage/status/route.ts @@ -46,7 +46,7 @@ export async function GET() { // List folders in the user's path try { // Using the user prefix to list all folders - const prefix = `pages/user-${userId}/`; + const prefix = `user-${userId}/`; const command = new ListObjectsV2Command({ Bucket: S3_CONFIG.bucket, Prefix: prefix, diff --git a/app/pages/page.tsx b/app/pages/page.tsx index fa9adf4c..84604894 100644 --- a/app/pages/page.tsx +++ b/app/pages/page.tsx @@ -296,7 +296,7 @@ export default function CarnetPage() { setIsSaving(true); // Construct API payload with lowercase folder name const payload = { - id: note.id || `pages/user-${session?.user?.id}/${selectedFolder.toLowerCase()}/${note.title}${note.title.endsWith('.md') ? '' : '.md'}`, + id: note.id || `user-${session?.user?.id}/${selectedFolder.toLowerCase()}/${note.title}${note.title.endsWith('.md') ? '' : '.md'}`, title: note.title, content: note.content, folder: selectedFolder.toLowerCase(), // Use lowercase for storage consistency diff --git a/lib/s3.ts b/lib/s3.ts index 084b3e41..c45a6569 100644 --- a/lib/s3.ts +++ b/lib/s3.ts @@ -68,8 +68,8 @@ console.log('S3 Configuration:', { // List objects in a "folder" for a specific user export async function listUserObjects(userId: string, folder: string) { try { - // Updated to include 'pages/' prefix in the path - const prefix = `pages/user-${userId}/${folder}/`; + // Remove the 'pages/' prefix since it's already the bucket name + const prefix = `user-${userId}/${folder}/`; console.log(`Listing objects with prefix: ${prefix}`); const command = new ListObjectsV2Command({ @@ -172,12 +172,13 @@ export async function createUserFolderStructure(userId: string) { for (const folder of folders) { try { // Create the folder path (just a prefix in S3) - const key = `pages/user-${userId}/${folder}/`; + // Remove the 'pages/' prefix since it's already the bucket name + const key = `user-${userId}/${folder}/`; console.log(`Creating folder: ${key}`); await putObject(key, '', 'application/x-directory'); // Create a placeholder file to ensure the folder exists and is visible - const placeholderKey = `pages/user-${userId}/${folder}/.placeholder`; + const placeholderKey = `user-${userId}/${folder}/.placeholder`; await putObject(placeholderKey, 'Folder placeholder', 'text/plain'); results.push(folder);