This commit is contained in:
alma 2025-05-04 15:51:31 +02:00
parent dc4283a002
commit 3ffc32b513
6 changed files with 14 additions and 10 deletions

View File

@ -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 {

View File

@ -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 });

View File

@ -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}`);

View File

@ -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,

View File

@ -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

View File

@ -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);