File tree Expand file tree Collapse file tree 3 files changed +27
-5
lines changed
Expand file tree Collapse file tree 3 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -5,21 +5,22 @@ import ProjectCard from "../../../components/ProjectCard.astro";
55
66import natureLogo from " ../../../icons/events/nature/logo-full.png" ;
77import type { Project } from " ../../../ts/ModGardenAPI" ;
8- import { getEventProjects } from " ../../../ts/ModGardenAPI" ;
8+ import { getEventProjects , getModrinthModDataForEvent } from " ../../../ts/ModGardenAPI" ;
99import { formatTime , isoTime } from " ../../../ts/TimeHelper" ;
10- import { getModrinthProject , type Mod } from " ../../../ts/ModrinthHelper" ;
10+ import { type Mod } from " ../../../ts/ModrinthHelper" ;
1111
1212type ProjectAndMod = {
1313 project: Project ;
1414 mod: Mod ;
1515}
1616
1717async function getProjects() : Promise <ProjectAndMod []> {
18+ const modrinthProjects = await getModrinthModDataForEvent (" mod-garden-nature" );
1819 const unsortedProjects = await getEventProjects (" mod-garden-nature" );
1920 const projects = new Array <ProjectAndMod >(unsortedProjects .length );
2021 for (let i = 0 ; i < unsortedProjects .length ; ++ i ) {
2122 const project = unsortedProjects [i ];
22- const mod = await getModrinthProject ( project .modrinth_id );
23+ const mod = modrinthProjects . find ( mod => mod . id == project .modrinth_id );
2324 projects [i ] = { project: project , mod: mod } as ProjectAndMod ;
2425 }
2526 projects .sort ((a , b ) => a .mod .title .localeCompare (b .mod .title ))
Original file line number Diff line number Diff line change 1- import { getModrinthProject , type Mod } from "./ModrinthHelper.ts" ;
1+ import { getModrinthProject , getModrinthProjects , type Mod } from "./ModrinthHelper.ts" ;
22
33export type MinecraftAccount = {
44 uuid : string ;
@@ -174,8 +174,14 @@ export async function getUserAwards(user: string): Promise<Award[]> {
174174 . then ( ( data ) => data as Award [ ] ) ;
175175}
176176
177+
177178export async function getModrinthModData (
178179 modrinth_id : string ,
179180) : Promise < Mod | undefined > {
180181 return await getModrinthProject ( modrinth_id ) ;
181182}
183+
184+ export async function getModrinthModDataForEvent ( event : string ) : Promise < Mod [ ] > {
185+ const projects = await getEventProjects ( event ) ;
186+ return await getModrinthProjects ( projects . map ( project => project . modrinth_id ) ) ;
187+ }
Original file line number Diff line number Diff line change 11import EleventyFetch from "@11ty/eleventy-fetch" ;
22import { LIB_VERSION } from "./Version" ;
33const MODRINTH_PROJECT_API = "https://api.modrinth.com/v2/project/" ;
4+ const MODRINTH_PROJECTS_API = "https://api.modrinth.com/v2/projects?ids=" ;
45const MODRINTH_USER_API = "https://api.modrinth.com/v2/user/" ;
56export interface GalleryImage {
67 url : string ;
@@ -28,7 +29,7 @@ export interface File {
2829}
2930
3031export async function getModrinthProject ( projectName : string ) : Promise < Mod > {
31- let data = await EleventyFetch ( `${ MODRINTH_PROJECT_API } ${ projectName } ` , {
32+ let data = await EleventyFetch ( `${ MODRINTH_PROJECT_API } [ ${ projectName } ] ` , {
3233 duration : "1h" ,
3334 type : "json" ,
3435 fetchOptions : {
@@ -39,6 +40,20 @@ export async function getModrinthProject(projectName: string): Promise<Mod> {
3940 } ) ;
4041 return data as Mod ;
4142}
43+
44+ export async function getModrinthProjects ( projectNames : string [ ] ) : Promise < Mod [ ] > {
45+ let data = await EleventyFetch ( `${ MODRINTH_PROJECTS_API } [${ projectNames . map ( projectName => "\"" + projectName + "\"" ) . join ( "," ) } ]` , {
46+ duration : "1h" ,
47+ type : "json" ,
48+ fetchOptions : {
49+ headers : {
50+ "User-Agent" : `ModGardenEvent/website/${ LIB_VERSION } (modgarden.net)` ,
51+ } ,
52+ } ,
53+ } ) ;
54+ return data as Mod [ ] ;
55+ }
56+
4257export async function getModrinthUser ( username : string ) : Promise < ModrinthUser > {
4358 let data = await EleventyFetch ( `${ MODRINTH_USER_API } ${ username } ` , {
4459 duration : "1h" ,
You can’t perform that action at this time.
0 commit comments