-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkers.js
More file actions
40 lines (34 loc) · 1.27 KB
/
Copy pathworkers.js
File metadata and controls
40 lines (34 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const REPO = "CydiaBlock/AppStore";
const RELEASES = new Set(["game", "application"]);
const INDEXES = new Set(["Packages", "Packages.gz"]);
const rawFile = (name) =>
`https://raw.githubusercontent.com/${REPO}/main/${name}`;
export default {
async fetch(request) {
if (request.method !== "GET" && request.method !== "HEAD") {
return new Response("Method not allowed", {
status: 405,
headers: { Allow: "GET, HEAD" },
});
}
const path = new URL(request.url).pathname.split("/").filter(Boolean);
if (path.length === 1 && INDEXES.has(path[0])) {
return fetch(new Request(rawFile(path[0]), request), { redirect: "follow" });
}
if (path.length < 2 || !RELEASES.has(path[0])) {
return new Response("Not found", { status: 404 });
}
const tag = path[0];
let asset;
try {
asset = path.slice(1).map(decodeURIComponent).join("/");
} catch {
return new Response("Not found", { status: 404 });
}
if (!asset.endsWith(".deb") || asset.includes("..")) {
return new Response("Not found", { status: 404 });
}
const origin = `https://github.com/${REPO}/releases/download/${tag}/${encodeURIComponent(asset)}`;
return fetch(new Request(origin, request), { redirect: "follow" });
},
};