import { NextResponse } from 'next/server'; import { getServerSession } from 'next-auth'; import { authOptions } from '@/app/api/auth/[...nextauth]/route'; import { getNextCloudService } from '@/lib/nextcloud-utils'; export async function GET() { console.log('🔍 Test endpoint called - Starting execution'); try { // Check session console.log('👤 Checking user session...'); const session = await getServerSession(authOptions); if (!session?.user?.email) { console.error('❌ No valid session found'); return NextResponse.json( { error: 'Unauthorized - No valid session' }, { status: 401 } ); } console.log('✅ Session validated for user:', session.user.email); // Initialize NextCloud service console.log('🔄 Initializing NextCloud service...'); const service = await getNextCloudService(); console.log('✅ NextCloud service initialized'); // Initialize user folders console.log('📁 Initializing user folders...'); await service.initializeUserFolders(session.user.email); console.log('✅ User folders initialized'); // List notes console.log('📝 Attempting to list notes...'); const notes = await service.listNotes(session.user.email); console.log('✅ Notes retrieved successfully:', notes.length, 'notes found'); return NextResponse.json({ status: 'success', message: 'Test completed successfully', data: { userEmail: session.user.email, notesCount: notes.length, notes: notes } }); } catch (error) { console.error('❌ Test failed with error:', error); return NextResponse.json( { error: 'Test failed', details: error instanceof Error ? error.message : 'Unknown error' }, { status: 500 } ); } }