-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
42 lines (38 loc) · 1.51 KB
/
worker.js
File metadata and controls
42 lines (38 loc) · 1.51 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
41
42
/**
* Cloudflare Worker — pool redirect for packages.omakasui.org
*
* apt always treats the Filename field in a Packages index as a path relative
* to the repository base URL. Binary packages live as release assets in
* omakasui/build-apt-packages, so we need a redirect layer instead of storing
* .deb files in this repository.
*
* Filename written to Packages: pool/<tag>/<file>
* Worker redirects: /pool/<tag>/<file>
* → https://github.com/omakasui/build-apt-packages/releases/download/<tag>/<file>
*
* apt follows HTTP 302 redirects, so the download ends up at the GitHub CDN
* without any binary ever being committed to this repo.
*
* Every other request is passed through to GitHub Pages unchanged.
*/
const BUILD_REPO = "omakasui/build-apt-packages";
export default {
async fetch(request) {
const url = new URL(request.url);
// Only intercept GET/HEAD requests to /pool/<tag>/<filename>
if (
(request.method === "GET" || request.method === "HEAD") &&
url.pathname.startsWith("/pool/")
) {
const parts = url.pathname.split("/").filter(Boolean);
// Expect exactly: ['pool', '<tag>', '<filename>']
if (parts.length === 3) {
const [, tag, filename] = parts;
const target = `https://github.com/${BUILD_REPO}/releases/download/${encodeURIComponent(tag)}/${encodeURIComponent(filename)}`;
return Response.redirect(target, 302);
}
}
// Pass everything else through to GitHub Pages.
return fetch(request);
},
};