mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 03:17:38 -07:00
[client] Fix update check
This commit is contained in:
parent
aaed62bde1
commit
cd8809e927
4 changed files with 23 additions and 42 deletions
|
@ -1,4 +1,5 @@
|
|||
import define from "../define.js";
|
||||
import config from "@/config/index.js";
|
||||
|
||||
export const meta = {
|
||||
tags: ["meta"],
|
||||
|
@ -16,7 +17,7 @@ export const paramDef = {
|
|||
export default define(meta, paramDef, async () => {
|
||||
let tag_name;
|
||||
await fetch(
|
||||
"https://iceshrimp.dev/api/v1/repos/iceshrimp/iceshrimp/releases?draft=false&pre-release=false&page=1&limit=1",
|
||||
`https://iceshrimp.dev/api/v1/repos/iceshrimp/iceshrimp/releases?draft=false&pre-release=${config.version.includes('-pre')}&page=1&limit=1`,
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
|
|
|
@ -88,6 +88,7 @@ import {
|
|||
provideMetadataReceiver,
|
||||
setPageMetadata,
|
||||
} from "@/scripts/page-metadata";
|
||||
import { isUpdateAvailable } from "@/scripts/is-update-available.js";
|
||||
|
||||
const isEmpty = (x: string | null) => x == null || x === "";
|
||||
const el = ref<HTMLElement | null>(null);
|
||||
|
@ -125,26 +126,7 @@ os.api("admin/abuse-user-reports", {
|
|||
});
|
||||
|
||||
if (defaultStore.state.showAdminUpdates) {
|
||||
os.api("latest-version").then((res) => {
|
||||
if (!res?.tag_name) {
|
||||
updateAvailable = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const tag = res.tag_name as string;
|
||||
if (tag === `v${version}`) {
|
||||
updateAvailable = false;
|
||||
return;
|
||||
}
|
||||
const tagDate = tag.includes('-') ? tag.substring(0, tag.indexOf('-')) : tag;
|
||||
const versionDate = version.includes('-') ? version.substring(0, version.indexOf('-')) : version;
|
||||
if (tagDate < versionDate) {
|
||||
updateAvailable = false;
|
||||
return;
|
||||
}
|
||||
updateAvailable = true;
|
||||
return;
|
||||
});
|
||||
updateAvailable = await isUpdateAvailable();
|
||||
}
|
||||
|
||||
const NARROW_THRESHOLD = 600;
|
||||
|
|
16
packages/client/src/scripts/is-update-available.ts
Normal file
16
packages/client/src/scripts/is-update-available.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { version } from "@/config.js";
|
||||
import * as os from "@/os.js";
|
||||
|
||||
type LatestVersionResponse = {
|
||||
tag_name?: string;
|
||||
};
|
||||
|
||||
export async function isUpdateAvailable(): Promise<boolean> {
|
||||
if (version.includes('-dev-')) return false;
|
||||
|
||||
return os.api("latest-version").then((res: LatestVersionResponse) => {
|
||||
if (!res?.tag_name) return false;
|
||||
const tag = res.tag_name as string;
|
||||
return (version.includes('-pre') && !tag.includes('-pre')) || tag > `v${version}`;
|
||||
});
|
||||
}
|
|
@ -149,6 +149,7 @@ import { defaultStore } from "@/store";
|
|||
import { i18n } from "@/i18n";
|
||||
import { instance } from "@/instance";
|
||||
import { version } from "@/config";
|
||||
import { isUpdateAvailable } from "@/scripts/is-update-available.js";
|
||||
|
||||
const isEmpty = (x: string | null) => x == null || x === "";
|
||||
|
||||
|
@ -196,26 +197,7 @@ if ($i?.isAdmin) {
|
|||
});
|
||||
|
||||
if (defaultStore.state.showAdminUpdates) {
|
||||
os.api("latest-version").then((res) => {
|
||||
if (!res?.tag_name) {
|
||||
updateAvailable = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const tag = res.tag_name as string;
|
||||
if (tag === `v${version}`) {
|
||||
updateAvailable = false;
|
||||
return;
|
||||
}
|
||||
const tagDate = tag.includes('-') ? tag.substring(0, tag.indexOf('-')) : tag;
|
||||
const versionDate = version.includes('-') ? version.substring(0, version.indexOf('-')) : version;
|
||||
if (tagDate < versionDate) {
|
||||
updateAvailable = false;
|
||||
return;
|
||||
}
|
||||
updateAvailable = true;
|
||||
return;
|
||||
});
|
||||
updateAvailable = await isUpdateAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue