Spaces:
Running
Running
| import { NextResponse } from 'next/server' | |
| import fs from 'fs' | |
| import path from 'path' | |
| const DATA_DIR = process.env.NODE_ENV === 'production' && fs.existsSync('/data') | |
| ? '/data' | |
| : path.join(process.cwd(), 'data') | |
| const FLUTTER_APPS_DIR = path.join(DATA_DIR, 'documents', 'flutter_apps') | |
| export async function GET() { | |
| try { | |
| if (!fs.existsSync(FLUTTER_APPS_DIR)) { | |
| return NextResponse.json({ | |
| success: true, | |
| apps: [], | |
| count: 0 | |
| }) | |
| } | |
| const files = fs.readdirSync(FLUTTER_APPS_DIR) | |
| const apps = [] | |
| for (const file of files) { | |
| if (file.endsWith('.flutter.json')) { | |
| try { | |
| const filePath = path.join(FLUTTER_APPS_DIR, file) | |
| const fileContent = fs.readFileSync(filePath, 'utf-8') | |
| const appData = JSON.parse(fileContent) | |
| apps.push({ | |
| name: appData.name || file.replace('.flutter.json', ''), | |
| created: appData.metadata?.created, | |
| modified: appData.metadata?.modified, | |
| dependenciesCount: appData.dependencies?.length || 0, | |
| filePath: `flutter_apps/${file}` | |
| }) | |
| } catch (error) { | |
| // Skip malformed files | |
| console.error(`Error parsing ${file}:`, error) | |
| continue | |
| } | |
| } | |
| } | |
| return NextResponse.json({ | |
| success: true, | |
| apps, | |
| count: apps.length | |
| }) | |
| } catch (error) { | |
| console.error('Error listing Flutter apps:', error) | |
| return NextResponse.json( | |
| { success: false, error: 'Failed to list Flutter apps' }, | |
| { status: 500 } | |
| ) | |
| } | |
| } | |