fix: move upload endpoint to root /upload route (works from both app and atelier)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yusuf Suleman
2026-04-01 21:44:46 -05:00
parent b09fa0b42b
commit f94987ac1b
2 changed files with 0 additions and 117 deletions

View File

@@ -0,0 +1,25 @@
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import fs from 'fs';
import path from 'path';
const UPLOAD_DIR = '/app/screenshots';
export const POST: RequestHandler = async ({ request }) => {
const formData = await request.formData();
const file = formData.get('file') as File;
if (!file) return json({ error: 'No file' }, { status: 400 });
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
const ext = file.name.split('.').pop() || 'png';
const filename = `${timestamp}.${ext}`;
const buffer = Buffer.from(await file.arrayBuffer());
// Ensure directory exists
if (!fs.existsSync(UPLOAD_DIR)) fs.mkdirSync(UPLOAD_DIR, { recursive: true });
fs.writeFileSync(path.join(UPLOAD_DIR, filename), buffer);
return json({ ok: true, filename, path: `/app/screenshots/${filename}` });
};