throw userError and maxFileSize
gitea/salix/pipeline/head This commit is unstable Details

This commit is contained in:
Alex Moreno 2022-06-01 07:57:32 +02:00
parent cac4e74793
commit 8340041b33
3 changed files with 19 additions and 30 deletions

View File

@ -2585,10 +2585,4 @@ INSERT INTO `vn`.`mdbBranch` (`name`)
INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`)
VALUES
('tpv', 'test', '1'),
('lab', 'master', '1'),
('enc', 'test', '1'),
('ent', 'master', '1'),
('com', 'test', '1'),
('eti', 'master', '1'),
('ser', 'test', '1'),
('lib', 'master', '1');
('lab', 'master', '1');

View File

@ -104,7 +104,7 @@
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./storage/access",
"maxFileSize": "2621440000",
"maxFileSize": "524288000",
"allowedContentTypes": [
"application/x-7z-compressed"
]

View File

@ -1,5 +1,6 @@
const fs = require('fs-extra');
const path = require('path');
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('upload', {
@ -68,16 +69,21 @@ module.exports = Self => {
const destinationFile = path.join(
accessContainer.client.root, accessContainer.name, appName, `${newVersion}.7z`);
if (process.env.NODE_ENV == 'test') {
try {
await fs.unlink(srcFile);
} catch (e) {}
} else {
if (process.env.NODE_ENV == 'test')
await fs.unlink(srcFile);
else {
await fs.move(srcFile, destinationFile, {
overwrite: true
});
await fs.chmod(destinationFile, 0o644);
const existBranch = await models.MdbBranch.findOne({
where: {name: branch}
});
if (!existBranch)
throw new UserError('Not exist this branch');
const branchPath = path.join(accessContainer.client.root, 'branches', branch);
await fs.mkdir(branchPath, {recursive: true});
@ -96,28 +102,17 @@ module.exports = Self => {
}
}
const version = await models.MdbVersion.findOne({
where: {
app: appName,
branchFk: branch
}
}, myOptions);
if (!version) {
return await models.MdbVersion.create({
app: appName,
branchFk: branch,
version: newVersion
});
}
await version.updateAttributes({version: newVersion}, myOptions);
await models.MdbVersion.upsert({
app: appName,
branchFk: branch,
version: newVersion
});
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
if (await fs.stat(srcFile))
if (fs.existsSync(srcFile))
await fs.unlink(srcFile);
throw e;