-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
58 lines (51 loc) · 1.44 KB
/
index.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Router } from 'itty-router'
import { Octokit } from "@octokit/rest";
const octokit = new Octokit({
auth: API_KEY
});
const esOwner = "endless-sky"
const esRepo = esOwner
// Create a new router
const router = Router()
router.get("/", () => {
return new Response(`
https://github.com/EndlessSkyCommunity/artifact-unblocker
GET /artifact/1337 to get a download link for the artifact with ID 1337. Only works for the ES repo.
`)
})
router.get("/artifact/:id", async ({ params }) => {
try {
let response = await octokit.rest.actions.downloadArtifact({
request: {
redirect: 'manual' // Lest octokit follows the redirect
},
"owner": esOwner,
"repo": esRepo,
"artifact_id": params.id,
"archive_format": "zip"
})
return new Response(JSON.stringify(response.data), {
headers: response.headers,
status: response.status
})
} catch (e) {
if (e.response) {
return new Response(JSON.stringify(e.response.data), {
headers: e.response.headers,
status: e.response.status
})
}
else {
return new Response('{"error": "Unknown Error"}', {
headers: { "Content-Type": "application/json" },
status: e.status
})
}
console.log(JSON.stringify(e))
}
})
// Catch-all 404
router.all("*", () => new Response("404, not found!", { status: 404 }))
addEventListener('fetch', (e) => {
e.respondWith(router.handle(e.request))
})