(kind)
| 3025 | } |
| 3026 | |
| 3027 | async function directRead(kind) { |
| 3028 | const isPdf = kind === "pdf"; |
| 3029 | const sourceLabel = isPdf ? ui().common.localPdf : ui().common.arxiv; |
| 3030 | const payload = { |
| 3031 | user_id: currentUser(), |
| 3032 | write_feishu: isPdf ? Boolean($("directPdfWriteFeishu")?.checked) : Boolean($("directWriteFeishu")?.checked) |
| 3033 | }; |
| 3034 | let route = "/api/read/arxiv"; |
| 3035 | if (!isPdf) { |
| 3036 | const raw = $("directArxivId").value.trim(); |
| 3037 | payload.arxiv_id = raw.replace(/^https?:\/\/arxiv\.org\/abs\//, ""); |
| 3038 | if (!payload.arxiv_id) { |
| 3039 | setDirectReadStatus("arxiv", "warning", ui().reports.arxivRequiredTitle, ui().reports.arxivRequiredDetail); |
| 3040 | throw new Error(ui().reports.arxivRequiredTitle); |
| 3041 | } |
| 3042 | } else { |
| 3043 | route = "/api/read/pdf"; |
| 3044 | payload.pdf_path = $("directPdfPath").value.trim(); |
| 3045 | payload.title = $("directPdfTitle").value.trim(); |
| 3046 | if (!payload.pdf_path) { |
| 3047 | setDirectReadStatus("pdf", "warning", ui().reports.pdfRequiredTitle, ui().reports.pdfRequiredDetail); |
| 3048 | throw new Error(ui().reports.pdfRequiredTitle); |
| 3049 | } |
| 3050 | } |
| 3051 | payload.response_language = responseLanguage(); |
| 3052 | setDirectReadBusy(kind, true); |
| 3053 | setDirectReadStatus( |
| 3054 | kind, |
| 3055 | "pending", |
| 3056 | ui().reports.generatingTitle(sourceLabel), |
| 3057 | ui().reports.generatingDetail |
| 3058 | ); |
| 3059 | try { |
| 3060 | const data = await api(route, { method: "POST", body: JSON.stringify(payload) }); |
| 3061 | const reports = data.reports || data; |
| 3062 | const doc = reports?.created_docs?.[0]; |
| 3063 | if (!doc?.report_id) { |
| 3064 | throw new Error(ui().reports.missingReportId); |
| 3065 | } |
| 3066 | const reportTitle = doc.title || doc.paper?.title || ui().reports.defaultTitle; |
| 3067 | const reportPath = doc.report_path || ""; |
| 3068 | const warning = reports.feishu_warning || ""; |
| 3069 | setDirectReadStatus( |
| 3070 | kind, |
| 3071 | warning ? "warning" : "success", |
| 3072 | warning ? ui().reports.generatedWarning : ui().reports.generatedTitle, |
| 3073 | `${reportTitle}${reportPath ? ` · ${reportPath}` : ""}${warning ? ` · ${warning}` : ""}` |
| 3074 | ); |
| 3075 | showFeedbackToast(warning ? "warning" : "success", ui().reports.generatedToast, reportTitle); |
| 3076 | await openReport(doc.report_id); |
| 3077 | await loadWiki(); |
| 3078 | } catch (error) { |
| 3079 | setDirectReadStatus(kind, "error", ui().reports.generationFailed, error.message || String(error)); |
| 3080 | throw error; |
| 3081 | } finally { |
| 3082 | setDirectReadBusy(kind, false); |
| 3083 | } |
| 3084 | } |
no test coverage detected