Spaces:
Sleeping
Sleeping
Wire file upload to server-side parser (PDF/DOCX via pdf-parse + mammoth)
Browse files
web/app/dashboard-pages/analyze/page.tsx
CHANGED
|
@@ -88,20 +88,19 @@ export default function AnalyzePage() {
|
|
| 88 |
setError("");
|
| 89 |
|
| 90 |
try {
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
setError("DOCX parsing requires the Pro plan backend. Paste text for now.");
|
| 99 |
-
} else {
|
| 100 |
-
const content = await file.text();
|
| 101 |
-
setText(content);
|
| 102 |
}
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
| 105 |
}
|
| 106 |
setLoading(false);
|
| 107 |
if (fileInputRef.current) fileInputRef.current.value = "";
|
|
@@ -173,7 +172,7 @@ export default function AnalyzePage() {
|
|
| 173 |
<ScanText className="w-6 h-6 text-zinc-400" />
|
| 174 |
Scan a document
|
| 175 |
</h1>
|
| 176 |
-
<p className="mt-1 text-sm text-zinc-500">Paste text or upload a file (.
|
| 177 |
</div>
|
| 178 |
{userPlan === "free" && (
|
| 179 |
<span className="text-xs text-zinc-400 border border-zinc-200 px-2.5 py-1 rounded-md">
|
|
|
|
| 88 |
setError("");
|
| 89 |
|
| 90 |
try {
|
| 91 |
+
const formData = new FormData();
|
| 92 |
+
formData.append("file", file);
|
| 93 |
+
|
| 94 |
+
const res = await fetch("/api/parse-upload", { method: "POST", body: formData });
|
| 95 |
+
if (!res.ok) {
|
| 96 |
+
const err = await res.json();
|
| 97 |
+
throw new Error(err.error || "Failed to parse file");
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
}
|
| 99 |
+
|
| 100 |
+
const { text: extractedText } = await res.json();
|
| 101 |
+
setText(extractedText);
|
| 102 |
+
} catch (e: any) {
|
| 103 |
+
setError(e.message || "Could not read file.");
|
| 104 |
}
|
| 105 |
setLoading(false);
|
| 106 |
if (fileInputRef.current) fileInputRef.current.value = "";
|
|
|
|
| 172 |
<ScanText className="w-6 h-6 text-zinc-400" />
|
| 173 |
Scan a document
|
| 174 |
</h1>
|
| 175 |
+
<p className="mt-1 text-sm text-zinc-500">Paste text or upload a file (.pdf, .docx, .txt).</p>
|
| 176 |
</div>
|
| 177 |
{userPlan === "free" && (
|
| 178 |
<span className="text-xs text-zinc-400 border border-zinc-200 px-2.5 py-1 rounded-md">
|