4108-mdb_backend #987
|
@ -32,7 +32,7 @@ services:
|
||||||
- /mnt/appdata/pdfs:/var/lib/salix/pdfs
|
- /mnt/appdata/pdfs:/var/lib/salix/pdfs
|
||||||
- /mnt/appdata/dms:/var/lib/salix/dms
|
- /mnt/appdata/dms:/var/lib/salix/dms
|
||||||
- /mnt/appdata/image:/var/lib/salix/image
|
- /mnt/appdata/image:/var/lib/salix/image
|
||||||
- /mnt/appdata/access:/var/lib/salix/access
|
- /mnt/appdata/vn-access:/var/lib/salix/vn-access
|
||||||
deploy:
|
deploy:
|
||||||
replicas: ${BACK_REPLICAS:?}
|
replicas: ${BACK_REPLICAS:?}
|
||||||
placement:
|
placement:
|
||||||
|
|
|
@ -103,7 +103,7 @@
|
||||||
"name": "accessStorage",
|
"name": "accessStorage",
|
||||||
"connector": "loopback-component-storage",
|
"connector": "loopback-component-storage",
|
||||||
"provider": "filesystem",
|
"provider": "filesystem",
|
||||||
"root": "./storage/access/branches",
|
"root": "./storage/access",
|
||||||
"maxFileSize": "2621440000",
|
"maxFileSize": "2621440000",
|
||||||
alexm marked this conversation as resolved
Outdated
|
|||||||
"allowedContentTypes": [
|
"allowedContentTypes": [
|
||||||
"application/x-7z-compressed"
|
"application/x-7z-compressed"
|
||||||
|
|
|
@ -52,6 +52,7 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let srcFile;
|
||||||
try {
|
try {
|
||||||
const tempContainer = await TempContainer.container('access');
|
const tempContainer = await TempContainer.container('access');
|
||||||
const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions);
|
const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions);
|
||||||
|
@ -61,23 +62,64 @@ module.exports = Self => {
|
||||||
const uploadedFile = files[0];
|
const uploadedFile = files[0];
|
||||||
|
|
||||||
const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name);
|
const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name);
|
||||||
const srcFile = path.join(file.client.root, file.container, file.name);
|
srcFile = path.join(file.client.root, file.container, file.name);
|
||||||
const accessContainer = await AccessContainer.container(branch);
|
|
||||||
const destinationFile = path.join(accessContainer.client.root, branch, `${appName}${newVersion}.7z`);
|
|
||||||
|
|
||||||
|
const accessContainer = await AccessContainer.container('.archive');
|
||||||
|
const destinationFile = path.join(
|
||||||
juan marked this conversation as resolved
Outdated
juan
commented
Cuando Cuando `NODE_ENV` es `test` no hay que guardar el fichero, si no sobreescribira el de producción. Añadir un if para evitar el guardado en ese caso.
|
|||||||
|
accessContainer.client.root, accessContainer.name, appName, `${newVersion}.7z`);
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV == 'test') {
|
||||||
|
try {
|
||||||
alexm marked this conversation as resolved
Outdated
juan
commented
Lleva el try/catch, si intenta borrar el fitxer i no pot, ha de tornar el error. Lleva el try/catch, si intenta borrar el fitxer i no pot, ha de tornar el error.
|
|||||||
|
await fs.unlink(srcFile);
|
||||||
|
} catch (e) {}
|
||||||
|
} else {
|
||||||
await fs.move(srcFile, destinationFile, {
|
await fs.move(srcFile, destinationFile, {
|
||||||
overwrite: true
|
overwrite: true
|
||||||
});
|
});
|
||||||
|
await fs.chmod(destinationFile, 0o644);
|
||||||
|
|
||||||
await models.MdbVersion.create({
|
const branchPath = path.join(accessContainer.client.root, 'branches', branch);
|
||||||
alexm marked this conversation as resolved
Outdated
juan
commented
Abans de crear el directori, comprovar que la rama existeix en la taula mdbBranch, en cas contrari llançar un error notificant que la rama no existeix Abans de crear el directori, comprovar que la rama existeix en la taula mdbBranch, en cas contrari llançar un error notificant que la rama no existeix
|
|||||||
|
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);
|
||||||
alexm marked this conversation as resolved
juan
commented
Es necesari borrarlo primer? fs.symlink no el reescriu si existeix? Es necesari borrarlo primer? fs.symlink no el reescriu si existeix?
|
|||||||
|
} catch (e) {}
|
||||||
|
await fs.symlink(destinationFile, destinationBranch);
|
||||||
|
|
||||||
|
if (branch == 'master') {
|
||||||
|
try {
|
||||||
|
await fs.unlink(destinationRoot);
|
||||||
alexm marked this conversation as resolved
juan
commented
Es necesari borrarlo primer? fs.symlink no el reescriu si existeix? Es necesari borrarlo primer? fs.symlink no el reescriu si existeix?
|
|||||||
|
} catch (e) {}
|
||||||
|
await fs.symlink(destinationFile, destinationRoot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const version = await models.MdbVersion.findOne({
|
||||||
|
where: {
|
||||||
app: appName,
|
app: appName,
|
||||||
version: newVersion,
|
|
||||||
branchFk: branch
|
branchFk: branch
|
||||||
|
}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
if (!version) {
|
||||||
alexm marked this conversation as resolved
Outdated
juan
commented
Pots gastar upsert, aixina en menys codi insertes (si no existeix) o actualitzes. https://loopback.io/doc/en/lb3/Creating-updating-and-deleting-data.html Pots gastar upsert, aixina en menys codi insertes (si no existeix) o actualitzes.
https://loopback.io/doc/en/lb3/Creating-updating-and-deleting-data.html
|
|||||||
|
return await models.MdbVersion.create({
|
||||||
|
app: appName,
|
||||||
|
branchFk: branch,
|
||||||
|
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))
|
||||||
|
await fs.unlink(srcFile);
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"app": {
|
"app": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The app name"
|
"description": "The app name",
|
||||||
|
"id": true
|
||||||
},
|
},
|
||||||
"version": {
|
"version": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
|
|
Loading…
Reference in New Issue
Fica màxim 500MB, crec que el valor està en bytes, comprova-ho en la documentació de looback storage.