fix: change version name
This commit is contained in:
parent
d97053a443
commit
4aaf791801
@ -147,7 +147,7 @@ router.post('/api/s1/resources/upload/chunk', async (req, res) => {
|
||||
// Notify the app
|
||||
const r = await app.call({
|
||||
path: 'app',
|
||||
key: 'detect-version-list',
|
||||
key: 'detectVersionList',
|
||||
payload: {
|
||||
token: token,
|
||||
data: {
|
||||
|
13
src/routes/app-manager/admin/mv-user-app.ts
Normal file
13
src/routes/app-manager/admin/mv-user-app.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { app } from '@/app.ts';
|
||||
import { AppModel, AppListModel } from '../module/index.ts';
|
||||
export const mvAppFromUserAToUserB = async (userA: string, userB: string) => {
|
||||
const appList = await AppModel.findAll({
|
||||
where: {
|
||||
user: userA,
|
||||
},
|
||||
});
|
||||
for (const app of appList) {
|
||||
app.user = userB;
|
||||
await app.save();
|
||||
}
|
||||
};
|
@ -2,7 +2,7 @@ import { app } from '@/app.ts';
|
||||
export const callDetectAppVersion = async ({ appKey, version, username }: { appKey: string; version: string; username: string }, token: string) => {
|
||||
const res = await app.call({
|
||||
path: 'app',
|
||||
key: 'detect-version-list',
|
||||
key: 'detectVersionList',
|
||||
payload: {
|
||||
token: token,
|
||||
data: { appKey, version, username },
|
||||
|
@ -299,7 +299,7 @@ app
|
||||
app
|
||||
.route({
|
||||
path: 'app',
|
||||
key: 'detect-version-list',
|
||||
key: 'detectVersionList',
|
||||
description: '检测版本列表,minio中的数据自己上传后,根据版本信息,进行替换',
|
||||
middleware: ['auth'],
|
||||
})
|
||||
@ -332,7 +332,7 @@ app
|
||||
let appListFiles = appList.data?.files || [];
|
||||
const needAddFiles = newFiles.map((item) => {
|
||||
const findFile = appListFiles.find((appListFile) => appListFile.name === item.name);
|
||||
if (findFile && findFile.path === item.path) {
|
||||
if (findFile && findFile.name === item.name) {
|
||||
return { ...findFile, ...item };
|
||||
}
|
||||
return item;
|
||||
|
@ -39,20 +39,21 @@ app
|
||||
if (!id && !key) {
|
||||
ctx.throw(500, 'id is required');
|
||||
}
|
||||
let am: AppModel;
|
||||
if (id) {
|
||||
const am = await AppModel.findByPk(id);
|
||||
am = await AppModel.findByPk(id);
|
||||
if (!am) {
|
||||
ctx.throw(500, 'app not found');
|
||||
}
|
||||
ctx.body = am;
|
||||
} else {
|
||||
const am = await AppModel.findOne({ where: { key, uid: tokenUser.id } });
|
||||
am = await AppModel.findOne({ where: { key, uid: tokenUser.id } });
|
||||
if (!am) {
|
||||
ctx.throw(500, 'app not found');
|
||||
}
|
||||
ctx.body = am;
|
||||
}
|
||||
|
||||
ctx.body = am;
|
||||
|
||||
return ctx;
|
||||
})
|
||||
.addTo(app);
|
||||
@ -66,11 +67,25 @@ app
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
|
||||
const { data, id, ...rest } = ctx.query.data;
|
||||
const { data, id, user, ...rest } = ctx.query.data;
|
||||
if (id) {
|
||||
const app = await AppModel.findByPk(id);
|
||||
if (app) {
|
||||
const newData = { ...app.data, ...data };
|
||||
if (app.user !== tokenUser.username) {
|
||||
rest.user = tokenUser.username;
|
||||
let files = newData?.files || [];
|
||||
if (files.length > 0) {
|
||||
files = files.map((item) => {
|
||||
const paths = item.path.split('/');
|
||||
return {
|
||||
...item,
|
||||
path: newData.user + '/' + paths.slice(1).join('/'),
|
||||
};
|
||||
});
|
||||
}
|
||||
newData.files = files;
|
||||
}
|
||||
const newApp = await app.update({ data: newData, ...rest });
|
||||
ctx.body = newApp;
|
||||
if (app.status !== 'running') {
|
||||
|
@ -3,13 +3,29 @@ import { App } from '@kevisual/router';
|
||||
type Opts = {
|
||||
prefix: string;
|
||||
};
|
||||
/**
|
||||
* fix path
|
||||
* @param data
|
||||
* @param prefix
|
||||
* @param opts
|
||||
* @returns
|
||||
*/
|
||||
export const prefixFix = (data: any, prefix: string, opts?: Opts) => {
|
||||
const len = prefix.length || 0;
|
||||
console.log('prefixFix', prefix, opts?.prefix);
|
||||
const wrapperPrefix = (path: string, prefix: string) => {
|
||||
if (prefix) {
|
||||
return prefix + '/' + path;
|
||||
}
|
||||
return path;
|
||||
};
|
||||
if (data.data.files) {
|
||||
data.data.files = data.data.files.map((item) => {
|
||||
const paths = item.path.split('/').filter((item) => item);
|
||||
return {
|
||||
...item,
|
||||
path: item.path.slice(len + 1),
|
||||
path: wrapperPrefix(paths.slice(1).join('/'), ''),
|
||||
origin: item.path,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ import { User } from '@/models/user.ts';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { CustomError } from '@kevisual/router';
|
||||
import { backupUserA, deleteUser, mvUserAToUserB } from '@/routes/file/index.ts';
|
||||
// import { mvAppFromUserAToUserB } from '@/routes/app-manager/admin/mv-user-app.ts';
|
||||
|
||||
export const checkUsername = (username: string) => {
|
||||
if (username.length > 30) {
|
||||
throw new CustomError(400, 'Username cannot be too long');
|
||||
@ -44,6 +46,7 @@ app
|
||||
// 迁移文件数据
|
||||
await backupUserA(oldName, user.id); // 备份文件数据
|
||||
await mvUserAToUserB(oldName, newName, true); // 迁移文件数据
|
||||
// await mvAppFromUserAToUserB(oldName, newName); // 迁移应用数据
|
||||
} catch (error) {
|
||||
console.error('迁移文件数据失败', error);
|
||||
ctx.throw(500, 'Failed to change username');
|
||||
|
Loading…
x
Reference in New Issue
Block a user