4108-mdb_backend #987

Merged
juan merged 9 commits from 4108-mdb_backend into dev 2022-06-02 07:33:24 +00:00
3 changed files with 19 additions and 30 deletions
Showing only changes of commit 8340041b33 - Show all commits

View File

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

View File

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

View File

@ -1,5 +1,6 @@
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('upload', { Self.remoteMethodCtx('upload', {
@ -68,16 +69,21 @@ module.exports = Self => {
const destinationFile = path.join( const destinationFile = path.join(
accessContainer.client.root, accessContainer.name, appName, `${newVersion}.7z`); accessContainer.client.root, accessContainer.name, appName, `${newVersion}.7z`);
if (process.env.NODE_ENV == 'test') { if (process.env.NODE_ENV == 'test')
try {
await fs.unlink(srcFile); await fs.unlink(srcFile);
} catch (e) {} else {
} else {
await fs.move(srcFile, destinationFile, { await fs.move(srcFile, destinationFile, {
overwrite: true overwrite: true
}); });
await fs.chmod(destinationFile, 0o644); 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); const branchPath = path.join(accessContainer.client.root, 'branches', branch);
alexm marked this conversation as resolved
Review

Es necesari borrarlo primer? fs.symlink no el reescriu si existeix?

Es necesari borrarlo primer? fs.symlink no el reescriu si existeix?
await fs.mkdir(branchPath, {recursive: true}); await fs.mkdir(branchPath, {recursive: true});
@ -96,28 +102,17 @@ module.exports = Self => {
} }
} }
const version = await models.MdbVersion.findOne({ await models.MdbVersion.upsert({
where: {
app: appName,
branchFk: branch
}
}, myOptions);
if (!version) {
return await models.MdbVersion.create({
app: appName, app: appName,
branchFk: branch, branchFk: branch,
version: newVersion version: newVersion
}); });
}
await version.updateAttributes({version: newVersion}, myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
if (await fs.stat(srcFile)) if (fs.existsSync(srcFile))
await fs.unlink(srcFile); await fs.unlink(srcFile);
throw e; throw e;