temp
This commit is contained in:
parent
b5fc5d279e
commit
1ae123e63a
@ -57,7 +57,7 @@
|
|||||||
"zod": "^3.24.2"
|
"zod": "^3.24.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@kevisual/code-center-module": "0.0.12",
|
"@kevisual/code-center-module": "0.0.13",
|
||||||
"@kevisual/types": "^0.0.6",
|
"@kevisual/types": "^0.0.6",
|
||||||
"@rollup/plugin-alias": "^5.1.1",
|
"@rollup/plugin-alias": "^5.1.1",
|
||||||
"@rollup/plugin-commonjs": "^28.0.2",
|
"@rollup/plugin-commonjs": "^28.0.2",
|
||||||
|
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@ -96,8 +96,8 @@ importers:
|
|||||||
version: 3.24.2
|
version: 3.24.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@kevisual/code-center-module':
|
'@kevisual/code-center-module':
|
||||||
specifier: 0.0.12
|
specifier: 0.0.13
|
||||||
version: 0.0.12(@kevisual/auth@1.0.5)(@kevisual/router@0.0.9)(@kevisual/use-config@1.0.9)(ioredis@5.6.0)(pg@8.13.3)(sequelize@6.37.6(pg@8.13.3))
|
version: 0.0.13(@kevisual/auth@1.0.5)(@kevisual/router@0.0.9)(@kevisual/use-config@1.0.9)(ioredis@5.6.0)(pg@8.13.3)(sequelize@6.37.6(pg@8.13.3))
|
||||||
'@kevisual/types':
|
'@kevisual/types':
|
||||||
specifier: ^0.0.6
|
specifier: ^0.0.6
|
||||||
version: 0.0.6
|
version: 0.0.6
|
||||||
@ -351,8 +351,8 @@ packages:
|
|||||||
'@kevisual/auth@1.0.5':
|
'@kevisual/auth@1.0.5':
|
||||||
resolution: {integrity: sha512-GwsLj7unKXi7lmMiIIgdig4LwwLiDJnOy15HHZR5gMbyK6s5/uJiMY5RXPB2+onGzTNDqFo/hXjsD2wkerHPVg==}
|
resolution: {integrity: sha512-GwsLj7unKXi7lmMiIIgdig4LwwLiDJnOy15HHZR5gMbyK6s5/uJiMY5RXPB2+onGzTNDqFo/hXjsD2wkerHPVg==}
|
||||||
|
|
||||||
'@kevisual/code-center-module@0.0.12':
|
'@kevisual/code-center-module@0.0.13':
|
||||||
resolution: {integrity: sha512-klQWlsifSeW7ej33B6/0ipB1UorEce5XHTvwNnX1QLGfUNCWm43j5xk+t71NuaVCmBO9OIRri88aU/GQc4G4fw==}
|
resolution: {integrity: sha512-A82sX8rdG2igyVLIF+0dagcUsGfk2b0JAga1BDDr9mrChrG1HbG1uYN7JJdjJbGE6zGYqGxRZwxKZmzB/+KMnw==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@kevisual/auth': ^1.0.5
|
'@kevisual/auth': ^1.0.5
|
||||||
'@kevisual/router': ^0.0.7
|
'@kevisual/router': ^0.0.7
|
||||||
@ -2568,7 +2568,7 @@ snapshots:
|
|||||||
|
|
||||||
'@kevisual/auth@1.0.5': {}
|
'@kevisual/auth@1.0.5': {}
|
||||||
|
|
||||||
'@kevisual/code-center-module@0.0.12(@kevisual/auth@1.0.5)(@kevisual/router@0.0.9)(@kevisual/use-config@1.0.9)(ioredis@5.6.0)(pg@8.13.3)(sequelize@6.37.6(pg@8.13.3))':
|
'@kevisual/code-center-module@0.0.13(@kevisual/auth@1.0.5)(@kevisual/router@0.0.9)(@kevisual/use-config@1.0.9)(ioredis@5.6.0)(pg@8.13.3)(sequelize@6.37.6(pg@8.13.3))':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@kevisual/auth': 1.0.5
|
'@kevisual/auth': 1.0.5
|
||||||
'@kevisual/router': 0.0.9
|
'@kevisual/router': 0.0.9
|
||||||
|
@ -287,8 +287,8 @@
|
|||||||
|
|
||||||
// useContextKey('UserModel', () => UserServices);
|
// useContextKey('UserModel', () => UserServices);
|
||||||
|
|
||||||
import { User, UserInit } from '@kevisual/code-center-module';
|
import { User, UserInit, UserServices } from '@kevisual/code-center-module/models';
|
||||||
export { User, UserInit };
|
export { User, UserInit, UserServices };
|
||||||
UserInit(null, null, {
|
UserInit(null, null, {
|
||||||
alter: true,
|
alter: true,
|
||||||
logging: true,
|
logging: true,
|
||||||
|
@ -138,8 +138,10 @@ router.post('/api/app/upload', async (req, res) => {
|
|||||||
fs.unlinkSync(file.filepath);
|
fs.unlinkSync(file.filepath);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
let appKey, version;
|
let appKey,
|
||||||
const { appKey: _appKey, version: _version } = fields;
|
version,
|
||||||
|
username = '';
|
||||||
|
const { appKey: _appKey, version: _version, username: _username } = fields;
|
||||||
if (Array.isArray(_appKey)) {
|
if (Array.isArray(_appKey)) {
|
||||||
appKey = _appKey?.[0];
|
appKey = _appKey?.[0];
|
||||||
} else {
|
} else {
|
||||||
@ -150,6 +152,20 @@ router.post('/api/app/upload', async (req, res) => {
|
|||||||
} else {
|
} else {
|
||||||
version = _version;
|
version = _version;
|
||||||
}
|
}
|
||||||
|
if (Array.isArray(_username)) {
|
||||||
|
username = _username?.[0];
|
||||||
|
} else if (_username) {
|
||||||
|
username = _username;
|
||||||
|
}
|
||||||
|
if (username) {
|
||||||
|
const user = await User.getUserByToken(token);
|
||||||
|
const has = user.hasUser(username);
|
||||||
|
if (!has) {
|
||||||
|
res.end(error('username is not found'));
|
||||||
|
clearFiles();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!appKey) {
|
if (!appKey) {
|
||||||
res.end(error('appKey is required'));
|
res.end(error('appKey is required'));
|
||||||
clearFiles();
|
clearFiles();
|
||||||
@ -171,7 +187,7 @@ router.post('/api/app/upload', async (req, res) => {
|
|||||||
const tempPath = file.filepath; // 文件上传时的临时路径
|
const tempPath = file.filepath; // 文件上传时的临时路径
|
||||||
const relativePath = file.originalFilename; // 保留表单中上传的文件名 (包含文件夹结构)
|
const relativePath = file.originalFilename; // 保留表单中上传的文件名 (包含文件夹结构)
|
||||||
// 比如 child2/b.txt
|
// 比如 child2/b.txt
|
||||||
const minioPath = `${tokenUser.username}/${appKey}/${version}/${relativePath}`;
|
const minioPath = `${username || tokenUser.username}/${appKey}/${version}/${relativePath}`;
|
||||||
// 上传到 MinIO 并保留文件夹结构
|
// 上传到 MinIO 并保留文件夹结构
|
||||||
const isHTML = relativePath.endsWith('.html');
|
const isHTML = relativePath.endsWith('.html');
|
||||||
await minioClient.fPutObject(bucketName, minioPath, tempPath, {
|
await minioClient.fPutObject(bucketName, minioPath, tempPath, {
|
||||||
@ -194,6 +210,7 @@ router.post('/api/app/upload', async (req, res) => {
|
|||||||
data: {
|
data: {
|
||||||
appKey,
|
appKey,
|
||||||
version,
|
version,
|
||||||
|
username,
|
||||||
files: uploadResults,
|
files: uploadResults,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -5,6 +5,7 @@ import _ from 'lodash';
|
|||||||
import { prefixFix } from './util.ts';
|
import { prefixFix } from './util.ts';
|
||||||
import { deleteFiles } from '../file/index.ts';
|
import { deleteFiles } from '../file/index.ts';
|
||||||
import { setExpire } from './revoke.ts';
|
import { setExpire } from './revoke.ts';
|
||||||
|
import { User } from '@/models/user.ts';
|
||||||
app
|
app
|
||||||
.route({
|
.route({
|
||||||
path: 'app',
|
path: 'app',
|
||||||
@ -143,19 +144,34 @@ app
|
|||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
try {
|
try {
|
||||||
const tokenUser = ctx.state.tokenUser;
|
const tokenUser = ctx.state.tokenUser;
|
||||||
const { appKey, files, version } = ctx.query.data;
|
const { appKey, files, version, username } = ctx.query.data;
|
||||||
if (!appKey) {
|
if (!appKey) {
|
||||||
throw new CustomError('appKey is required');
|
throw new CustomError('appKey is required');
|
||||||
}
|
}
|
||||||
if (!files || !files.length) {
|
if (!files || !files.length) {
|
||||||
throw new CustomError('files is required');
|
throw new CustomError('files is required');
|
||||||
}
|
}
|
||||||
let am = await AppModel.findOne({ where: { key: appKey, uid: tokenUser.id } });
|
let uid = tokenUser.id;
|
||||||
|
let userPrefix = tokenUser.username;
|
||||||
|
if (username) {
|
||||||
|
try {
|
||||||
|
const _user = await User.getUserByToken(ctx.query.token);
|
||||||
|
if (_user.hasUser(username)) {
|
||||||
|
const upUser = await User.findOne({ where: { username } });
|
||||||
|
uid = upUser.id;
|
||||||
|
userPrefix = username;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log('getUserByToken error', e);
|
||||||
|
throw new CustomError('user not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let am = await AppModel.findOne({ where: { key: appKey, uid } });
|
||||||
if (!am) {
|
if (!am) {
|
||||||
am = await AppModel.create({
|
am = await AppModel.create({
|
||||||
user: tokenUser.username,
|
user: userPrefix,
|
||||||
key: appKey,
|
key: appKey,
|
||||||
uid: tokenUser.id,
|
uid,
|
||||||
version: '0.0.0',
|
version: '0.0.0',
|
||||||
title: appKey,
|
title: appKey,
|
||||||
data: {
|
data: {
|
||||||
@ -163,13 +179,13 @@ app
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let app = await AppListModel.findOne({ where: { version: version, key: appKey, uid: tokenUser.id } });
|
let app = await AppListModel.findOne({ where: { version: version, key: appKey, uid: uid } });
|
||||||
if (!app) {
|
if (!app) {
|
||||||
// throw new CustomError('app not found');
|
// throw new CustomError('app not found');
|
||||||
app = await AppListModel.create({
|
app = await AppListModel.create({
|
||||||
key: appKey,
|
key: appKey,
|
||||||
version,
|
version,
|
||||||
uid: tokenUser.id,
|
uid: uid,
|
||||||
data: {
|
data: {
|
||||||
files: [],
|
files: [],
|
||||||
},
|
},
|
||||||
@ -178,8 +194,8 @@ app
|
|||||||
const dataFiles = app.data.files || [];
|
const dataFiles = app.data.files || [];
|
||||||
const newFiles = _.uniqBy([...dataFiles, ...files], 'name');
|
const newFiles = _.uniqBy([...dataFiles, ...files], 'name');
|
||||||
const res = await app.update({ data: { ...app.data, files: newFiles } });
|
const res = await app.update({ data: { ...app.data, files: newFiles } });
|
||||||
setExpire(app.id, 'test');
|
setExpire(app.id, userPrefix);
|
||||||
ctx.body = prefixFix(res, tokenUser.username);
|
ctx.body = prefixFix(res, userPrefix);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('update error', e);
|
console.log('update error', e);
|
||||||
throw new CustomError(e.message);
|
throw new CustomError(e.message);
|
||||||
@ -214,7 +230,7 @@ app
|
|||||||
key: app.key,
|
key: app.key,
|
||||||
version: app.version,
|
version: app.version,
|
||||||
appManager: am,
|
appManager: am,
|
||||||
user: am.user
|
user: am.user,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.addTo(app);
|
.addTo(app);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { User } from '@/models/user.ts';
|
import { UserServices } from '@/models/user.ts';
|
||||||
|
|
||||||
import { app } from '@/app.ts';
|
import { app } from '@/app.ts';
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ app
|
|||||||
if (!password) {
|
if (!password) {
|
||||||
ctx.throw(500, 'root password are required');
|
ctx.throw(500, 'root password are required');
|
||||||
}
|
}
|
||||||
const res = await User.initializeUser(password);
|
const res = await UserServices.initializeUser(password);
|
||||||
ctx.body = res;
|
ctx.body = res;
|
||||||
})
|
})
|
||||||
.addTo(app);
|
.addTo(app);
|
||||||
@ -28,7 +28,7 @@ app
|
|||||||
if (!username && username.startsWith('demo')) {
|
if (!username && username.startsWith('demo')) {
|
||||||
ctx.throw(500, 'username are required, and must start with demo');
|
ctx.throw(500, 'username are required, and must start with demo');
|
||||||
}
|
}
|
||||||
const res = await User.createDemoUser(username, password);
|
const res = await UserServices.createDemoUser(username, password);
|
||||||
ctx.body = res;
|
ctx.body = res;
|
||||||
})
|
})
|
||||||
.addTo(app);
|
.addTo(app);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user