Ethscriptions commited on
Commit
80df0f0
·
verified ·
1 Parent(s): 6fc4216

Docker 版:后台自动抓取,数据存 R2,保持常驻

Browse files
Files changed (1) hide show
  1. server.js +8 -1
server.js CHANGED
@@ -43699,6 +43699,7 @@ async function fetchPage(channel, before2, f = fetch) {
43699
  return parsePage(html, channel);
43700
  } catch (e) {
43701
  lastErr = `${relay.name}: ${e.message}`;
 
43702
  relay.blockedUntil = Date.now() + (e.limited ? 25e3 : 12e3);
43703
  } finally {
43704
  clearTimeout(timer);
@@ -43939,6 +43940,7 @@ function startBackfill(ch) {
43939
  emit(ch, "progress");
43940
  }
43941
  if (state.stop) break;
 
43942
  await persist(ch, batch, {
43943
  backfill_status: done ? "done" : "partial",
43944
  backfill_lease: done ? null : `${TAB}@${(/* @__PURE__ */ new Date()).toISOString()}`
@@ -43951,7 +43953,8 @@ function startBackfill(ch) {
43951
  await persist(ch, [], { backfill_status: `error:${err.message}`, backfill_lease: null }).catch(() => {
43952
  });
43953
  } finally {
43954
- backfills.delete(ch);
 
43955
  emit(ch, "done");
43956
  }
43957
  })();
@@ -44099,6 +44102,7 @@ async function handle(method, path2, qs, body) {
44099
  if (method === "DELETE") {
44100
  const bf = backfills.get(ch);
44101
  if (bf) bf.stop = true;
 
44102
  await withLock(ch, async () => {
44103
  await deleteChannelData(ch);
44104
  const idx = await loadIndex();
@@ -44328,6 +44332,9 @@ app.get("*", (_req, res) => {
44328
  res.setHeader("Cache-Control", "no-cache");
44329
  res.sendFile(import_path.default.join(PUBLIC, "index.html"));
44330
  });
 
 
 
44331
  app.listen(PORT, () => console.log(`\u5C0F\u8BF4\u7D20\u6750\u5E93 listening on ${PORT}`));
44332
  enableDirectFetch();
44333
  startServerMode({
 
43699
  return parsePage(html, channel);
43700
  } catch (e) {
43701
  lastErr = `${relay.name}: ${e.message}`;
43702
+ if (typeof window === "undefined") console.warn("fetchPage", url, lastErr);
43703
  relay.blockedUntil = Date.now() + (e.limited ? 25e3 : 12e3);
43704
  } finally {
43705
  clearTimeout(timer);
 
43940
  emit(ch, "progress");
43941
  }
43942
  if (state.stop) break;
43943
+ if (serverMode) console.log("backfill", ch, "got", batch.length, "min_id", state.minId);
43944
  await persist(ch, batch, {
43945
  backfill_status: done ? "done" : "partial",
43946
  backfill_lease: done ? null : `${TAB}@${(/* @__PURE__ */ new Date()).toISOString()}`
 
43953
  await persist(ch, [], { backfill_status: `error:${err.message}`, backfill_lease: null }).catch(() => {
43954
  });
43955
  } finally {
43956
+ if (backfills.get(ch) === state) backfills.delete(ch);
43957
+ if (serverMode) console.log("backfill end", ch, state.stop ? "stopped" : "finished", "min_id", state.minId);
43958
  emit(ch, "done");
43959
  }
43960
  })();
 
44102
  if (method === "DELETE") {
44103
  const bf = backfills.get(ch);
44104
  if (bf) bf.stop = true;
44105
+ backfills.delete(ch);
44106
  await withLock(ch, async () => {
44107
  await deleteChannelData(ch);
44108
  const idx = await loadIndex();
 
44332
  res.setHeader("Cache-Control", "no-cache");
44333
  res.sendFile(import_path.default.join(PUBLIC, "index.html"));
44334
  });
44335
+ app.use((err, _req, res, _next) => {
44336
+ res.status(err.status || 500).json({ error: err.status === 400 ? "bad request" : "server error" });
44337
+ });
44338
  app.listen(PORT, () => console.log(`\u5C0F\u8BF4\u7D20\u6750\u5E93 listening on ${PORT}`));
44339
  enableDirectFetch();
44340
  startServerMode({