chore: Switch to v3 API (#247)

This commit is contained in:
oSumAtrIX 2024-07-13 16:51:31 +02:00 committed by GitHub
parent 145c11e856
commit f428902773
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 75 additions and 103 deletions

View File

@ -3,22 +3,21 @@ import * as settings from './settings';
// API Endpoints // API Endpoints
import type { import type {
Patch, Patch,
Repository, Contributable,
Metadata, Release,
Asset,
TeamMember, TeamMember,
DonationPlatform, DonationPlatform,
CryptoWallet, CryptoWallet,
Social, Social,
Info, About,
CompatiblePackage CompatiblePackage
} from '$lib/types'; } from '$lib/types';
export type ReposData = { repositories: Repository[] }; export type ContributorsData = { contributables: Contributable[] };
export type PatchesData = { patches: Patch[]; packages: string[] }; 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 TeamData = { members: TeamMember[] };
export type InfoData = { info: Info }; export type AboutData = { about: About };
export type DonationData = { wallets: CryptoWallet[]; platforms: DonationPlatform[] }; export type DonationData = { wallets: CryptoWallet[]; platforms: DonationPlatform[] };
export type SocialsData = { socials: Social[] }; export type SocialsData = { socials: Social[] };
@ -27,25 +26,24 @@ async function get_json(endpoint: string) {
return await fetch(url).then((r) => r.json()); return await fetch(url).then((r) => r.json());
} }
async function repositories(): Promise<ReposData> { async function contributors(): Promise<ContributorsData> {
const json = await get_json('contributors'); const json = await get_json('v3/contributors');
return { repositories: json.repositories }; return { contributables: json };
} }
async function manager(): Promise<ReleaseData> { async function manager(): Promise<ReleaseData> {
const json = await get_json('v2/revanced-manager/releases/latest'); const json = await get_json('v3/manager/latest');
// console.log(json.release.metadata.tag_name);
console.log(json.release.assets[0].browser_download_url); return { release: json };
return { metadata: json.release.metadata, assets: json.release.assets };
} }
async function patches(): Promise<PatchesData> { 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 } = {}; const packagesWithCount: { [key: string]: number } = {};
// gets packages and patch count // gets packages and patch count
for (let i = 0; i < json.patches.length; i++) { for (let i = 0; i < json.length; i++) {
json.patches[i].compatiblePackages?.forEach((pkg: CompatiblePackage) => { json[i].compatiblePackages?.forEach((pkg: CompatiblePackage) => {
packagesWithCount[pkg.name] = (packagesWithCount[pkg.name] || 0) + 1; packagesWithCount[pkg.name] = (packagesWithCount[pkg.name] || 0) + 1;
}); });
} }
@ -54,27 +52,17 @@ async function patches(): Promise<PatchesData> {
const packages = Object.keys(packagesWithCount); const packages = Object.keys(packagesWithCount);
packages.sort((a, b) => packagesWithCount[b] - packagesWithCount[a]); packages.sort((a, b) => packagesWithCount[b] - packagesWithCount[a]);
return { patches: json.patches, packages }; return { patches: json, packages };
} }
async function team(): Promise<TeamData> { async function team(): Promise<TeamData> {
const json = await get_json('v2/team/members'); const json = await get_json('v3/team');
return { members: json.members }; return { members: json };
} }
async function info(): Promise<InfoData> { async function about(): Promise<AboutData> {
const json = await get_json('v2/info'); const json = await get_json('v3/about');
return { info: json.info }; return { about: json };
}
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 };
} }
export const staleTime = 5 * 60 * 1000; export const staleTime = 5 * 60 * 1000;
@ -89,9 +77,9 @@ export const queries = {
queryFn: patches, queryFn: patches,
staleTime staleTime
}, },
repositories: { contributors: {
queryKey: ['repositories'], queryKey: ['contributors'],
queryFn: repositories, queryFn: contributors,
staleTime staleTime
}, },
team: { team: {
@ -99,19 +87,9 @@ export const queries = {
queryFn: team, queryFn: team,
staleTime staleTime
}, },
info: { about: {
queryKey: ['info'], queryKey: ['info'],
queryFn: info, queryFn: about,
staleTime
},
donate: {
queryKey: ['donate'],
queryFn: donate,
staleTime
},
socials: {
queryKey: ['socials'],
queryFn: socials,
staleTime staleTime
} }
}; };

View File

@ -8,8 +8,7 @@
import Query from '$lib/components/Query.svelte'; import Query from '$lib/components/Query.svelte';
import FooterSection from './FooterSection.svelte'; import FooterSection from './FooterSection.svelte';
const infoQuery = createQuery(['info'], queries.info); const aboutQuery = createQuery(['about'], queries.about);
const socialsQuery = createQuery(['socials'], queries.socials);
</script> </script>
<!-- squiggly divider line --> <!-- squiggly divider line -->
@ -33,11 +32,11 @@
<div class="footer-top"> <div class="footer-top">
<section class="main-content"> <section class="main-content">
<img src="/logo.svg" class="logo-image" alt="ReVanced Logo" /> <img src="/logo.svg" class="logo-image" alt="ReVanced Logo" />
<Query query={infoQuery} let:data> <Query query={aboutQuery} let:data>
{#if data} {#if data}
<div> <div>
<p> <p>
{data.info.about} {data.about.about}
</p> </p>
</div> </div>
{/if} {/if}
@ -52,10 +51,10 @@
<li><a href="/contributors">Contributors</a></li> <li><a href="/contributors">Contributors</a></li>
<li><a href="/donate">Donate</a></li> <li><a href="/donate">Donate</a></li>
</FooterSection> </FooterSection>
<Query query={socialsQuery} let:data> <Query query={aboutQuery} let:data>
{#if data} {#if data}
<FooterSection title="Socials"> <FooterSection title="Socials">
{#each data.socials as { name, url }} {#each data.about.socials as { name, url }}
<li> <li>
<a href={url} target="_blank" rel="noreferrer">{name}</a> <a href={url} target="_blank" rel="noreferrer">{name}</a>
</li> </li>
@ -65,12 +64,12 @@
</Query> </Query>
</section> </section>
</div> </div>
<Query query={infoQuery} let:data> <Query query={aboutQuery} let:data>
{#if data} {#if data}
<div class="footer-bottom"> <div class="footer-bottom">
<div id="logo-name"><span>Re</span>Vanced</div> <div id="logo-name"><span>Re</span>Vanced</div>
<a href="/donate"><div>Donate</div></a> <a href="/donate"><div>Donate</div></a>
<a href="mailto:{data.info.contact.email}"><div>Email</div></a> <a href="mailto:{data.about.contact.email}"><div>Email</div></a>
</div> </div>
{/if} {/if}
</Query> </Query>

View File

@ -4,13 +4,13 @@
import { createQuery } from '@tanstack/svelte-query'; import { createQuery } from '@tanstack/svelte-query';
import Query from '$lib/components/Query.svelte'; import Query from '$lib/components/Query.svelte';
const query = createQuery(['socials'], queries.socials); const aboutQuery = createQuery(['about'], queries.about);
</script> </script>
<div class="social-host"> <div class="social-host">
<Query {query} let:data> <Query query={aboutQuery} let:data>
{#if data} {#if data}
{#each data.socials.filter((s) => s.name != 'Website') as social} {#each data.about.socials.filter((s) => s.name != 'Website') as social}
<SocialButton {social} /> <SocialButton {social} />
{/each} {/each}
{/if} {/if}

View File

@ -78,12 +78,10 @@
<Navigation href="/" label="Home">Home</Navigation> <Navigation href="/" label="Home">Home</Navigation>
<Navigation queryKey="manager" href="/download" label="Download">Download</Navigation> <Navigation queryKey="manager" href="/download" label="Download">Download</Navigation>
<Navigation queryKey="patches" href="/patches" label="Patches">Patches</Navigation> <Navigation queryKey="patches" href="/patches" label="Patches">Patches</Navigation>
<Navigation queryKey="repositories" href="/contributors" label="Contributors"> <Navigation queryKey="contributors" href="/contributors" label="Contributors">
Contributors Contributors
</Navigation> </Navigation>
<Navigation queryKey={['donate', 'team']} href="/donate" label="Donate"> <Navigation queryKey={['about', 'team']} href="/donate" label="Donate">Donate</Navigation>
Donate
</Navigation>
</ul> </ul>
</div> </div>
<div id="secondary-navigation"> <div id="secondary-navigation">

View File

@ -1,10 +1,11 @@
export interface Contributor { export interface Contributor {
login: string; name: string;
avatar_url: string; avatar_url: string;
html_url: string; url: string;
contributions: number;
} }
export interface Repository { export interface Contributable {
name: string; name: string;
contributors: Contributor[]; contributors: Contributor[];
} }
@ -33,24 +34,20 @@ export interface PatchOption {
export interface Asset { export interface Asset {
name: string; name: string;
content_type: string; download_url: string;
browser_download_url: string;
} }
export interface Metadata { export interface Release {
tag_name: string; version: string;
name: string;
draft: boolean;
prerelease: boolean;
created_at: string; created_at: string;
published_at: string; description: string;
body: string; assets: Asset[];
} }
export interface TeamMember { export interface TeamMember {
login: string; name: string;
avatar_url: string; avatar_url: string;
html_url: string; url: string;
bio?: string; bio?: string;
} }
@ -70,6 +67,7 @@ export interface DonationPlatform {
export interface Social { export interface Social {
name: string; name: string;
url: string; url: string;
preferred: boolean;
} }
interface Donations { interface Donations {
@ -81,7 +79,7 @@ interface Contact {
email: string; email: string;
} }
export interface Info { export interface About {
name: string; name: string;
about: string; about: string;
contact: Contact; contact: Contact;

View File

@ -10,7 +10,7 @@
import { queries } from '$data/api'; import { queries } from '$data/api';
import { createQuery } from '@tanstack/svelte-query'; import { createQuery } from '@tanstack/svelte-query';
const query = createQuery(['repositories'], queries.repositories); const query = createQuery(['contributors'], queries.contributors);
</script> </script>
<Head <Head
@ -52,7 +52,7 @@
</div> </div>
<div class="repos"> <div class="repos">
<Query {query} let:data> <Query {query} let:data>
{#each data.repositories as { contributors, name: repo }} {#each data.contributables as { contributors, name: repo }}
<div in:fly={{ y: 10, easing: quintOut, duration: 750 }}> <div in:fly={{ y: 10, easing: quintOut, duration: 750 }}>
<ContributorHost {contributors} {repo} /> <ContributorHost {contributors} {repo} />
</div> </div>

View File

@ -9,8 +9,7 @@
export let repo: string; export let repo: string;
let expanded = true; let expanded = true;
// Yes let bots = ['semantic-release-bot', 'revanced-bot'];
let usersIwantToExplodeSoBadly = ['semantic-release-bot', 'revanced-bot'];
let repo_name = friendlyName(repo); let repo_name = friendlyName(repo);
</script> </script>
@ -34,9 +33,9 @@
{#if expanded} {#if expanded}
<div class="contrib-host" transition:slide={{ easing: quintOut, duration: 500 }}> <div class="contrib-host" transition:slide={{ easing: quintOut, duration: 500 }}>
{#each contributors as { login, avatar_url, html_url }} {#each contributors as { name, avatar_url, url }}
{#if !usersIwantToExplodeSoBadly.includes(login)} {#if !bots.includes(name)}
<ContributorButton name={login} pfp={avatar_url} url={html_url} /> <ContributorButton {name} pfp={avatar_url} {url} />
{/if} {/if}
{/each} {/each}
</div> </div>

View File

@ -19,7 +19,7 @@
import { supportsWebP } from '$util/supportsWebP'; import { supportsWebP } from '$util/supportsWebP';
const teamQuery = createQuery(['team'], queries.team); const teamQuery = createQuery(['team'], queries.team);
const donateQuery = createQuery(['donate'], queries.donate); const aboutQuery = createQuery(['about'], queries.about);
let qrCodeDialogue = false; let qrCodeDialogue = false;
let cryptoDialogue = false; let cryptoDialogue = false;
@ -89,24 +89,24 @@
</div> </div>
</section> </section>
<h3>Donate</h3> <h3>Donate</h3>
<Query query={donateQuery} let:data> <Query query={aboutQuery} let:data>
<div class="donate-cards"> <div class="donate-cards">
{#if data.platforms} {#if data.about.donations.links}
{#each data.platforms as platform} {#each data.about.donations.links as link}
<a class="donate-card" target="_blank" rel="noreferrer" href={platform.url}> <a class="donate-card" target="_blank" rel="noreferrer" href={link.url}>
<!-- not using <img/> because we want the image height to always be 200px --> <!-- not using <img/> because we want the image height to always be 200px -->
<div <div
style="background-image: url('/donate/card-images/{platform.name}.{supportsWebP() style="background-image: url('/donate/card-images/{link.name}.{supportsWebP()
? 'webp' ? 'webp'
: 'png'}'), url('/donate/card-images/fallback.svg');" : 'png'}'), url('/donate/card-images/fallback.svg');"
role="img" role="img"
aria-label="{platform.name} preview image" aria-label="{link.name} preview image"
/> />
<span>{platform.name}</span> <span>{link.name}</span>
</a> </a>
{/each} {/each}
{/if} {/if}
{#if data.wallets} {#if data.about.donations.wallets}
<button class="donate-card" on:click={() => (cryptoDialogue = !cryptoDialogue)}> <button class="donate-card" on:click={() => (cryptoDialogue = !cryptoDialogue)}>
<div <div
style="background-image: url('/donate/card-images/Cryptocurrencies.{supportsWebP() style="background-image: url('/donate/card-images/Cryptocurrencies.{supportsWebP()
@ -141,8 +141,8 @@
<svelte:fragment slot="description"> <svelte:fragment slot="description">
<hr style="margin: 1rem 0;" /> <hr style="margin: 1rem 0;" />
<div class="wallets"> <div class="wallets">
<Query query={donateQuery} let:data> <Query query={aboutQuery} let:data>
{#each data.wallets as wallet} {#each data.about.donations.wallets as wallet}
<button <button
on:click={() => { on:click={() => {
qrCodeValue = wallet.address; qrCodeValue = wallet.address;

View File

@ -10,15 +10,15 @@
<a <a
class="member" class="member"
href={member.html_url} href={member.url}
rel="noreferrer" rel="noreferrer"
target="_blank" target="_blank"
in:fly|global={{ y: 10, easing: quintOut, duration: 750, delay: 50 * i }} in:fly|global={{ y: 10, easing: quintOut, duration: 750, delay: 50 * i }}
> >
<img src={member.avatar_url} alt="{member.login}'s profile picture." /> <img src={member.avatar_url} alt="{member.name}'s profile picture." />
<div class="member-text"> <div class="member-text">
<h4>{member.login}</h4> <h4>{member.name}</h4>
{#if member.bio} {#if member.bio}
<h6>{member.bio}</h6> <h6>{member.bio}</h6>
{/if} {/if}

View File

@ -75,7 +75,7 @@
<Query {query} let:data> <Query {query} let:data>
<Button <Button
type="text" type="text"
href={data.assets[0].browser_download_url} href={data.release.assets[0].download_url}
on:click={() => (warningDialogue = false)}>Okay</Button on:click={() => (warningDialogue = false)}>Okay</Button
> >
</Query> </Query>
@ -90,16 +90,16 @@
<Query {query} let:data> <Query {query} let:data>
{#if !isAndroid || androidVersion < 8} {#if !isAndroid || androidVersion < 8}
<Button on:click={handleClick} type="filled" icon="download"> <Button on:click={handleClick} type="filled" icon="download">
{data.metadata.tag_name} {data.release.version}
</Button> </Button>
{:else} {:else}
<Button <Button
on:click={handleClick} on:click={handleClick}
type="filled" type="filled"
icon="download" icon="download"
href={data.assets[0].browser_download_url} href={data.release.assets[0].download_url}
> >
{data.metadata.tag_name} {data.release.version}
</Button> </Button>
{/if} {/if}
</Query> </Query>