(e: React.ChangeEvent<HTMLInputElement>)
| 87 | } |
| 88 | |
| 89 | const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => { |
| 90 | const file = e.target.files?.[0] |
| 91 | if (!file) return |
| 92 | |
| 93 | setUploadedFile(file) |
| 94 | |
| 95 | if (file.type === "text/plain" || file.name.endsWith(".md") || file.name.endsWith(".tex")) { |
| 96 | const text = await file.text() |
| 97 | setInputText(text) |
| 98 | } else if (file.type === "application/pdf") { |
| 99 | setIsPdfProcessing(true) |
| 100 | setInputText(`[Processing PDF: ${file.name}...]`) |
| 101 | |
| 102 | try { |
| 103 | const formData = new FormData() |
| 104 | formData.append("pdf_file", file) |
| 105 | |
| 106 | console.log("[AutoFigure] Trying remote API extraction...") |
| 107 | const result = await convertPdfToMarkdown(formData) |
| 108 | |
| 109 | if (result.success && result.markdown) { |
| 110 | setInputText(result.markdown) |
| 111 | console.log("[AutoFigure] PDF extraction successful (remote API)") |
| 112 | } else { |
| 113 | console.log("[AutoFigure] Remote API failed, trying local extraction...") |
| 114 | setInputText(`[Remote API failed, using local extraction...]`) |
| 115 | |
| 116 | try { |
| 117 | const localText = await extractPdfText(file) |
| 118 | if (localText && localText.trim()) { |
| 119 | setInputText(localText) |
| 120 | console.log("[AutoFigure] PDF extraction successful (local fallback)") |
| 121 | } else { |
| 122 | setInputText(`[PDF extraction failed: No text extracted]`) |
| 123 | console.error("[AutoFigure] Local extraction returned empty text") |
| 124 | } |
| 125 | } catch (localError) { |
| 126 | setInputText(`[PDF extraction failed: ${result.error || "Unknown error"}]`) |
| 127 | console.error("[AutoFigure] Both remote and local extraction failed:", localError) |
| 128 | } |
| 129 | } |
| 130 | } catch (error) { |
| 131 | console.log("[AutoFigure] Server Action failed, trying local extraction...") |
| 132 | try { |
| 133 | const localText = await extractPdfText(file) |
| 134 | if (localText && localText.trim()) { |
| 135 | setInputText(localText) |
| 136 | console.log("[AutoFigure] PDF extraction successful (local fallback after error)") |
| 137 | } else { |
| 138 | setInputText(`[PDF extraction failed: ${error}]`) |
| 139 | } |
| 140 | } catch (localError) { |
| 141 | setInputText(`[PDF extraction failed: ${error}]`) |
| 142 | console.error("[AutoFigure] PDF extraction error:", error) |
| 143 | } |
| 144 | } finally { |
| 145 | setIsPdfProcessing(false) |
| 146 | } |
nothing calls this directly
no test coverage detected