diff --git a/src/routes/api/scripts/+server.ts b/src/routes/api/scripts/+server.ts index c98d28d..ddb2eb8 100644 --- a/src/routes/api/scripts/+server.ts +++ b/src/routes/api/scripts/+server.ts @@ -44,12 +44,13 @@ export async function GET() { } // Multipart POST — creates a script + version 1 from a single file upload. -// Fields: name (text), targetRelPath (text), scopeType (optional: 'game'|'map'), -// scopeValue (optional string), notes (optional), content (file). +// Fields: name (text), scopeType (optional: 'game'|'map'), scopeValue +// (optional string), notes (optional), content (file). The target rel path +// defaults to the uploaded filename — T5 servers keep all scripts in a flat +// sp/ directory, so there's no sub-path to specify. export async function POST({ request }: { request: Request }) { const form = await request.formData(); const name = String(form.get('name') ?? '').trim(); - const targetRelPath = String(form.get('targetRelPath') ?? '').trim(); const notes = form.get('notes') ? String(form.get('notes')) : undefined; let scopeType: ScopeType | null; try { @@ -62,6 +63,7 @@ export async function POST({ request }: { request: Request }) { const file = form.get('content'); if (!(file instanceof File)) return json({ ok: false, error: 'content file is required' }, { status: 400 }); + const targetRelPath = file.name; const content = Buffer.from(await file.arrayBuffer()); try { diff --git a/src/routes/scripts/+page.svelte b/src/routes/scripts/+page.svelte index d507041..66223d2 100644 --- a/src/routes/scripts/+page.svelte +++ b/src/routes/scripts/+page.svelte @@ -27,7 +27,6 @@ // Form state for creating a new script. let newName = $state(''); - let newTargetRelPath = $state(''); let newScopeType = $state<'none' | 'game' | 'map'>('none'); let newScopeValue = $state(''); let newFile = $state(null); @@ -45,18 +44,18 @@ function pickFile(e: Event): void { const t = e.target as HTMLInputElement; newFile = t.files?.[0] ?? null; - if (!newTargetRelPath && newFile) newTargetRelPath = newFile.name; + // Every T5 script lands in a flat sp/ directory, so target rel path is + // just the filename — no need to ask the user. if (!newName && newFile) newName = newFile.name.replace(/\.[^.]+$/, ''); } async function createScript(e: Event): Promise { e.preventDefault(); - if (uploading || !newFile || !newName.trim() || !newTargetRelPath.trim()) return; + if (uploading || !newFile || !newName.trim()) return; uploading = true; flash = null; const form = new FormData(); form.append('name', newName.trim()); - form.append('targetRelPath', newTargetRelPath.trim()); form.append('scopeType', newScopeType); if (newScopeValue.trim()) form.append('scopeValue', newScopeValue.trim()); if (newNotes.trim()) form.append('notes', newNotes.trim()); @@ -69,7 +68,6 @@ return; } newName = ''; - newTargetRelPath = ''; newScopeType = 'none'; newScopeValue = ''; newNotes = ''; @@ -95,10 +93,6 @@ name -