freecrayon-getlatestgitcoreversion.web.val.run
March 15, 2024
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
import { fetch } from "https://esm.town/v/std/fetch";
export default async function(request: Request): Promise<Response> {
const url = new URL(request.url);
const query = url.searchParams.get("query") ?? "";
const cheerio = await import("https://esm.sh/cheerio@1.0.0-rc.12");
const response = await fetch(
"https://launchpad.net/~git-core/+archive/ubuntu/ppa/+packages",
);
const body = await response.text();
const $ = cheerio.load(body);
const rowText = [...$(".archive_package_row a")].map((el) => {
return $(el).text();
}).find((row) => {
return !query || row.includes(query);
});
const matchVersion = /^\s*git\s*-\s*(.+)/.exec(rowText);
if (!matchVersion) {
throw new Error(
`Could not extract version from page. Trying to parse "${rowText}"`,
);
}
const version = matchVersion[1];
return new Response(JSON.stringify({ query, version }));
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
March 15, 2024