Spaces:
Running
Running
| import { NextRequest, 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(request: NextRequest) { | |
| try { | |
| const searchParams = request.nextUrl.searchParams | |
| const name = searchParams.get('name') | |
| if (!name) { | |
| return NextResponse.json( | |
| { success: false, error: 'App name is required' }, | |
| { status: 400 } | |
| ) | |
| } | |
| // Sanitize name | |
| const safeName = name.replace(/[^a-zA-Z0-9_-]/g, '_').toLowerCase() | |
| const fileName = `${safeName}.flutter.json` | |
| const filePath = path.join(FLUTTER_APPS_DIR, fileName) | |
| if (!fs.existsSync(filePath)) { | |
| return NextResponse.json( | |
| { success: false, error: `Flutter app '${safeName}' not found` }, | |
| { status: 404 } | |
| ) | |
| } | |
| const fileContent = fs.readFileSync(filePath, 'utf-8') | |
| const appData = JSON.parse(fileContent) | |
| return NextResponse.json({ | |
| success: true, | |
| appName: safeName, | |
| appData | |
| }) | |
| } catch (error) { | |
| console.error('Error getting Flutter app:', error) | |
| return NextResponse.json( | |
| { success: false, error: 'Failed to get Flutter app' }, | |
| { status: 500 } | |
| ) | |
| } | |
| } | |