NeahNew/app/api/storage/init/route.ts
2025-05-04 14:16:58 +02:00

33 lines
1.1 KiB
TypeScript

import { NextResponse } from 'next/server';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
import { createUserFolderStructure } from '@/lib/s3';
export async function POST(request: Request) {
try {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
console.log(`Initializing storage for user: ${session.user.id}`);
// Create folder structure for the user
await createUserFolderStructure(session.user.id);
// Update the session to indicate storage is initialized
// This is handled client-side since we can't modify the session directly here
// Return success response
return NextResponse.json({
success: true,
message: 'Storage initialized successfully'
});
} catch (error) {
console.error('Storage initialization failed:', error);
return NextResponse.json({
error: 'Failed to initialize storage',
details: error instanceof Error ? error.message : 'Unknown error'
}, { status: 500 });
}
}