MCPcopy Create free account
hub / github.com/itwanger/toBeBetterJavaer / probe

Function probe

docs/scripts/gen-paicoding-canonical.mjs:36–52  ·  view source on GitHub ↗
(slug)

Source from the content-addressed store, hash-verified

34}
35
36async function probe(slug) {
37 const ctrl = new AbortController();
38 const t = setTimeout(() => ctrl.abort(), TIMEOUT_MS);
39 try {
40 const res = await fetch(`${HOST}/${slug}`, { signal: ctrl.signal, redirect: "follow" });
41 if (!res.ok) return false;
42 const html = await res.text();
43 const m = html.match(/<title>([\s\S]*?)<\/title>/i);
44 const title = m ? m[1].trim() : "";
45 // 标题恰好等于首页标题(或为空)说明该 slug 不存在,paicoding 用首页兜底
46 return title !== "" && title !== HOME_TITLE;
47 } catch {
48 return null; // 网络异常:返回 null,调用方据此保留旧清单中的该项
49 } finally {
50 clearTimeout(t);
51 }
52}
53
54async function pool(items, worker, size) {
55 const results = new Array(items.length);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected