Skip to content

Commit f428902

Browse files
authored
chore: Switch to v3 API (#247)
1 parent 145c11e commit f428902

File tree

10 files changed

+75
-103
lines changed

10 files changed

+75
-103
lines changed

src/data/api/index.ts

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ import * as settings from './settings';
33
// API Endpoints
44
import type {
55
Patch,
6-
Repository,
7-
Metadata,
8-
Asset,
6+
Contributable,
7+
Release,
98
TeamMember,
109
DonationPlatform,
1110
CryptoWallet,
1211
Social,
13-
Info,
12+
About,
1413
CompatiblePackage
1514
} from '$lib/types';
1615

17-
export type ReposData = { repositories: Repository[] };
16+
export type ContributorsData = { contributables: Contributable[] };
1817
export type PatchesData = { patches: Patch[]; packages: string[] };
19-
export type ReleaseData = { metadata: Metadata; assets: Asset[] };
18+
export type ReleaseData = { release: Release };
2019
export type TeamData = { members: TeamMember[] };
21-
export type InfoData = { info: Info };
20+
export type AboutData = { about: About };
2221
export type DonationData = { wallets: CryptoWallet[]; platforms: DonationPlatform[] };
2322
export type SocialsData = { socials: Social[] };
2423

@@ -27,25 +26,24 @@ async function get_json(endpoint: string) {
2726
return await fetch(url).then((r) => r.json());
2827
}
2928

30-
async function repositories(): Promise<ReposData> {
31-
const json = await get_json('contributors');
32-
return { repositories: json.repositories };
29+
async function contributors(): Promise<ContributorsData> {
30+
const json = await get_json('v3/contributors');
31+
return { contributables: json };
3332
}
3433

3534
async function manager(): Promise<ReleaseData> {
36-
const json = await get_json('v2/revanced-manager/releases/latest');
37-
// console.log(json.release.metadata.tag_name);
38-
console.log(json.release.assets[0].browser_download_url);
39-
return { metadata: json.release.metadata, assets: json.release.assets };
35+
const json = await get_json('v3/manager/latest');
36+
37+
return { release: json };
4038
}
4139

4240
async function patches(): Promise<PatchesData> {
43-
const json = await get_json('v2/patches/latest');
41+
const json = await get_json('v3/patches/latest/list');
4442
const packagesWithCount: { [key: string]: number } = {};
4543

4644
// gets packages and patch count
47-
for (let i = 0; i < json.patches.length; i++) {
48-
json.patches[i].compatiblePackages?.forEach((pkg: CompatiblePackage) => {
45+
for (let i = 0; i < json.length; i++) {
46+
json[i].compatiblePackages?.forEach((pkg: CompatiblePackage) => {
4947
packagesWithCount[pkg.name] = (packagesWithCount[pkg.name] || 0) + 1;
5048
});
5149
}
@@ -54,27 +52,17 @@ async function patches(): Promise<PatchesData> {
5452
const packages = Object.keys(packagesWithCount);
5553
packages.sort((a, b) => packagesWithCount[b] - packagesWithCount[a]);
5654

57-
return { patches: json.patches, packages };
55+
return { patches: json, packages };
5856
}
5957

6058
async function team(): Promise<TeamData> {
61-
const json = await get_json('v2/team/members');
62-
return { members: json.members };
63-
}
64-
65-
async function info(): Promise<InfoData> {
66-
const json = await get_json('v2/info');
67-
return { info: json.info };
68-
}
69-
70-
async function donate(): Promise<DonationData> {
71-
const json = await get_json('v2/donations');
72-
return { wallets: json.donations.wallets, platforms: json.donations.links };
59+
const json = await get_json('v3/team');
60+
return { members: json };
7361
}
7462

75-
async function socials(): Promise<SocialsData> {
76-
const json = await get_json('v2/socials');
77-
return { socials: json.socials };
63+
async function about(): Promise<AboutData> {
64+
const json = await get_json('v3/about');
65+
return { about: json };
7866
}
7967

8068
export const staleTime = 5 * 60 * 1000;
@@ -89,29 +77,19 @@ export const queries = {
8977
queryFn: patches,
9078
staleTime
9179
},
92-
repositories: {
93-
queryKey: ['repositories'],
94-
queryFn: repositories,
80+
contributors: {
81+
queryKey: ['contributors'],
82+
queryFn: contributors,
9583
staleTime
9684
},
9785
team: {
9886
queryKey: ['team'],
9987
queryFn: team,
10088
staleTime
10189
},
102-
info: {
90+
about: {
10391
queryKey: ['info'],
104-
queryFn: info,
105-
staleTime
106-
},
107-
donate: {
108-
queryKey: ['donate'],
109-
queryFn: donate,
110-
staleTime
111-
},
112-
socials: {
113-
queryKey: ['socials'],
114-
queryFn: socials,
92+
queryFn: about,
11593
staleTime
11694
}
11795
};

src/layout/Footer/FooterHost.svelte

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import Query from '$lib/components/Query.svelte';
99
import FooterSection from './FooterSection.svelte';
1010
11-
const infoQuery = createQuery(['info'], queries.info);
12-
const socialsQuery = createQuery(['socials'], queries.socials);
11+
const aboutQuery = createQuery(['about'], queries.about);
1312
</script>
1413

1514
<!-- squiggly divider line -->
@@ -33,11 +32,11 @@
3332
<div class="footer-top">
3433
<section class="main-content">
3534
<img src="/logo.svg" class="logo-image" alt="ReVanced Logo" />
36-
<Query query={infoQuery} let:data>
35+
<Query query={aboutQuery} let:data>
3736
{#if data}
3837
<div>
3938
<p>
40-
{data.info.about}
39+
{data.about.about}
4140
</p>
4241
</div>
4342
{/if}
@@ -52,10 +51,10 @@
5251
<li><a href="/contributors">Contributors</a></li>
5352
<li><a href="/donate">Donate</a></li>
5453
</FooterSection>
55-
<Query query={socialsQuery} let:data>
54+
<Query query={aboutQuery} let:data>
5655
{#if data}
5756
<FooterSection title="Socials">
58-
{#each data.socials as { name, url }}
57+
{#each data.about.socials as { name, url }}
5958
<li>
6059
<a href={url} target="_blank" rel="noreferrer">{name}</a>
6160
</li>
@@ -65,12 +64,12 @@
6564
</Query>
6665
</section>
6766
</div>
68-
<Query query={infoQuery} let:data>
67+
<Query query={aboutQuery} let:data>
6968
{#if data}
7069
<div class="footer-bottom">
7170
<div id="logo-name"><span>Re</span>Vanced</div>
7271
<a href="/donate"><div>Donate</div></a>
73-
<a href="mailto:{data.info.contact.email}"><div>Email</div></a>
72+
<a href="mailto:{data.about.contact.email}"><div>Email</div></a>
7473
</div>
7574
{/if}
7675
</Query>

src/layout/Hero/SocialHost.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import { createQuery } from '@tanstack/svelte-query';
55
import Query from '$lib/components/Query.svelte';
66
7-
const query = createQuery(['socials'], queries.socials);
7+
const aboutQuery = createQuery(['about'], queries.about);
88
</script>
99

1010
<div class="social-host">
11-
<Query {query} let:data>
11+
<Query query={aboutQuery} let:data>
1212
{#if data}
13-
{#each data.socials.filter((s) => s.name != 'Website') as social}
13+
{#each data.about.socials.filter((s) => s.name != 'Website') as social}
1414
<SocialButton {social} />
1515
{/each}
1616
{/if}

src/layout/Navbar/NavHost.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,10 @@
7878
<Navigation href="/" label="Home">Home</Navigation>
7979
<Navigation queryKey="manager" href="/download" label="Download">Download</Navigation>
8080
<Navigation queryKey="patches" href="/patches" label="Patches">Patches</Navigation>
81-
<Navigation queryKey="repositories" href="/contributors" label="Contributors">
81+
<Navigation queryKey="contributors" href="/contributors" label="Contributors">
8282
Contributors
8383
</Navigation>
84-
<Navigation queryKey={['donate', 'team']} href="/donate" label="Donate">
85-
Donate
86-
</Navigation>
84+
<Navigation queryKey={['about', 'team']} href="/donate" label="Donate">Donate</Navigation>
8785
</ul>
8886
</div>
8987
<div id="secondary-navigation">

src/lib/types.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
export interface Contributor {
2-
login: string;
2+
name: string;
33
avatar_url: string;
4-
html_url: string;
4+
url: string;
5+
contributions: number;
56
}
67

7-
export interface Repository {
8+
export interface Contributable {
89
name: string;
910
contributors: Contributor[];
1011
}
@@ -33,24 +34,20 @@ export interface PatchOption {
3334

3435
export interface Asset {
3536
name: string;
36-
content_type: string;
37-
browser_download_url: string;
37+
download_url: string;
3838
}
3939

40-
export interface Metadata {
41-
tag_name: string;
42-
name: string;
43-
draft: boolean;
44-
prerelease: boolean;
40+
export interface Release {
41+
version: string;
4542
created_at: string;
46-
published_at: string;
47-
body: string;
43+
description: string;
44+
assets: Asset[];
4845
}
4946

5047
export interface TeamMember {
51-
login: string;
48+
name: string;
5249
avatar_url: string;
53-
html_url: string;
50+
url: string;
5451
bio?: string;
5552
}
5653

@@ -70,6 +67,7 @@ export interface DonationPlatform {
7067
export interface Social {
7168
name: string;
7269
url: string;
70+
preferred: boolean;
7371
}
7472

7573
interface Donations {
@@ -81,7 +79,7 @@ interface Contact {
8179
email: string;
8280
}
8381

84-
export interface Info {
82+
export interface About {
8583
name: string;
8684
about: string;
8785
contact: Contact;

src/routes/contributors/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { queries } from '$data/api';
1111
import { createQuery } from '@tanstack/svelte-query';
1212
13-
const query = createQuery(['repositories'], queries.repositories);
13+
const query = createQuery(['contributors'], queries.contributors);
1414
</script>
1515

1616
<Head
@@ -52,7 +52,7 @@
5252
</div>
5353
<div class="repos">
5454
<Query {query} let:data>
55-
{#each data.repositories as { contributors, name: repo }}
55+
{#each data.contributables as { contributors, name: repo }}
5656
<div in:fly={{ y: 10, easing: quintOut, duration: 750 }}>
5757
<ContributorHost {contributors} {repo} />
5858
</div>

src/routes/contributors/ContributorSection.svelte

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
export let repo: string;
1010
let expanded = true;
1111
12-
// Yes
13-
let usersIwantToExplodeSoBadly = ['semantic-release-bot', 'revanced-bot'];
12+
let bots = ['semantic-release-bot', 'revanced-bot'];
1413
let repo_name = friendlyName(repo);
1514
</script>
1615

@@ -34,9 +33,9 @@
3433

3534
{#if expanded}
3635
<div class="contrib-host" transition:slide={{ easing: quintOut, duration: 500 }}>
37-
{#each contributors as { login, avatar_url, html_url }}
38-
{#if !usersIwantToExplodeSoBadly.includes(login)}
39-
<ContributorButton name={login} pfp={avatar_url} url={html_url} />
36+
{#each contributors as { name, avatar_url, url }}
37+
{#if !bots.includes(name)}
38+
<ContributorButton {name} pfp={avatar_url} {url} />
4039
{/if}
4140
{/each}
4241
</div>

src/routes/donate/+page.svelte

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import { supportsWebP } from '$util/supportsWebP';
2020
2121
const teamQuery = createQuery(['team'], queries.team);
22-
const donateQuery = createQuery(['donate'], queries.donate);
22+
const aboutQuery = createQuery(['about'], queries.about);
2323
2424
let qrCodeDialogue = false;
2525
let cryptoDialogue = false;
@@ -89,24 +89,24 @@
8989
</div>
9090
</section>
9191
<h3>Donate</h3>
92-
<Query query={donateQuery} let:data>
92+
<Query query={aboutQuery} let:data>
9393
<div class="donate-cards">
94-
{#if data.platforms}
95-
{#each data.platforms as platform}
96-
<a class="donate-card" target="_blank" rel="noreferrer" href={platform.url}>
94+
{#if data.about.donations.links}
95+
{#each data.about.donations.links as link}
96+
<a class="donate-card" target="_blank" rel="noreferrer" href={link.url}>
9797
<!-- not using <img/> because we want the image height to always be 200px -->
9898
<div
99-
style="background-image: url('/donate/card-images/{platform.name}.{supportsWebP()
99+
style="background-image: url('/donate/card-images/{link.name}.{supportsWebP()
100100
? 'webp'
101101
: 'png'}'), url('/donate/card-images/fallback.svg');"
102102
role="img"
103-
aria-label="{platform.name} preview image"
103+
aria-label="{link.name} preview image"
104104
/>
105-
<span>{platform.name}</span>
105+
<span>{link.name}</span>
106106
</a>
107107
{/each}
108108
{/if}
109-
{#if data.wallets}
109+
{#if data.about.donations.wallets}
110110
<button class="donate-card" on:click={() => (cryptoDialogue = !cryptoDialogue)}>
111111
<div
112112
style="background-image: url('/donate/card-images/Cryptocurrencies.{supportsWebP()
@@ -141,8 +141,8 @@
141141
<svelte:fragment slot="description">
142142
<hr style="margin: 1rem 0;" />
143143
<div class="wallets">
144-
<Query query={donateQuery} let:data>
145-
{#each data.wallets as wallet}
144+
<Query query={aboutQuery} let:data>
145+
{#each data.about.donations.wallets as wallet}
146146
<button
147147
on:click={() => {
148148
qrCodeValue = wallet.address;

src/routes/donate/TeamMember.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
<a
1212
class="member"
13-
href={member.html_url}
13+
href={member.url}
1414
rel="noreferrer"
1515
target="_blank"
1616
in:fly|global={{ y: 10, easing: quintOut, duration: 750, delay: 50 * i }}
1717
>
18-
<img src={member.avatar_url} alt="{member.login}'s profile picture." />
18+
<img src={member.avatar_url} alt="{member.name}'s profile picture." />
1919

2020
<div class="member-text">
21-
<h4>{member.login}</h4>
21+
<h4>{member.name}</h4>
2222
{#if member.bio}
2323
<h6>{member.bio}</h6>
2424
{/if}

0 commit comments

Comments
 (0)