diff options
Diffstat (limited to 'scripts/park-editor.mjs')
| -rw-r--r-- | scripts/park-editor.mjs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/scripts/park-editor.mjs b/scripts/park-editor.mjs index feeb059..b3a3e80 100644 --- a/scripts/park-editor.mjs +++ b/scripts/park-editor.mjs @@ -109,7 +109,7 @@ function canonicalKeysFrom(lists) { return [...keys]; } -// 「ベンチ・椅���」のような項目名の文字化けを、前後の文字から正しい項目名に戻す +// 「ベンチ・椅子」のような項目名の文字化けを、前後の文字から正しい項目名に戻す function normalizeRecordKeys(rec, canonicalKeys) { const src = rec && rec.properties ? rec.properties : rec; if (!src) return; @@ -241,6 +241,40 @@ const server = createServer(async (req, res) => { return; } + // 確認チェックの切り替えを、その場でJSONに反映する(サイトの「未確認」用)。 + if (req.method === "POST" && url === "/api/check") { + let body = ""; + for await (const chunk of req) body += chunk; + const payload = JSON.parse(body); + const dataset = DATASETS[payload.id]; + if (!dataset) { + send(res, 404, "text/plain; charset=utf-8", "not found"); + return; + } + const data = JSON.parse(await readFile(dataset.path, "utf-8")); + const list = payload.id === "nearbyParks" ? data.features : data; + const updates = Array.isArray(payload.updates) ? payload.updates : []; + for (const update of updates) { + const rec = list[Number(update.index)]; + if (!rec) continue; + const props = rec.properties || rec; + props["確認"] = update.checked ? "済" : ""; + } + const text = dataset.pretty + ? `${JSON.stringify(data, null, 2)}\n` + : `${JSON.stringify(data)}\n`; + const tmp = `${dataset.path}.tmp`; + await writeFile(tmp, text, "utf-8"); + await rename(tmp, dataset.path); + send( + res, + 200, + "application/json; charset=utf-8", + JSON.stringify({ ok: true, count: updates.length }), + ); + return; + } + const target = datasetFromUrl(url); if (!target) { send(res, 404, "text/plain; charset=utf-8", "not found"); |
