添加自动检测最新版本功能,更新应用信息时支持检测参数
This commit is contained in:
@@ -6,6 +6,7 @@ import { getUidByUsername, prefixFix } from './util.ts';
|
|||||||
import { deleteFiles, getMinioListAndSetToAppList } from '../file/index.ts';
|
import { deleteFiles, getMinioListAndSetToAppList } from '../file/index.ts';
|
||||||
import { setExpire } from './revoke.ts';
|
import { setExpire } from './revoke.ts';
|
||||||
import { User } from '@/models/user.ts';
|
import { User } from '@/models/user.ts';
|
||||||
|
import { callDetectAppVersion } from './export.ts';
|
||||||
app
|
app
|
||||||
.route({
|
.route({
|
||||||
path: 'app',
|
path: 'app',
|
||||||
@@ -258,7 +259,7 @@ app
|
|||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const tokenUser = ctx.state.tokenUser;
|
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) {
|
if (!id && !appKey) {
|
||||||
throw new CustomError('id or appKey is required');
|
throw new CustomError('id or appKey is required');
|
||||||
}
|
}
|
||||||
@@ -268,22 +269,31 @@ app
|
|||||||
if (id) {
|
if (id) {
|
||||||
appList = await AppListModel.findByPk(id);
|
appList = await AppListModel.findByPk(id);
|
||||||
if (appList?.uid !== uid) {
|
if (appList?.uid !== uid) {
|
||||||
throw new CustomError('no permission');
|
ctx.throw('no permission');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!appList && appKey) {
|
if (!appList && appKey) {
|
||||||
if (!version) {
|
if (!version) {
|
||||||
throw new CustomError('version is required');
|
ctx.throw('version is required');
|
||||||
}
|
}
|
||||||
appList = await AppListModel.findOne({ where: { key: appKey, version, uid } });
|
appList = await AppListModel.findOne({ where: { key: appKey, version, uid } });
|
||||||
}
|
}
|
||||||
if (!appList) {
|
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 files = appList.data.files || [];
|
||||||
const am = await AppModel.findOne({ where: { key: appList.key, uid: uid } });
|
const am = await AppModel.findOne({ where: { key: appList.key, uid: uid } });
|
||||||
if (!am) {
|
if (!am) {
|
||||||
throw new CustomError('app not found');
|
ctx.throw('app 未发现');
|
||||||
}
|
}
|
||||||
await am.update({ data: { ...am.data, files }, version: appList.version });
|
await am.update({ data: { ...am.data, files }, version: appList.version });
|
||||||
setExpire(appList.key, am.user);
|
setExpire(appList.key, am.user);
|
||||||
@@ -385,7 +395,7 @@ app
|
|||||||
am = await AppModel.create({
|
am = await AppModel.create({
|
||||||
title: appKey,
|
title: appKey,
|
||||||
key: appKey,
|
key: appKey,
|
||||||
version: version || '0.0.0',
|
version: version || '0.0.1',
|
||||||
user: checkUsername,
|
user: checkUsername,
|
||||||
uid,
|
uid,
|
||||||
data: { files: needAddFiles },
|
data: { files: needAddFiles },
|
||||||
|
|||||||
Reference in New Issue
Block a user