添加自动检测最新版本功能,更新应用信息时支持检测参数

This commit is contained in:
2026-02-05 01:07:44 +08:00
parent db5c5a89b3
commit 7bbefd8a4a

View File

@@ -6,6 +6,7 @@ import { getUidByUsername, prefixFix } from './util.ts';
import { deleteFiles, getMinioListAndSetToAppList } from '../file/index.ts';
import { setExpire } from './revoke.ts';
import { User } from '@/models/user.ts';
import { callDetectAppVersion } from './export.ts';
app
.route({
path: 'app',
@@ -258,7 +259,7 @@ app
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const { id, username, appKey, version } = ctx.query.data;
const { id, username, appKey, version, detect } = ctx.query.data;
if (!id && !appKey) {
throw new CustomError('id or appKey is required');
}
@@ -268,22 +269,31 @@ app
if (id) {
appList = await AppListModel.findByPk(id);
if (appList?.uid !== uid) {
throw new CustomError('no permission');
ctx.throw('no permission');
}
}
if (!appList && appKey) {
if (!version) {
throw new CustomError('version is required');
ctx.throw('version is required');
}
appList = await AppListModel.findOne({ where: { key: appKey, version, uid } });
}
if (!appList) {
throw new CustomError('app not found');
ctx.throw('app 未发现');
}
if (detect) {
// 自动检测最新版本
const res = await callDetectAppVersion({ appKey, version, username: username || tokenUser.username }, ctx.query.token);
if (res.code !== 200) {
ctx.throw(res.message || '检测版本列表失败');
}
appList = await AppListModel.findByPk(appList.id);
}
const files = appList.data.files || [];
const am = await AppModel.findOne({ where: { key: appList.key, uid: uid } });
if (!am) {
throw new CustomError('app not found');
ctx.throw('app 未发现');
}
await am.update({ data: { ...am.data, files }, version: appList.version });
setExpire(appList.key, am.user);
@@ -385,7 +395,7 @@ app
am = await AppModel.create({
title: appKey,
key: appKey,
version: version || '0.0.0',
version: version || '0.0.1',
user: checkUsername,
uid,
data: { files: needAddFiles },