mirror of
https://github.com/ReVanced/revanced-website.git
synced 2026-01-25 11:51:03 +00:00
chore: Switch to v3 API (#247)
This commit is contained in:
@@ -3,22 +3,21 @@ import * as settings from './settings';
|
||||
// API Endpoints
|
||||
import type {
|
||||
Patch,
|
||||
Repository,
|
||||
Metadata,
|
||||
Asset,
|
||||
Contributable,
|
||||
Release,
|
||||
TeamMember,
|
||||
DonationPlatform,
|
||||
CryptoWallet,
|
||||
Social,
|
||||
Info,
|
||||
About,
|
||||
CompatiblePackage
|
||||
} from '$lib/types';
|
||||
|
||||
export type ReposData = { repositories: Repository[] };
|
||||
export type ContributorsData = { contributables: Contributable[] };
|
||||
export type PatchesData = { patches: Patch[]; packages: string[] };
|
||||
export type ReleaseData = { metadata: Metadata; assets: Asset[] };
|
||||
export type ReleaseData = { release: Release };
|
||||
export type TeamData = { members: TeamMember[] };
|
||||
export type InfoData = { info: Info };
|
||||
export type AboutData = { about: About };
|
||||
export type DonationData = { wallets: CryptoWallet[]; platforms: DonationPlatform[] };
|
||||
export type SocialsData = { socials: Social[] };
|
||||
|
||||
@@ -27,25 +26,24 @@ async function get_json(endpoint: string) {
|
||||
return await fetch(url).then((r) => r.json());
|
||||
}
|
||||
|
||||
async function repositories(): Promise<ReposData> {
|
||||
const json = await get_json('contributors');
|
||||
return { repositories: json.repositories };
|
||||
async function contributors(): Promise<ContributorsData> {
|
||||
const json = await get_json('v3/contributors');
|
||||
return { contributables: json };
|
||||
}
|
||||
|
||||
async function manager(): Promise<ReleaseData> {
|
||||
const json = await get_json('v2/revanced-manager/releases/latest');
|
||||
// console.log(json.release.metadata.tag_name);
|
||||
console.log(json.release.assets[0].browser_download_url);
|
||||
return { metadata: json.release.metadata, assets: json.release.assets };
|
||||
const json = await get_json('v3/manager/latest');
|
||||
|
||||
return { release: json };
|
||||
}
|
||||
|
||||
async function patches(): Promise<PatchesData> {
|
||||
const json = await get_json('v2/patches/latest');
|
||||
const json = await get_json('v3/patches/latest/list');
|
||||
const packagesWithCount: { [key: string]: number } = {};
|
||||
|
||||
// gets packages and patch count
|
||||
for (let i = 0; i < json.patches.length; i++) {
|
||||
json.patches[i].compatiblePackages?.forEach((pkg: CompatiblePackage) => {
|
||||
for (let i = 0; i < json.length; i++) {
|
||||
json[i].compatiblePackages?.forEach((pkg: CompatiblePackage) => {
|
||||
packagesWithCount[pkg.name] = (packagesWithCount[pkg.name] || 0) + 1;
|
||||
});
|
||||
}
|
||||
@@ -54,27 +52,17 @@ async function patches(): Promise<PatchesData> {
|
||||
const packages = Object.keys(packagesWithCount);
|
||||
packages.sort((a, b) => packagesWithCount[b] - packagesWithCount[a]);
|
||||
|
||||
return { patches: json.patches, packages };
|
||||
return { patches: json, packages };
|
||||
}
|
||||
|
||||
async function team(): Promise<TeamData> {
|
||||
const json = await get_json('v2/team/members');
|
||||
return { members: json.members };
|
||||
const json = await get_json('v3/team');
|
||||
return { members: json };
|
||||
}
|
||||
|
||||
async function info(): Promise<InfoData> {
|
||||
const json = await get_json('v2/info');
|
||||
return { info: json.info };
|
||||
}
|
||||
|
||||
async function donate(): Promise<DonationData> {
|
||||
const json = await get_json('v2/donations');
|
||||
return { wallets: json.donations.wallets, platforms: json.donations.links };
|
||||
}
|
||||
|
||||
async function socials(): Promise<SocialsData> {
|
||||
const json = await get_json('v2/socials');
|
||||
return { socials: json.socials };
|
||||
async function about(): Promise<AboutData> {
|
||||
const json = await get_json('v3/about');
|
||||
return { about: json };
|
||||
}
|
||||
|
||||
export const staleTime = 5 * 60 * 1000;
|
||||
@@ -89,9 +77,9 @@ export const queries = {
|
||||
queryFn: patches,
|
||||
staleTime
|
||||
},
|
||||
repositories: {
|
||||
queryKey: ['repositories'],
|
||||
queryFn: repositories,
|
||||
contributors: {
|
||||
queryKey: ['contributors'],
|
||||
queryFn: contributors,
|
||||
staleTime
|
||||
},
|
||||
team: {
|
||||
@@ -99,19 +87,9 @@ export const queries = {
|
||||
queryFn: team,
|
||||
staleTime
|
||||
},
|
||||
info: {
|
||||
about: {
|
||||
queryKey: ['info'],
|
||||
queryFn: info,
|
||||
staleTime
|
||||
},
|
||||
donate: {
|
||||
queryKey: ['donate'],
|
||||
queryFn: donate,
|
||||
staleTime
|
||||
},
|
||||
socials: {
|
||||
queryKey: ['socials'],
|
||||
queryFn: socials,
|
||||
queryFn: about,
|
||||
staleTime
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user