Skip to content

Commit 5f6fc04

Browse files
committed
fix slowness
1 parent 16bcd38 commit 5f6fc04

2 files changed

Lines changed: 1 addition & 72 deletions

File tree

assets/js/utils/fetchers.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,5 @@
11
import { cacheGet, cacheSet } from "./cache.js";
22
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-
};
313

324
const _githubApiTree = async (path) => {
335
try {
@@ -59,11 +31,7 @@ const github = {
5931
gitUrl: "https://github.com/" + path + ".git",
6032
displayUrl: "github.com/" + path,
6133
}),
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),
6735
rawUrl: (loc, tree, path) => {
6836
const url =
6937
"https://cdn.jsdelivr.net/gh/" +

assets/js/utils/jsdelivr-sanity.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)