▍ humdrum codex / soft
472 B raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
"use client";

export async function uploadImport(file: File): Promise<void> {
  const text = await file.text();

  // validate JSON before upload for a clearer error
  try {
    JSON.parse(text);
  } catch {
    throw new Error("File is not valid JSON");
  }

  const res = await fetch("/api/import", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: text,
  });

  if (!res.ok) throw new Error(`Import failed: ${await res.text()}`);
}