chore: add update dialog
This commit is contained in:
33
src/lib/api/git.ts
Normal file
33
src/lib/api/git.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { Release } from '@/types';
|
||||
import { betterFetch } from '@better-fetch/fetch';
|
||||
import semver from 'semver';
|
||||
|
||||
const ENDPOINT = 'https://git.ez-pp.farm/';
|
||||
|
||||
const timeout = 5000; // 5 seconds;
|
||||
|
||||
export const git = {
|
||||
hasUpdate: async (version: string): Promise<Release | undefined> => {
|
||||
try {
|
||||
const request = await betterFetch<Release[]>(
|
||||
`${ENDPOINT}api/v1/repos/EZPPFarm/EZPPLauncher/releases?limit=1`,
|
||||
{
|
||||
timeout,
|
||||
headers: {
|
||||
'User-Agent': 'EZPPLauncher',
|
||||
},
|
||||
}
|
||||
);
|
||||
if (request.error) return undefined;
|
||||
|
||||
const latestRelease = request.data[0];
|
||||
if (!latestRelease) return undefined;
|
||||
|
||||
const hasUpdate = semver.lt(version, latestRelease.tag_name);
|
||||
|
||||
return hasUpdate ? latestRelease : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user