-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (36 loc) · 1.01 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
/*
* index.js
* Copyright (C) 2021 andy <andy@andys-Air.lan>
*
* Distributed under terms of the MIT license.
*/
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
function simpleResponse(statusCode, message) {
let resp = {
message: message,
status: statusCode
}
return new Response(JSON.stringify(resp), {
headers: {"Content-Type": "application/json"},
status: statusCode
})
}
MIRROR_URL = "https://cdn.npmmirror.com/binaries/python"
// MIRROR_URL = "https://repo.huaweicloud.com/python"
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
const url = new URL(request.url)
sha2name = url.pathname.replace("/", "")
config = JSON.parse(await PYENV_PROXY.get("config"))
if (config[sha2name]) {
version = config[sha2name][0]
suffix = config[sha2name][1]
return Response.redirect(MIRROR_URL + "/" + version + "/Python-" + version + "." + suffix, 301)
}
return simpleResponse(404, "Not Found.")
}