diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index ca8791c21..c91ba71c2 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -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'); \ No newline at end of file + ('lab', 'master', '1'); \ No newline at end of file diff --git a/loopback/server/datasources.json b/loopback/server/datasources.json index 86ec7d10f..5dade9c2e 100644 --- a/loopback/server/datasources.json +++ b/loopback/server/datasources.json @@ -104,7 +104,7 @@ "connector": "loopback-component-storage", "provider": "filesystem", "root": "./storage/access", - "maxFileSize": "2621440000", + "maxFileSize": "524288000", "allowedContentTypes": [ "application/x-7z-compressed" ] diff --git a/modules/mdb/back/methods/mdbVersion/upload.js b/modules/mdb/back/methods/mdbVersion/upload.js index fa32fca97..3d54c0250 100644 --- a/modules/mdb/back/methods/mdbVersion/upload.js +++ b/modules/mdb/back/methods/mdbVersion/upload.js @@ -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;