temp
This commit is contained in:
@@ -138,8 +138,10 @@ router.post('/api/app/upload', async (req, res) => {
|
||||
fs.unlinkSync(file.filepath);
|
||||
});
|
||||
};
|
||||
let appKey, version;
|
||||
const { appKey: _appKey, version: _version } = fields;
|
||||
let appKey,
|
||||
version,
|
||||
username = '';
|
||||
const { appKey: _appKey, version: _version, username: _username } = fields;
|
||||
if (Array.isArray(_appKey)) {
|
||||
appKey = _appKey?.[0];
|
||||
} else {
|
||||
@@ -150,6 +152,20 @@ router.post('/api/app/upload', async (req, res) => {
|
||||
} else {
|
||||
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) {
|
||||
res.end(error('appKey is required'));
|
||||
clearFiles();
|
||||
@@ -171,7 +187,7 @@ router.post('/api/app/upload', async (req, res) => {
|
||||
const tempPath = file.filepath; // 文件上传时的临时路径
|
||||
const relativePath = file.originalFilename; // 保留表单中上传的文件名 (包含文件夹结构)
|
||||
// 比如 child2/b.txt
|
||||
const minioPath = `${tokenUser.username}/${appKey}/${version}/${relativePath}`;
|
||||
const minioPath = `${username || tokenUser.username}/${appKey}/${version}/${relativePath}`;
|
||||
// 上传到 MinIO 并保留文件夹结构
|
||||
const isHTML = relativePath.endsWith('.html');
|
||||
await minioClient.fPutObject(bucketName, minioPath, tempPath, {
|
||||
@@ -194,6 +210,7 @@ router.post('/api/app/upload', async (req, res) => {
|
||||
data: {
|
||||
appKey,
|
||||
version,
|
||||
username,
|
||||
files: uploadResults,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user