[client] Fix update check

This commit is contained in:
Laura Hausmann 2023-11-29 17:28:20 +01:00
parent aaed62bde1
commit cd8809e927
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
4 changed files with 23 additions and 42 deletions

View file

@ -1,4 +1,5 @@
import define from "../define.js"; import define from "../define.js";
import config from "@/config/index.js";
export const meta = { export const meta = {
tags: ["meta"], tags: ["meta"],
@ -16,7 +17,7 @@ export const paramDef = {
export default define(meta, paramDef, async () => { export default define(meta, paramDef, async () => {
let tag_name; let tag_name;
await fetch( 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((response) => response.json())
.then((data) => { .then((data) => {

View file

@ -88,6 +88,7 @@ import {
provideMetadataReceiver, provideMetadataReceiver,
setPageMetadata, setPageMetadata,
} from "@/scripts/page-metadata"; } from "@/scripts/page-metadata";
import { isUpdateAvailable } from "@/scripts/is-update-available.js";
const isEmpty = (x: string | null) => x == null || x === ""; const isEmpty = (x: string | null) => x == null || x === "";
const el = ref<HTMLElement | null>(null); const el = ref<HTMLElement | null>(null);
@ -125,26 +126,7 @@ os.api("admin/abuse-user-reports", {
}); });
if (defaultStore.state.showAdminUpdates) { if (defaultStore.state.showAdminUpdates) {
os.api("latest-version").then((res) => { updateAvailable = await isUpdateAvailable();
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;
});
} }
const NARROW_THRESHOLD = 600; const NARROW_THRESHOLD = 600;

View 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}`;
});
}

View file

@ -149,6 +149,7 @@ import { defaultStore } from "@/store";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { instance } from "@/instance"; import { instance } from "@/instance";
import { version } from "@/config"; import { version } from "@/config";
import { isUpdateAvailable } from "@/scripts/is-update-available.js";
const isEmpty = (x: string | null) => x == null || x === ""; const isEmpty = (x: string | null) => x == null || x === "";
@ -196,26 +197,7 @@ if ($i?.isAdmin) {
}); });
if (defaultStore.state.showAdminUpdates) { if (defaultStore.state.showAdminUpdates) {
os.api("latest-version").then((res) => { updateAvailable = await isUpdateAvailable();
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;
});
} }
} }