Pages corrections
This commit is contained in:
parent
b8078a261f
commit
817dffda9c
@ -37,15 +37,14 @@ export async function POST(request: Request) {
|
|||||||
console.log(`Creating folder ${folderLowercase} for user ${userId}`);
|
console.log(`Creating folder ${folderLowercase} for user ${userId}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create the folder path (just a prefix in S3)
|
// In S3/MinIO, folders are just prefixes, so we don't need to create an empty object.
|
||||||
const key = `user-${userId}/${folderLowercase}/`;
|
// We only create a placeholder file to mark the folder as initialized.
|
||||||
await putObject(key, '', 'application/x-directory');
|
|
||||||
|
|
||||||
// Create a placeholder file to ensure the folder exists and is visible
|
|
||||||
const placeholderKey = `user-${userId}/${folderLowercase}/.placeholder`;
|
const placeholderKey = `user-${userId}/${folderLowercase}/.placeholder`;
|
||||||
await putObject(placeholderKey, 'Folder placeholder', 'text/plain');
|
const placeholderContent = `Folder initialized at ${new Date().toISOString()}`;
|
||||||
|
|
||||||
console.log(`Successfully created folder: ${key}`);
|
await putObject(placeholderKey, placeholderContent, 'text/plain');
|
||||||
|
|
||||||
|
console.log(`Successfully created folder: user-${userId}/${folderLowercase}/`);
|
||||||
|
|
||||||
// Return success
|
// Return success
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
@ -54,7 +53,10 @@ export async function POST(request: Request) {
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error creating folder ${folderLowercase}:`, error);
|
console.error(`Error creating folder ${folderLowercase}:`, error);
|
||||||
return NextResponse.json({ error: 'Failed to create folder' }, { status: 500 });
|
return NextResponse.json({
|
||||||
|
error: 'Failed to create folder',
|
||||||
|
details: error instanceof Error ? error.message : String(error)
|
||||||
|
}, { status: 500 });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in folder creation endpoint:', error);
|
console.error('Error in folder creation endpoint:', error);
|
||||||
|
|||||||
33
lib/s3.ts
33
lib/s3.ts
@ -43,11 +43,17 @@ export async function putObject(
|
|||||||
): Promise<{ key: string; url?: string }> {
|
): Promise<{ key: string; url?: string }> {
|
||||||
// Convert string to Buffer consistently, exactly like mission-uploads.ts
|
// Convert string to Buffer consistently, exactly like mission-uploads.ts
|
||||||
// This ensures the same encoding and buffer handling that works for mission attachments
|
// This ensures the same encoding and buffer handling that works for mission attachments
|
||||||
const buffer = typeof content === 'string'
|
// For empty strings, use an empty buffer instead of Buffer.from('') to avoid MinIO issues
|
||||||
? Buffer.from(content, 'utf-8')
|
let buffer: Buffer;
|
||||||
: Buffer.isBuffer(content)
|
if (typeof content === 'string') {
|
||||||
? content
|
buffer = content.length > 0
|
||||||
: Buffer.from(content);
|
? Buffer.from(content, 'utf-8')
|
||||||
|
: Buffer.alloc(0);
|
||||||
|
} else if (Buffer.isBuffer(content)) {
|
||||||
|
buffer = content;
|
||||||
|
} else {
|
||||||
|
buffer = Buffer.from(content);
|
||||||
|
}
|
||||||
|
|
||||||
// Use the same pattern as mission-uploads.ts: direct s3Client.send with PutObjectCommand
|
// Use the same pattern as mission-uploads.ts: direct s3Client.send with PutObjectCommand
|
||||||
await s3Client.send(new PutObjectCommand({
|
await s3Client.send(new PutObjectCommand({
|
||||||
@ -148,21 +154,24 @@ export function getPublicUrl(filePath: string, bucket?: string): string {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create standard folder structure for a user
|
* Create standard folder structure for a user
|
||||||
|
* In S3/MinIO, folders don't need to be explicitly created - they exist as prefixes.
|
||||||
|
* We only create a placeholder file to mark the folder as initialized.
|
||||||
*/
|
*/
|
||||||
export async function createUserFolderStructure(userId: string): Promise<void> {
|
export async function createUserFolderStructure(userId: string): Promise<void> {
|
||||||
const folders = ['notes', 'diary', 'health', 'contacts'];
|
const folders = ['notes', 'diary', 'health', 'contacts'];
|
||||||
|
|
||||||
for (const folder of folders) {
|
for (const folder of folders) {
|
||||||
try {
|
try {
|
||||||
// Create folder path (prefix in S3)
|
// In S3/MinIO, folders are just prefixes, so we don't need to create an empty object.
|
||||||
const folderKey = `user-${userId}/${folder}/`;
|
// We only create a placeholder file to mark the folder as initialized.
|
||||||
await putObject(folderKey, '', 'application/x-directory');
|
|
||||||
|
|
||||||
// Create placeholder file to ensure folder is visible
|
|
||||||
const placeholderKey = `user-${userId}/${folder}/.placeholder`;
|
const placeholderKey = `user-${userId}/${folder}/.placeholder`;
|
||||||
await putObject(placeholderKey, 'Folder placeholder', 'text/plain');
|
|
||||||
|
|
||||||
console.log(`Created folder: ${folderKey}`);
|
// Use a simple text content for the placeholder
|
||||||
|
const placeholderContent = `Folder initialized at ${new Date().toISOString()}`;
|
||||||
|
|
||||||
|
await putObject(placeholderKey, placeholderContent, 'text/plain');
|
||||||
|
|
||||||
|
console.log(`Created folder: user-${userId}/${folder}/`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error creating folder ${folder} for user ${userId}:`, error);
|
console.error(`Error creating folder ${folder} for user ${userId}:`, error);
|
||||||
// Continue with other folders even if one fails
|
// Continue with other folders even if one fails
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user