Feat: add versionChanged status

This commit is contained in:
unitwk 2023-11-07 15:05:48 +08:00
parent 5ad53f11e3
commit 479b58a57d
5 changed files with 28 additions and 2 deletions

View File

@ -25,6 +25,7 @@ const { updateUserInfo, state } = useAppStateStore();
async function checkPanelStatus() {
const status = await panelStatus().execute();
state.isInstall = status.value?.isInstall ?? true;
state.versionChanged = status.value?.versionChange ? true : false;
if (!state.isInstall) {
return router.push({
path: "/init"

View File

@ -37,6 +37,7 @@ export const panelStatus = useDefineApi<
{
isInstall: boolean;
language: string;
versionChange?: string;
}
>({
url: "/api/auth/status",

View File

@ -7,6 +7,7 @@ import type { BaseUserInfo } from "@/types/user";
interface AppStateInfo {
userInfo: BaseUserInfo | null;
isInstall: boolean;
versionChanged: boolean;
}
export const useAppStateStore = createGlobalState(() => {
@ -14,7 +15,8 @@ export const useAppStateStore = createGlobalState(() => {
const state: AppStateInfo = reactive<AppStateInfo>({
userInfo: null,
isInstall: true
isInstall: true,
versionChanged: false
});
const cloneState = (): AppStateInfo => {

View File

@ -10,6 +10,7 @@ import userSystem from "../../service/system_user";
import { logger } from "../../service/log";
import { $t } from "../../i18n";
import axios from "axios";
import GlobalVariable from "../../common/global_variable";
const router = new Router({ prefix: "/auth" });
// [Public Permission]
@ -66,6 +67,7 @@ router.all(
isInstall = false;
}
ctx.body = {
versionChange: GlobalVariable.get("versionChange", null),
isInstall,
language: systemConfig.language || null
};

View File

@ -1,21 +1,41 @@
import * as fs from "fs-extra";
import GlobalVariable from "./common/global_variable";
import { logger } from "./service/log";
import path from "path";
const PACKAGE_JSON = "package.json";
let CURRENT_VERSION = "";
const VERSION_LOG_TEXT_PATH = path.normalize(path.join(process.cwd(), "data/current-version.txt"));
interface PackageInfo {
name: string;
version: string;
daemonVersion: string;
description: string;
}
export function initVersionManager() {
try {
GlobalVariable.set("version", "Unknown");
if (fs.existsSync(PACKAGE_JSON)) {
const data: any = JSON.parse(fs.readFileSync(PACKAGE_JSON, { encoding: "utf-8" }));
const data: PackageInfo = JSON.parse(fs.readFileSync(PACKAGE_JSON, { encoding: "utf-8" }));
if (data.version) {
GlobalVariable.set("version", data.version);
CURRENT_VERSION = String(data.version);
}
}
} catch (error) {
logger.error("Version Check failure:", error);
}
if (CURRENT_VERSION && fs.existsSync(VERSION_LOG_TEXT_PATH)) {
const LastLaunchedVersion = fs.readFileSync(VERSION_LOG_TEXT_PATH, { encoding: "utf-8" });
if (LastLaunchedVersion && LastLaunchedVersion != CURRENT_VERSION) {
logger.info(`Version changed from ${LastLaunchedVersion} to ${CURRENT_VERSION}`);
GlobalVariable.set("versionChange", CURRENT_VERSION);
}
}
fs.writeFileSync(VERSION_LOG_TEXT_PATH, CURRENT_VERSION, { encoding: "utf-8" });
}
export function getVersion(): string {