-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-modrinth-releases.ts
64 lines (56 loc) · 1.36 KB
/
index-modrinth-releases.ts
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
59
60
61
62
63
64
import {writeFileSync} from "node:fs";
export enum ModrinthReleaseType {
RELEASE = "release",
BETA = "beta",
ALPHA = "alpha",
}
export type ModrinthRelease = {
id: string;
filename: string;
version: string;
displayName: string;
type: ModrinthReleaseType;
gameVersions: string[];
published: string;
loaders: string[];
};
async function fetchReleases(): Promise<ModrinthRelease[]> {
const url = "https://api.modrinth.com/v2/project/XxWD5pD3/version";
console.info("Requesting %s", url);
const response = await fetch(url, {
headers: {
"User-Agent": "ae2",
},
});
if (!response.ok) {
throw new Error(
"Failed to fetch. " +
response.status +
" (" +
(await response.text()) +
")"
);
}
const data = await response.json();
return data.map(
(record: any) =>
({
id: record.id,
displayName: record.name,
version: record.version_number,
type: record.version_type,
gameVersions: record.game_versions,
published: record.date_published,
filename: record.files.find((f: any) => f.primary)?.filename ?? "",
loaders: record.loaders,
} satisfies ModrinthRelease)
);
}
const releases = await fetchReleases();
writeFileSync(
"caches/modrinth_releases.json",
JSON.stringify(releases, null, 2),
{
encoding: "utf-8",
}
);