This commit is contained in:
2026-02-14 18:57:27 +08:00
parent 9961efd91a
commit 84e7a4158d

View File

@@ -208,7 +208,7 @@ app
try { try {
const _user = await User.getUserByToken(ctx.query.token); const _user = await User.getUserByToken(ctx.query.token);
if (_user.hasUser(username)) { if (_user.hasUser(username)) {
const upUser = await User.findOne({ where: { username } }); const upUser = await User.findOne({ username });
uid = upUser.id; uid = upUser.id;
userPrefix = username; userPrefix = username;
} }
@@ -318,6 +318,7 @@ app
if (!appList) { if (!appList) {
ctx.throw('app 未发现'); ctx.throw('app 未发现');
} }
let isDetect = false;
if (detect) { if (detect) {
const appKey = appList.key; const appKey = appList.key;
const version = appList.version; const version = appList.version;
@@ -328,11 +329,11 @@ app
} }
const appLists2 = await db.select().from(schema.kvAppList).where(eq(schema.kvAppList.id, appList.id)).limit(1); const appLists2 = await db.select().from(schema.kvAppList).where(eq(schema.kvAppList.id, appList.id)).limit(1);
appList = appLists2[0]; appList = appLists2[0];
isDetect = true;
} }
if (!appList) { if (!appList) {
ctx.throw('app 未发现'); ctx.throw('app 未发现');
} }
const appListData = appList.data as AppData; const appListData = appList.data as AppData;
const files = appListData.files || []; const files = appListData.files || [];
const ams = await db.select().from(schema.kvApp).where(and( const ams = await db.select().from(schema.kvApp).where(and(
@@ -343,10 +344,13 @@ app
if (!am) { if (!am) {
ctx.throw('app 未发现'); ctx.throw('app 未发现');
} }
if (!isDetect) {
const amData = am.data as AppData; const amData = am.data as AppData;
await db.update(schema.kvApp) await db.update(schema.kvApp)
.set({ data: { ...amData, files }, version: appList.version, updatedAt: new Date().toISOString() }) .set({ data: { ...amData, files }, version: appList.version, updatedAt: new Date().toISOString() })
.where(eq(schema.kvApp.id, am.id)); .where(eq(schema.kvApp.id, am.id));
}
setExpire(appList.key, am.user); setExpire(appList.key, am.user);
ctx.body = { ctx.body = {
key: appList.key, key: appList.key,
@@ -465,14 +469,13 @@ app
let am = ams[0]; let am = ams[0];
if (!am) { if (!am) {
const newAms = await db.insert(schema.kvApp).values({ const newAms = await db.insert(schema.kvApp).values({
id: randomUUID(),
title: appKey, title: appKey,
key: appKey, key: appKey,
version: version || '0.0.1', version: version || '0.0.1',
user: checkUsername, user: checkUsername,
uid, uid,
data: { files: needAddFiles }, data: { files: needAddFiles },
proxy: appKey.includes('center') ? false : true, proxy: true,
}).returning(); }).returning();
am = newAms[0]; am = newAms[0];
} else { } else {
@@ -483,8 +486,9 @@ app
)).limit(1); )).limit(1);
const appModel = appModels[0]; const appModel = appModels[0];
if (appModel) { if (appModel) {
const data = appModel.data as AppData;
await db.update(schema.kvApp) await db.update(schema.kvApp)
.set({ data: { files: needAddFiles }, updatedAt: new Date().toISOString() }) .set({ data: { ...data, files: needAddFiles }, updatedAt: new Date().toISOString() })
.where(eq(schema.kvApp.id, appModel.id)); .where(eq(schema.kvApp.id, appModel.id));
setExpire(appModel.key, appModel.user); setExpire(appModel.key, appModel.user);
} }