Merge pull request '4108-mdb_backend' (#987) from 4108-mdb_backend into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #987 Reviewed-by: Juan Ferrer <juan@verdnatura.es>
This commit is contained in:
commit
ddca6713c9
|
@ -5,17 +5,17 @@ module.exports = Self => {
|
|||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'Number',
|
||||
type: 'number',
|
||||
description: 'The user id',
|
||||
http: {source: 'path'}
|
||||
}, {
|
||||
arg: 'oldPassword',
|
||||
type: 'String',
|
||||
type: 'string',
|
||||
description: 'The old password',
|
||||
required: true
|
||||
}, {
|
||||
arg: 'newPassword',
|
||||
type: 'String',
|
||||
type: 'string',
|
||||
description: 'The new password',
|
||||
required: true
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
CREATE TABLE `vn`.`mdbBranch` (
|
||||
`name` VARCHAR(255),
|
||||
PRIMARY KEY(`name`)
|
||||
);
|
||||
|
||||
CREATE TABLE `vn`.`mdbVersion` (
|
||||
`app` VARCHAR(255) NOT NULL,
|
||||
`branchFk` VARCHAR(255) NOT NULL,
|
||||
`version` INT,
|
||||
CONSTRAINT `mdbVersion_branchFk` FOREIGN KEY (`branchFk`) REFERENCES `vn`.`mdbBranch` (`name`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES('MdbVersion', '*', '*', 'ALLOW', 'ROLE', 'developer');
|
|
@ -2577,3 +2577,12 @@ INSERT INTO `vn`.`machineWorker` (`workerFk`, `machineFk`, `inTimed`, `outTimed`
|
|||
(1106, 2, CURDATE(), NULL),
|
||||
(1106, 2, DATE_ADD(CURDATE(), INTERVAL + 1 DAY), DATE_ADD(CURDATE(), INTERVAL +1 DAY));
|
||||
|
||||
INSERT INTO `vn`.`mdbBranch` (`name`)
|
||||
VALUES
|
||||
('test'),
|
||||
('master');
|
||||
|
||||
INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`)
|
||||
VALUES
|
||||
('tpv', 'test', '1'),
|
||||
('lab', 'master', '1');
|
|
@ -32,6 +32,7 @@ services:
|
|||
- /mnt/appdata/pdfs:/var/lib/salix/pdfs
|
||||
- /mnt/appdata/dms:/var/lib/salix/dms
|
||||
- /mnt/appdata/image:/var/lib/salix/image
|
||||
- /mnt/appdata/vn-access:/var/lib/salix/vn-access
|
||||
deploy:
|
||||
replicas: ${BACK_REPLICAS:?}
|
||||
placement:
|
||||
|
|
|
@ -98,5 +98,15 @@
|
|||
"image/jpg",
|
||||
"video/mp4"
|
||||
]
|
||||
},
|
||||
"accessStorage": {
|
||||
"name": "accessStorage",
|
||||
"connector": "loopback-component-storage",
|
||||
"provider": "filesystem",
|
||||
"root": "./storage/access",
|
||||
"maxFileSize": "524288000",
|
||||
"allowedContentTypes": [
|
||||
"application/x-7z-compressed"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('upload', {
|
||||
description: 'Upload and attach a access file',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'appName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The app name'
|
||||
},
|
||||
{
|
||||
arg: 'newVersion',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: `The new version number`
|
||||
},
|
||||
{
|
||||
arg: 'branch',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: `The branch name`
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/upload`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.upload = async(ctx, appName, newVersion, branch, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
||||
const TempContainer = models.TempContainer;
|
||||
const AccessContainer = models.AccessContainer;
|
||||
const fileOptions = {};
|
||||
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
let srcFile;
|
||||
try {
|
||||
const tempContainer = await TempContainer.container('access');
|
||||
const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions);
|
||||
const files = Object.values(uploaded.files).map(file => {
|
||||
return file[0];
|
||||
});
|
||||
const uploadedFile = files[0];
|
||||
|
||||
const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name);
|
||||
srcFile = path.join(file.client.root, file.container, file.name);
|
||||
|
||||
const accessContainer = await AccessContainer.container('.archive');
|
||||
const destinationFile = path.join(
|
||||
accessContainer.client.root, accessContainer.name, appName, `${newVersion}.7z`);
|
||||
|
||||
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});
|
||||
|
||||
const destinationBranch = path.join(branchPath, `${appName}.7z`);
|
||||
const destinationRoot = path.join(accessContainer.client.root, `${appName}.7z`);
|
||||
try {
|
||||
await fs.unlink(destinationBranch);
|
||||
} catch (e) {}
|
||||
await fs.symlink(destinationFile, destinationBranch);
|
||||
|
||||
if (branch == 'master') {
|
||||
try {
|
||||
await fs.unlink(destinationRoot);
|
||||
} catch (e) {}
|
||||
await fs.symlink(destinationFile, destinationRoot);
|
||||
}
|
||||
}
|
||||
|
||||
await models.MdbVersion.upsert({
|
||||
app: appName,
|
||||
branchFk: branch,
|
||||
version: newVersion
|
||||
});
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
|
||||
if (fs.existsSync(srcFile))
|
||||
await fs.unlink(srcFile);
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"MdbBranch": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"MdbVersion": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"AccessContainer": {
|
||||
"dataSource": "accessStorage"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "AccessContainer",
|
||||
"base": "Container",
|
||||
"acls": [{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "developer",
|
||||
"permission": "ALLOW"
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "MdbBranch",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "mdbBranch"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"name": {
|
||||
"id": true,
|
||||
"type": "string",
|
||||
"description": "Identifier"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/mdbVersion/upload')(Self);
|
||||
};
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "MdbVersion",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "mdbVersion"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"app": {
|
||||
"type": "string",
|
||||
"description": "The app name",
|
||||
"id": true
|
||||
},
|
||||
"version": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"branch": {
|
||||
"type": "belongsTo",
|
||||
"model": "MdbBranch",
|
||||
"foreignKey": "branchFk"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Forces tmp folder creation!
|
Loading…
Reference in New Issue