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
export const getVersion = async (request: Request) => {
const url = new URL(request.url);
const [username, repo] = url.pathname.split("/").filter(Boolean).map((s) => s.trim());
if (!username || !repo) {
throw new Error("Must provide /{username}/{repo}");
}
const targetUrl = `https://api.github.com/repos/${username}/${repo}/releases/latest`;
const headers = request.headers;
headers.set("accept", "application/vnd.github.v3+json");
const res = await fetch(targetUrl, { headers });
const release = await res.json();
if (!release || !release.tag_name) {
throw new Error(`No valid releases found for ${username}/${repo}`);
}
return Response.json({
username,
repo,
version: release.tag_name,
link: `https://github.com/${encodeURIComponent(username)}/${encodeURIComponent(repo)}`,
});
};