mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-18 20:30:08 +08:00
Refactor version API to GetNapCatVersion endpoint
Replaces the PackageInfo API and related frontend usage with a dedicated GetNapCatVersion endpoint that returns only the NapCat version string. Updates backend handler, helper, types, router, and frontend components to use the new API for improved clarity and separation of concerns.
This commit is contained in:
parent
f553f9dc8d
commit
e9856ac80f
@ -4,9 +4,9 @@ import { WebUiDataRuntime } from '@/napcat-webui-backend/helper/Data';
|
||||
import { sendSuccess } from '@/napcat-webui-backend/utils/response';
|
||||
import { WebUiConfig } from '@/napcat-webui-backend/index';
|
||||
|
||||
export const PackageInfoHandler: RequestHandler = (_, res) => {
|
||||
const data = WebUiDataRuntime.getPackageJson();
|
||||
sendSuccess(res, data);
|
||||
export const GetNapCatVersion: RequestHandler = (_, res) => {
|
||||
const data = WebUiDataRuntime.GetNapCatVersion();
|
||||
sendSuccess(res, { version: data });
|
||||
};
|
||||
|
||||
export const QQVersionHandler: RequestHandler = (_, res) => {
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import type { LoginRuntimeType } from '../types/data';
|
||||
import packageJson from '../../../../package.json';
|
||||
import store from 'napcat-common/src/store';
|
||||
import { napCatVersion } from 'napcat-common/src/version';
|
||||
|
||||
@ -31,12 +30,11 @@ const LoginRuntime: LoginRuntimeType = {
|
||||
QQLoginList: [],
|
||||
NewQQLoginList: [],
|
||||
},
|
||||
packageJson,
|
||||
NapCatVersion: napCatVersion,
|
||||
WebUiConfigQuickFunction: async () => {
|
||||
|
||||
},
|
||||
};
|
||||
packageJson.version = napCatVersion;
|
||||
export const WebUiDataRuntime = {
|
||||
setWebUiTokenChangeCallback (func: (token: string) => Promise<void>): void {
|
||||
LoginRuntime.onWebUiTokenChange = func;
|
||||
@ -131,8 +129,8 @@ export const WebUiDataRuntime = {
|
||||
return LoginRuntime.NapCatHelper.onOB11ConfigChanged(ob11);
|
||||
} as LoginRuntimeType['NapCatHelper']['onOB11ConfigChanged'],
|
||||
|
||||
getPackageJson () {
|
||||
return LoginRuntime.packageJson;
|
||||
GetNapCatVersion () {
|
||||
return LoginRuntime.NapCatVersion;
|
||||
},
|
||||
|
||||
setQQVersion (version: string) {
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { Router } from 'express';
|
||||
import { GetThemeConfigHandler, PackageInfoHandler, QQVersionHandler, SetThemeConfigHandler } from '../api/BaseInfo';
|
||||
import { GetThemeConfigHandler, GetNapCatVersion, QQVersionHandler, SetThemeConfigHandler } from '../api/BaseInfo';
|
||||
import { StatusRealTimeHandler } from '@/napcat-webui-backend/api/Status';
|
||||
import { GetProxyHandler } from '../api/Proxy';
|
||||
|
||||
const router = Router();
|
||||
// router: 获取nc的package.json信息
|
||||
router.get('/QQVersion', QQVersionHandler);
|
||||
router.get('/PackageInfo', PackageInfoHandler);
|
||||
router.get('/GetNapCatVersion', GetNapCatVersion);
|
||||
router.get('/GetSysStatusRealTime', StatusRealTimeHandler);
|
||||
router.get('/proxy', GetProxyHandler);
|
||||
router.get('/Theme', GetThemeConfigHandler);
|
||||
|
||||
@ -18,5 +18,5 @@ interface LoginRuntimeType {
|
||||
QQLoginList: string[];
|
||||
NewQQLoginList: LoginListItem[];
|
||||
};
|
||||
packageJson: object;
|
||||
NapCatVersion: string;
|
||||
}
|
||||
|
||||
@ -201,7 +201,7 @@ const NapCatVersion = () => {
|
||||
data: packageData,
|
||||
loading: packageLoading,
|
||||
error: packageError,
|
||||
} = useRequest(WebUIManager.getPackageInfo);
|
||||
} = useRequest(WebUIManager.GetNapCatVersion);
|
||||
|
||||
const currentVersion = packageData?.version;
|
||||
|
||||
|
||||
@ -42,9 +42,9 @@ export default class WebUIManager {
|
||||
return data.data as ServerResponse<T>;
|
||||
}
|
||||
|
||||
public static async getPackageInfo () {
|
||||
public static async GetNapCatVersion () {
|
||||
const { data } =
|
||||
await serverRequest.get<ServerResponse<PackageInfo>>('/base/PackageInfo');
|
||||
await serverRequest.get<ServerResponse<PackageInfo>>('/base/GetNapCatVersion');
|
||||
return data.data;
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ import logo from '@/assets/images/logo.png';
|
||||
import WebUIManager from '@/controllers/webui_manager';
|
||||
|
||||
function VersionInfo () {
|
||||
const { data, loading, error } = useRequest(WebUIManager.getPackageInfo);
|
||||
const { data, loading, error } = useRequest(WebUIManager.GetNapCatVersion);
|
||||
return (
|
||||
<div className='flex items-center gap-2 text-2xl font-bold'>
|
||||
<div className='flex items-center gap-2'>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user