From 44e60e02a6183cd658dcd31b854bd816fa6ba9b4 Mon Sep 17 00:00:00 2001 From: madkarmaa Date: Tue, 29 Apr 2025 09:36:57 +0200 Subject: [PATCH] feat: add mock data --- src/lib/api/index.ts | 299 ++++++++++++++++++++++++++++++++++++ src/lib/api/interfaces.d.ts | 2 +- src/lib/api/models.d.ts | 2 + 3 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 src/lib/api/index.ts diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts new file mode 100644 index 0000000..9404117 --- /dev/null +++ b/src/lib/api/index.ts @@ -0,0 +1,299 @@ +import type * as Interfaces from '$api/interfaces'; +import type * as Models from '$api/models'; + +const mockAnnouncements: Models.BackendResponseAnnouncement[] = [ + { + id: 1, + title: 'ReVanced 2.0 Released', + content: 'We are excited to announce the release of ReVanced 2.0 with many new features!', + created_at: new Date('2023-10-01'), + author: 'ReVanced Team', + tags: ['release', 'major'] + }, + { + id: 2, + title: 'Patch Updates Available', + content: 'Several patches have been updated to support the latest app versions.', + created_at: new Date('2023-10-15'), + author: 'Patch Team', + tags: ['patches', 'update'] + }, + { + id: 3, + title: 'Community Guidelines Update', + content: 'Please review our updated community guidelines.', + created_at: new Date('2023-09-20'), + author: 'Moderator', + tags: ['community', 'rules'] + } +].sort((a, b) => b.created_at.getTime() - a.created_at.getTime()); + +const mockPatches: Models.BackendPatch[] = [ + { + name: 'Remove Ads', + description: 'Removes advertisements from the application', + compatiblePackages: { + 'com.example.app': ['1.0.0', '1.1.0', '1.2.0'] + }, + options: [ + { + title: 'Remove all ads', + description: 'Removes all advertisements completely', + required: true + } + ] + }, + { + name: 'Background Play', + description: 'Allows playing media in the background', + compatiblePackages: { + 'com.example.app': ['1.0.0', '1.1.0'], + 'com.media.app': ['2.0.0', '2.1.0'] + }, + options: [ + { + title: 'Notification Style', + description: 'Choose the style of the notification', + required: false, + values: [ + { + name: 'compact', + value: 'Compact view' + }, + { + name: 'expanded', + value: 'Expanded view' + } + ] + } + ] + } +]; + +const mockContributors: Models.BackendContributable[] = [ + { + name: 'ReVanced Core', + url: 'https://github.com/revanced/revanced-core', + contributors: [ + { + name: 'Contributor1', + avatar_url: 'https://github.com/avatar1.png', + contributions: 45, + url: 'https://github.com/contributor1' + }, + { + name: 'Contributor2', + avatar_url: 'https://github.com/avatar2.png', + contributions: 32, + url: 'https://github.com/contributor2' + } + ] + } +]; + +const mockTeamMembers: Models.BackendTeamMember[] = [ + { + name: 'Team Member 1', + avatar_url: 'https://github.com/team1.png', + url: 'https://github.com/teammember1', + bio: 'Core developer and project lead' + }, + { + name: 'Team Member 2', + avatar_url: 'https://github.com/team2.png', + url: 'https://github.com/teammember2', + bio: 'UI/UX designer', + gpg_key: { + id: 'ABC123', + url: 'https://keys.openpgp.org/key/ABC123' + } + } +]; + +const mockAbout: Models.BackendAbout = { + contact: { + email: 'contact@revanced.app' + }, + donations: { + links: [ + { + name: 'GitHub Sponsors', + preferred: true, + url: 'https://github.com/sponsors/revanced' + }, + { + name: 'Open Collective', + preferred: false, + url: 'https://opencollective.com/revanced' + } + ], + wallets: [ + { + address: '0x123456789abcdef', + currency_code: 'ETH', + network: 'Ethereum', + preferred: true + } + ] + }, + socials: [ + { + name: 'GitHub', + preferred: true, + url: 'https://github.com/revanced' + }, + { + name: 'Twitter', + preferred: false, + url: 'https://twitter.com/revancedapp' + } + ], + status: 'https://status.revanced.app' +}; + +class MockAnnouncementsApi implements Interfaces.AnnouncementsApi { + async getAnnouncements( + cursor?: number, + count?: number, + tag?: string + ): Promise { + let result = [...mockAnnouncements]; + + if (tag) result = result.filter((announcement) => announcement.tags?.includes(tag)); + if (cursor !== undefined) result = result.slice(cursor); + if (count !== undefined) result = result.slice(0, count); + + return result; + } + + async getLatestAnnouncement(tag?: string): Promise { + const announcements = await this.getAnnouncements(undefined, 1, tag); + return announcements; + } + + async getLatestAnnouncementIds(tag?: string): Promise { + const announcements = await this.getAnnouncements(undefined, undefined, tag); + return announcements.map((a) => ({ id: a.id, title: a.title, created_at: a.created_at })); + } + + async getAnnouncement(id: number): Promise { + const announcement = mockAnnouncements.find((a) => a.id === id); + if (!announcement) throw new Error(`Announcement with ID ${id} not found`); + + return announcement; + } + + async createAnnouncement( + announcement: Models.BackendAnnouncement, + authToken: string + ): Promise { + console.log('Created announcement with token:', authToken); + return Promise.resolve(); + } + + async updateAnnouncement( + id: number, + announcement: Models.BackendAnnouncement, + authToken: string + ): Promise { + console.log(`Updated announcement ${id} with token:`, authToken); + return Promise.resolve(); + } + + async deleteAnnouncement(id: number, authToken: string): Promise { + console.log(`Deleted announcement ${id} with token:`, authToken); + return Promise.resolve(); + } + + async getAnnouncementTags(): Promise { + const tags = new Set(); + mockAnnouncements.forEach((a) => { + a.tags?.forEach((tag) => tags.add(tag)); + }); + return Array.from(tags).map((tag) => ({ name: tag })); + } +} + +class MockPatchesApi implements Interfaces.PatchesApi { + async getCurrentRelease(prerelease?: boolean): Promise { + return { + created_at: new Date('2023-10-01'), + description: 'Latest patches release with bug fixes', + download_url: + 'https://github.com/ReVanced/revanced-patches/releases/download/v5.21.0/patches-5.21.0.rvp', + version: 'v5.21.0', + signature_download_url: + 'https://github.com/ReVanced/revanced-patches/releases/download/v5.21.0/patches-5.21.0.rvp.asc' + }; + } + + async getCurrentReleaseVersion(prerelease?: boolean): Promise { + return { + version: 'v5.21.0' + }; + } + + async getPatchesList(prerelease?: boolean): Promise { + return mockPatches; + } +} + +class MockManagerApi implements Interfaces.ManagerApi { + async getCurrentRelease(prerelease?: boolean): Promise { + return { + created_at: new Date('2023-10-05'), + description: 'Latest manager release', + download_url: + 'https://github.com/ReVanced/revanced-manager/releases/download/v1.24.0/revanced-manager-1.24.0.apk', + version: 'v1.24.0' + }; + } + + async getCurrentReleaseVersion(prerelease?: boolean): Promise { + return { + version: 'v1.24.0' + }; + } +} + +class MockGeneralApi implements Interfaces.GeneralApi { + async getToken(username: string, password: string): Promise { + if (username === 'admin' && password === 'password') { + return { token: 'mock-auth-token-12345' }; + } + throw new Error('Invalid credentials'); + } + + async getContributors(): Promise { + return mockContributors; + } + + async getTeamMembers(): Promise { + return mockTeamMembers; + } + + async getAbout(): Promise { + return mockAbout; + } + + async ping(): Promise { + return Math.random() >= 0.5; + } + + async getRateLimit(): Promise { + return { + limit: 60, + remaining: 59, + reset: new Date(Date.now() + 3600000) + }; + } +} + +const api: Interfaces.ReVancedApi = { + announcements: new MockAnnouncementsApi(), + patches: new MockPatchesApi(), + manager: new MockManagerApi(), + general: new MockGeneralApi() +}; + +export default api; diff --git a/src/lib/api/interfaces.d.ts b/src/lib/api/interfaces.d.ts index fc9ff9f..2324301 100644 --- a/src/lib/api/interfaces.d.ts +++ b/src/lib/api/interfaces.d.ts @@ -16,7 +16,7 @@ export interface AnnouncementsApi { authToken: string ): Promise; deleteAnnouncement(id: number, authToken: string): Promise; - getAnnouncementTags(): Promise; + getAnnouncementTags(): Promise; } export interface PatchesApi { diff --git a/src/lib/api/models.d.ts b/src/lib/api/models.d.ts index 633b17d..25761cd 100644 --- a/src/lib/api/models.d.ts +++ b/src/lib/api/models.d.ts @@ -20,6 +20,8 @@ export type BackendAnnouncement = { title: string; }; +export type BackendAnnouncementTag = { name: string }; + type BackendAssetRelease = { created_at: Date; description: string;