You've already forked AstralRinth
forked from didirus/AstralRinth
Make game versions update every 10 minutes via server-side route (#4892)
This commit is contained in:
17
apps/frontend/src/plugins/update-game-versions.ts
Normal file
17
apps/frontend/src/plugins/update-game-versions.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import type { Labrinth } from '@modrinth/api-client'
|
||||||
|
|
||||||
|
export default defineNuxtPlugin(async () => {
|
||||||
|
try {
|
||||||
|
const gameVersions = await $fetch<Labrinth.Tags.v2.GameVersion[]>('/api/tags/game-versions')
|
||||||
|
|
||||||
|
if (gameVersions && gameVersions.length > 0) {
|
||||||
|
const state = useState<{ gameVersions: Labrinth.Tags.v2.GameVersion[] }>('generatedState')
|
||||||
|
|
||||||
|
if (state.value) {
|
||||||
|
state.value.gameVersions = gameVersions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[Game Version Updater] Failed to fetch:', error)
|
||||||
|
}
|
||||||
|
})
|
||||||
17
apps/frontend/src/server/routes/api/tags/game-versions.ts
Normal file
17
apps/frontend/src/server/routes/api/tags/game-versions.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import type { Labrinth } from '@modrinth/api-client'
|
||||||
|
|
||||||
|
const CACHE_MAX_AGE = 60 * 10 // 10 minutes
|
||||||
|
|
||||||
|
export default defineCachedEventHandler(
|
||||||
|
async (event) => {
|
||||||
|
const config = useRuntimeConfig(event)
|
||||||
|
const apiBaseUrl = config.apiBaseUrl || config.public.apiBaseUrl
|
||||||
|
|
||||||
|
return await $fetch<Labrinth.Tags.v2.GameVersion[]>(`${apiBaseUrl}tag/game_version`)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
maxAge: CACHE_MAX_AGE,
|
||||||
|
name: 'game-versions',
|
||||||
|
getKey: () => 'game-versions',
|
||||||
|
},
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user