gpt-engineer-app[bot] commited on
Commit
080b5cc
·
1 Parent(s): c5424aa
Files changed (1) hide show
  1. src/components/upload-dialog.tsx +2 -8
src/components/upload-dialog.tsx CHANGED
@@ -25,9 +25,6 @@ export function UploadDialog({ onCreated }: { onCreated?: (id: string) => void }
25
  const submit = async () => {
26
  setBusy(true);
27
  try {
28
- const { data: u } = await supabase.auth.getUser();
29
- if (!u.user) throw new Error("Not authenticated");
30
-
31
  let raw_text: string | null = null;
32
  let file_url: string | null = null;
33
  let file_name: string | null = null;
@@ -42,18 +39,15 @@ export function UploadDialog({ onCreated }: { onCreated?: (id: string) => void }
42
  const ext = file.name.split(".").pop()?.toLowerCase() ?? "";
43
  source_type = ext === "pdf" ? "pdf" : ["mp4","mov","webm","avi","mkv"].includes(ext) ? "video" : "file";
44
 
45
- // Upload to storage
46
- const path = `${u.user.id}/${Date.now()}-${file.name}`;
47
  const { error: upErr } = await supabase.storage.from("incident-files").upload(path, file);
48
  if (upErr) throw upErr;
49
  file_url = path;
50
 
51
- // Extract text for plain text-ish files
52
  if (["txt","csv","json","log","md","xml","yaml","yml"].includes(ext)) {
53
  raw_text = await file.text();
54
  source_type = "file";
55
  } else if (ext === "pdf") {
56
- // Best-effort: client cannot parse PDFs without lib; we send a note
57
  raw_text = `[PDF file: ${file.name}, ${(file.size/1024).toFixed(1)} KB. Extract incident details from the document referenced by file_name.]`;
58
  } else if (source_type === "video") {
59
  raw_text = `[Video file: ${file.name}, ${(file.size/1024/1024).toFixed(2)} MB. Treat as recorded incident footage; analyze based on title + any supplied notes. Recommend transcription if not yet performed.]`;
@@ -63,7 +57,7 @@ export function UploadDialog({ onCreated }: { onCreated?: (id: string) => void }
63
  const finalTitle = title.trim() || (raw_text ? raw_text.slice(0, 80) : file_name) || "Untitled incident";
64
  const { data: inc, error: insErr } = await supabase
65
  .from("incidents")
66
- .insert({ user_id: u.user.id, title: finalTitle, raw_text, file_url, file_name, source_type, status: "pending" })
67
  .select()
68
  .single();
69
  if (insErr) throw insErr;
 
25
  const submit = async () => {
26
  setBusy(true);
27
  try {
 
 
 
28
  let raw_text: string | null = null;
29
  let file_url: string | null = null;
30
  let file_name: string | null = null;
 
39
  const ext = file.name.split(".").pop()?.toLowerCase() ?? "";
40
  source_type = ext === "pdf" ? "pdf" : ["mp4","mov","webm","avi","mkv"].includes(ext) ? "video" : "file";
41
 
42
+ const path = `public/${Date.now()}-${file.name}`;
 
43
  const { error: upErr } = await supabase.storage.from("incident-files").upload(path, file);
44
  if (upErr) throw upErr;
45
  file_url = path;
46
 
 
47
  if (["txt","csv","json","log","md","xml","yaml","yml"].includes(ext)) {
48
  raw_text = await file.text();
49
  source_type = "file";
50
  } else if (ext === "pdf") {
 
51
  raw_text = `[PDF file: ${file.name}, ${(file.size/1024).toFixed(1)} KB. Extract incident details from the document referenced by file_name.]`;
52
  } else if (source_type === "video") {
53
  raw_text = `[Video file: ${file.name}, ${(file.size/1024/1024).toFixed(2)} MB. Treat as recorded incident footage; analyze based on title + any supplied notes. Recommend transcription if not yet performed.]`;
 
57
  const finalTitle = title.trim() || (raw_text ? raw_text.slice(0, 80) : file_name) || "Untitled incident";
58
  const { data: inc, error: insErr } = await supabase
59
  .from("incidents")
60
+ .insert({ title: finalTitle, raw_text, file_url, file_name, source_type, status: "pending" })
61
  .select()
62
  .single();
63
  if (insErr) throw insErr;