pages s3
This commit is contained in:
parent
1fa83110a3
commit
a3bc5871c3
33
app/api/debug/create-all-folders/route.ts
Normal file
33
app/api/debug/create-all-folders/route.ts
Normal file
@ -0,0 +1,33 @@
|
||||
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 GET(request: Request) {
|
||||
try {
|
||||
// Get session
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const userId = session.user.id;
|
||||
|
||||
console.log(`Manually creating all folders for user: ${userId}`);
|
||||
|
||||
// Create the folder structure for the user
|
||||
const result = await createUserFolderStructure(userId);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: 'All folders created successfully',
|
||||
userId
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error creating folders:', error);
|
||||
return NextResponse.json({
|
||||
error: 'Failed to create folders',
|
||||
message: error instanceof Error ? error.message : String(error)
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
@ -130,10 +130,27 @@ export default function CarnetPage() {
|
||||
if (status === "unauthenticated") {
|
||||
redirect("/signin");
|
||||
}
|
||||
if (status === "authenticated" && session?.user?.id) {
|
||||
// Initialize all folders when user logs in
|
||||
fetch('/api/storage/init', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
console.log('All folders initialized successfully');
|
||||
} else {
|
||||
console.error('Failed to initialize folders');
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error('Error initializing folders:', error);
|
||||
});
|
||||
}
|
||||
if (status !== "loading") {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [status]);
|
||||
}, [status, session?.user?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isSmallScreen) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user