|
1 | 1 | import { cacheGet, cacheSet } from "./cache.js"; |
2 | 2 | import { DETECT_TTL_MS } from "./config.js"; |
3 | | -import { jsdelivrTreeLooksSane } from "./jsdelivr-sanity.js"; |
4 | | - |
5 | | -const _flattenJsdelivr = (node, prefix, out) => { |
6 | | - if (!node || !Array.isArray(node.files)) return out; |
7 | | - node.files.forEach((f) => { |
8 | | - const p = prefix ? prefix + "/" + f.name : f.name; |
9 | | - if (f.type === "directory") _flattenJsdelivr(f, p, out); |
10 | | - else out.push(p); |
11 | | - }); |
12 | | - return out; |
13 | | -}; |
14 | | - |
15 | | -const _jsdelivrTree = async (path) => { |
16 | | - const refs = ["main", "master"]; |
17 | | - for (const ref of refs) { |
18 | | - try { |
19 | | - const r = await fetch( |
20 | | - "https://data.jsdelivr.com/v1/packages/gh/" + path + "@" + ref, |
21 | | - { headers: { accept: "application/json" } } |
22 | | - ); |
23 | | - if (!r.ok) continue; |
24 | | - const data = await r.json(); |
25 | | - const paths = _flattenJsdelivr(data, "", []); |
26 | | - if (paths.length) return { paths, ref, sha: null }; |
27 | | - } catch (_e) { } |
28 | | - } |
29 | | - return null; |
30 | | -}; |
31 | 3 |
|
32 | 4 | const _githubApiTree = async (path) => { |
33 | 5 | try { |
@@ -59,11 +31,7 @@ const github = { |
59 | 31 | gitUrl: "https://github.com/" + path + ".git", |
60 | 32 | displayUrl: "github.com/" + path, |
61 | 33 | }), |
62 | | - getTree: async (loc) => { |
63 | | - const t = await _jsdelivrTree(loc.path); |
64 | | - if (t && (await jsdelivrTreeLooksSane(loc.path, t))) return t; |
65 | | - return await _githubApiTree(loc.path); |
66 | | - }, |
| 34 | + getTree: (loc) => _githubApiTree(loc.path), |
67 | 35 | rawUrl: (loc, tree, path) => { |
68 | 36 | const url = |
69 | 37 | "https://cdn.jsdelivr.net/gh/" + |
|
0 commit comments