forked from Rosetta/landing
Redesign landing and generate Proto docs
This commit is contained in:
42
src/services/updates.ts
Normal file
42
src/services/updates.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
export interface DownloadRelease {
|
||||
platform: string;
|
||||
arch: string;
|
||||
version: string;
|
||||
link: string;
|
||||
}
|
||||
|
||||
interface UpdateItem {
|
||||
platform: string;
|
||||
arch: string;
|
||||
version: string;
|
||||
downloadUrl: string;
|
||||
}
|
||||
|
||||
const PLATFORM_ORDER = ['linux', 'win32', 'android'];
|
||||
const ARCH_ORDER = ['arm64', 'x64', 'universal'];
|
||||
|
||||
export async function fetchUpdates(signal?: AbortSignal): Promise<DownloadRelease[]> {
|
||||
const response = await fetch('https://sdu.rosetta.im/updates/all', { signal });
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Update server returned ${response.status}`);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as { items?: UpdateItem[] };
|
||||
|
||||
return (data.items || [])
|
||||
.map((item) => ({
|
||||
platform: item.platform,
|
||||
arch: item.arch,
|
||||
version: item.version,
|
||||
link: new URL(item.downloadUrl, 'https://sdu.rosetta.im').toString(),
|
||||
}))
|
||||
.sort((a, b) => {
|
||||
const platformComparison =
|
||||
PLATFORM_ORDER.indexOf(a.platform) - PLATFORM_ORDER.indexOf(b.platform);
|
||||
if (platformComparison !== 0) {
|
||||
return platformComparison;
|
||||
}
|
||||
return ARCH_ORDER.indexOf(a.arch) - ARCH_ORDER.indexOf(b.arch);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user