feat: switch api url and bypass cache while prerendering

This commit is contained in:
Ax333l 2022-10-27 17:36:49 +02:00
parent e7a34c2ae9
commit fe5877ade5
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
3 changed files with 24 additions and 3 deletions

16
src/lib/utils.ts Normal file
View File

@ -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;
}

View File

@ -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<ContribData> {
const response = await fetch('https://releases.rvcd.win/contributors');
const response = await fetch(api_url('contributors'));
const data = await response.json();
return data;
};

View File

@ -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<PatchesData> {
const response = await fetch('https://releases.rvcd.win/patches');
const response = await fetch(api_url('patches'));
const patches = await response.json();
let packages: string[] = [];