diff --git a/src/lib/utils.ts b/src/lib/utils.ts new file mode 100644 index 0000000..149c3cb --- /dev/null +++ b/src/lib/utils.ts @@ -0,0 +1,16 @@ +import { prerendering } from "$app/environment"; + +export function api_url(endpoint: string): string { + let url = `https://releases.revanced.app/${endpoint}`; + + if (prerendering) { + url += '?cacheBypass='; + // Just add some random stuff to the string. Doesn't really matter what we add. + // This is here to make sure we bypass the cache while prerendering. + for (let i = 0; i < 6; i++) { + url += Math.floor(Math.random() * 10).toString(); + } + } + + return url; +} diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index 26515cb..b9f942d 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -1,5 +1,7 @@ import type { Repository } from 'src/data/types'; +import { api_url } from '$lib/utils'; + export type ContribData = { repositories: Repository[] }; export const prerender = true; @@ -7,7 +9,7 @@ export const prerender = true; export async function load({ fetch }): Promise { - const response = await fetch('https://releases.rvcd.win/contributors'); + const response = await fetch(api_url('contributors')); const data = await response.json(); return data; }; diff --git a/src/routes/patches/+page.server.ts b/src/routes/patches/+page.server.ts index 52a76ea..14b3394 100644 --- a/src/routes/patches/+page.server.ts +++ b/src/routes/patches/+page.server.ts @@ -1,12 +1,15 @@ -import { readable } from 'svelte/store'; import type { Patch } from 'src/data/types'; +import { api_url } from '$lib/utils'; + +import { readable } from 'svelte/store'; + export type PatchesData = { patches: Patch[]; packages: string[] }; export async function load({ fetch }): Promise { - const response = await fetch('https://releases.rvcd.win/patches'); + const response = await fetch(api_url('patches')); const patches = await response.json(); let packages: string[] = [];