Spaces:
Sleeping
Sleeping
Update static/app.js
Browse files- static/app.js +20 -27
static/app.js
CHANGED
|
@@ -7,8 +7,10 @@ async function postJSON(url, body){
|
|
| 7 |
headers: {"Content-Type": "application/json"},
|
| 8 |
body: JSON.stringify(body)
|
| 9 |
});
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
document.getElementById("btnIngestEdinet").onclick = async () => {
|
|
@@ -16,14 +18,10 @@ document.getElementById("btnIngestEdinet").onclick = async () => {
|
|
| 16 |
const edinetDate = document.getElementById("edinetDate").value.trim();
|
| 17 |
const out = document.getElementById("ingestEdinetResult");
|
| 18 |
out.textContent = "実行中…";
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
}catch(e){
|
| 24 |
-
out.textContent = "エラー: " + e.message;
|
| 25 |
-
log("[EDINET][ERR] " + e.message);
|
| 26 |
-
}
|
| 27 |
};
|
| 28 |
|
| 29 |
document.getElementById("btnIngestUpload").onclick = async () => {
|
|
@@ -35,10 +33,10 @@ document.getElementById("btnIngestUpload").onclick = async () => {
|
|
| 35 |
const fd = new FormData();
|
| 36 |
for(const f of files){ fd.append("files", f, f.name); }
|
| 37 |
const res = await fetch("/ingest/upload", { method: "POST", body: fd });
|
| 38 |
-
if(!res.ok){ throw new Error(await res.text()); }
|
| 39 |
const data = await res.json();
|
| 40 |
-
out.textContent = `
|
| 41 |
-
|
|
|
|
| 42 |
}catch(e){
|
| 43 |
out.textContent = "エラー: " + e.message;
|
| 44 |
log("[UPLOAD][ERR] " + e.message);
|
|
@@ -49,21 +47,16 @@ document.getElementById("btnGenerate").onclick = async () => {
|
|
| 49 |
const q = document.getElementById("query").value.trim();
|
| 50 |
const st = document.getElementById("generateStatus");
|
| 51 |
const dl = document.getElementById("downloadLinks");
|
| 52 |
-
st.textContent = "生成中…(初回は
|
| 53 |
dl.innerHTML = "";
|
| 54 |
-
|
| 55 |
-
|
| 56 |
st.textContent = "生成完了";
|
| 57 |
-
const a1 = document.createElement("a");
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
dl.appendChild(document.createTextNode(" / "));
|
| 63 |
-
dl.appendChild(a2);
|
| 64 |
-
log(`[GENERATE] ppt=${data.pptx} csv=${data.qa_csv}`);
|
| 65 |
-
}catch(e){
|
| 66 |
-
st.textContent = "エラー: " + e.message;
|
| 67 |
-
log("[GENERATE][ERR] " + e.message);
|
| 68 |
}
|
|
|
|
| 69 |
};
|
|
|
|
| 7 |
headers: {"Content-Type": "application/json"},
|
| 8 |
body: JSON.stringify(body)
|
| 9 |
});
|
| 10 |
+
// 200以外でも本文を拾って表示したいのでここでは throw しない
|
| 11 |
+
let data = null;
|
| 12 |
+
try { data = await res.json(); } catch(_) { data = {ok:false, error:`${res.status} ${res.statusText}`}; }
|
| 13 |
+
return { status: res.status, data };
|
| 14 |
}
|
| 15 |
|
| 16 |
document.getElementById("btnIngestEdinet").onclick = async () => {
|
|
|
|
| 18 |
const edinetDate = document.getElementById("edinetDate").value.trim();
|
| 19 |
const out = document.getElementById("ingestEdinetResult");
|
| 20 |
out.textContent = "実行中…";
|
| 21 |
+
const {data} = await postJSON("/ingest/edinet", {edinet_code: edinetCode, date: edinetDate});
|
| 22 |
+
if(data.ok){ out.textContent = `投入チャンク数: ${data.ingested_chunks}`; }
|
| 23 |
+
else { out.textContent = "エラー: " + (data.error || "unknown"); }
|
| 24 |
+
log("[EDINET] " + JSON.stringify(data));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
};
|
| 26 |
|
| 27 |
document.getElementById("btnIngestUpload").onclick = async () => {
|
|
|
|
| 33 |
const fd = new FormData();
|
| 34 |
for(const f of files){ fd.append("files", f, f.name); }
|
| 35 |
const res = await fetch("/ingest/upload", { method: "POST", body: fd });
|
|
|
|
| 36 |
const data = await res.json();
|
| 37 |
+
if(data.ok){ out.textContent = `保存:${data.saved?.length||0} / チャンク:${data.ingested_chunks}`; }
|
| 38 |
+
else { out.textContent = "エラー: " + (data.error || "unknown"); }
|
| 39 |
+
log("[UPLOAD] " + JSON.stringify(data));
|
| 40 |
}catch(e){
|
| 41 |
out.textContent = "エラー: " + e.message;
|
| 42 |
log("[UPLOAD][ERR] " + e.message);
|
|
|
|
| 47 |
const q = document.getElementById("query").value.trim();
|
| 48 |
const st = document.getElementById("generateStatus");
|
| 49 |
const dl = document.getElementById("downloadLinks");
|
| 50 |
+
st.textContent = "生成中…(初回はDLで時間がかかる場合があります)";
|
| 51 |
dl.innerHTML = "";
|
| 52 |
+
const {data} = await postJSON("/generate/all", {query: q});
|
| 53 |
+
if(data.ok){
|
| 54 |
st.textContent = "生成完了";
|
| 55 |
+
const a1 = document.createElement("a"); a1.href = data.pptx; a1.textContent = "PPTXをダウンロード";
|
| 56 |
+
const a2 = document.createElement("a"); a2.href = data.qa_csv; a2.textContent = "Q&A CSVをダウンロード";
|
| 57 |
+
dl.appendChild(a1); dl.appendChild(document.createTextNode(" / ")); dl.appendChild(a2);
|
| 58 |
+
}else{
|
| 59 |
+
st.textContent = "エラー: " + (data.error || "unknown");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
}
|
| 61 |
+
log("[GENERATE] " + JSON.stringify(data));
|
| 62 |
};
|