feat: 上传资源和下载资源更新

This commit is contained in:
2025-03-20 02:29:26 +08:00
parent 9b1045d456
commit 0179fe73a3
19 changed files with 747 additions and 225 deletions

View File

@@ -309,20 +309,27 @@ app
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
let { key, version, username } = ctx.query?.data || {};
if (!key || !version) {
throw new CustomError('key and version are required');
let { appKey, version, username } = ctx.query?.data || {};
if (!appKey || !version) {
throw new CustomError('appKey and version are required');
}
const uid = await getUidByUsername(app, ctx, username);
const appList = await AppListModel.findOne({ where: { key, version, uid: uid } });
let appList = await AppListModel.findOne({ where: { key: appKey, version, uid } });
if (!appList) {
throw new CustomError('app not found');
appList = await AppListModel.create({
key: appKey,
version,
uid,
data: {
files: [],
},
});
}
const checkUsername = username || tokenUser.username;
const files = await getMinioListAndSetToAppList({ username: checkUsername, appKey: key, version });
const files = await getMinioListAndSetToAppList({ username: checkUsername, appKey, version });
const newFiles = files.map((item) => {
return {
name: item.name.replace(`${checkUsername}/${key}/${version}/`, ''),
name: item.name.replace(`${checkUsername}/${appKey}/${version}/`, ''),
path: item.name,
};
});
@@ -330,17 +337,31 @@ app
const needAddFiles = newFiles.map((item) => {
const findFile = appListFiles.find((appListFile) => appListFile.name === item.name);
if (findFile && findFile.path === item.path) {
return findFile;
return { ...findFile, ...item };
}
return item;
});
await appList.update({ data: { files: needAddFiles } });
setExpire(appList.id, 'test');
const appModel = await AppModel.findOne({ where: { key, version, uid: uid } });
if (appModel) {
await appModel.update({ data: { files: needAddFiles } });
setExpire(appModel.key, appModel.user);
let am = await AppModel.findOne({ where: { key: appKey, uid } });
if (!am) {
am = await AppModel.create({
title: appKey,
key: appKey,
version: version || '0.0.0',
user: checkUsername,
uid,
data: { files: needAddFiles },
proxy: true,
});
} else {
const appModel = await AppModel.findOne({ where: { key: appKey, version, uid } });
if (appModel) {
await appModel.update({ data: { files: needAddFiles } });
setExpire(appModel.key, appModel.user);
}
}
ctx.body = appList;
})
.addTo(app);