From cb742807b40c70502ee78a78103d0a31ce00bdd7 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Fri, 6 Feb 2026 02:46:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=BA=94=E7=94=A8=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=8F=98=E9=87=8F=E5=91=BD=E5=90=8D=E5=B9=B6=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E5=86=97=E4=BD=99=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/app-manager/list.ts | 61 +++++++++++++++++----------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/src/routes/app-manager/list.ts b/src/routes/app-manager/list.ts index 4338d29..7ce46ff 100644 --- a/src/routes/app-manager/list.ts +++ b/src/routes/app-manager/list.ts @@ -48,11 +48,11 @@ app if (!id && (!key || !version)) { throw new CustomError('id is required'); } - let am: AppListModel; + let appListModel: AppListModel; if (id) { - am = await AppListModel.findByPk(id); + appListModel = await AppListModel.findByPk(id); } else if (key && version) { - am = await AppListModel.findOne({ + appListModel = await AppListModel.findOne({ where: { key, version, @@ -60,18 +60,35 @@ app }, }); } - if (!am && create) { - am = await AppListModel.create({ + if (!appListModel && create) { + appListModel = await AppListModel.create({ key, version, uid: tokenUser.id, data: {}, }); - const res = await app.run({ path: 'app', key: "detectVersionList", payload: { data: { appKey: key, version, username: tokenUser.username }, token: ctx.query.token } }); + const appModel = await AppModel.findOne({ + where: { + key, + uid: tokenUser.id, + }, + }); + if (!appModel) { + await AppModel.create({ + key, + uid: tokenUser.id, + user: tokenUser.username, + version, + title: key, + description: '', + data: {}, + }); + } + const res = await callDetectAppVersion({ appKey: key, version, username: tokenUser.username }, ctx.query.token); if (res.code !== 200) { ctx.throw(res.message || 'detect version list error'); } - am = await AppListModel.findOne({ + appListModel = await AppListModel.findOne({ where: { key, version, @@ -79,11 +96,11 @@ app }, }); } - if (!am) { + if (!appListModel) { ctx.throw('app not found'); } - console.log('get app', am.id, am.key, am.version); - ctx.body = prefixFix(am, tokenUser.username); + console.log('get app', appListModel.id, appListModel.key, appListModel.version); + ctx.body = prefixFix(appListModel, tokenUser.username); }) .addTo(app); @@ -154,26 +171,7 @@ app return ctx; }) .addTo(app); -app - .route({ - path: 'app', - key: 'canUploadFiles', - middleware: ['auth'], - description: '检查是否可以上传文件,如果当前版本已存在,则不允许上传', - }) - .define(async (ctx) => { - const tokenUser = ctx.state.tokenUser; - const { appKey, version } = ctx.query.data; - if (!appKey) { - throw new CustomError('appKey is required'); - } - const app = await AppListModel.findOne({ where: { version: version, key: appKey, uid: tokenUser.id } }); - if (!app) { - throw new CustomError('app not found'); - } - ctx.body = app; - }) - .addTo(app); + app .route({ path: 'app', @@ -291,6 +289,9 @@ app } appList = await AppListModel.findByPk(appList.id); } + if (!appList) { + ctx.throw('app 未发现'); + } const files = appList.data.files || []; const am = await AppModel.findOne({ where: { key: appList.key, uid: uid } });