Skip to content

Commit dbfb68f

Browse files
committed
Use channel filter when possible for querying builds
1 parent 6f4f251 commit dbfb68f

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/utils/download.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export async function getProjectDescriptor(id: string): Promise<ProjectDescripto
4848
// Check for stable builds
4949
for (let i = flattenedVersions.length - 1; i >= 0; i--) {
5050
try {
51-
const builds = await getVersionBuilds(id, flattenedVersions[i]);
52-
if (builds.some((build) => build.channel === "STABLE")) {
51+
const builds = await getVersionBuilds(id, flattenedVersions[i], "STABLE");
52+
if (builds.length > 0) {
5353
latestStableVersion = flattenedVersions[i];
5454
break;
5555
}
@@ -84,8 +84,8 @@ export async function getProjectDescriptorWithHangar(id: string): Promise<{ proj
8484
// Check for stable builds
8585
for (let i = flattenedVersions.length - 1; i >= 0; i--) {
8686
try {
87-
const builds = await getVersionBuilds(id, flattenedVersions[i]);
88-
if (builds.some((build) => build.channel === "STABLE")) {
87+
const builds = await getVersionBuilds(id, flattenedVersions[i], "STABLE");
88+
if (builds.length > 0) {
8989
latestStableVersion = flattenedVersions[i];
9090
break;
9191
}

src/utils/fill.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Build, Project } from "@/utils/types";
1+
import type { Build, BuildChannel, Project } from "@/utils/types";
22

33
const API_ENDPOINT = "https://fill.papermc.io/v3";
44
const BSTATS_URL = "https://bstats.org/api/v1/plugins/580/charts/players/data/?maxElements=1";
@@ -20,8 +20,12 @@ export async function getProject(project: string): Promise<Project> {
2020
return res.json() as Promise<Project>;
2121
}
2222

23-
export async function getVersionBuilds(project: string, version: string): Promise<Build[]> {
24-
const res = await edgeFetch(`${API_ENDPOINT}/projects/${project}/versions/${version}/builds`, 300);
23+
export async function getVersionBuilds(project: string, version: string, channel?: BuildChannel): Promise<Build[]> {
24+
let url = `${API_ENDPOINT}/projects/${project}/versions/${version}/builds`;
25+
if (channel) {
26+
url += `?channel=${encodeURIComponent(channel)}`;
27+
}
28+
const res = await edgeFetch(url, 300);
2529
if (!res.ok) {
2630
throw new Error(`getVersionBuilds(${project}, ${version}) failed: ${res.status}`);
2731
}

src/utils/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ export interface VersionFamilyBuild extends Build {
3636
version: string;
3737
}
3838

39+
export type BuildChannel = "ALPHA" | "BETA" | "STABLE" | "RECOMMENDED";
40+
3941
export interface Build {
4042
id: number;
4143
time: string;
42-
channel: "ALPHA" | "BETA" | "STABLE" | "RECOMMENDED";
44+
channel: BuildChannel;
4345
commits: BuildChange[];
4446
downloads: {
4547
[key: string]: BuildDownload;

0 commit comments

Comments
 (0)