diff --git a/docker-compose.yml b/docker-compose.yml index e6e0dbdab..4fc5dc811 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,7 +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/access:/var/lib/salix/access + - /mnt/appdata/vn-access:/var/lib/salix/vn-access deploy: replicas: ${BACK_REPLICAS:?} placement: diff --git a/loopback/server/datasources.json b/loopback/server/datasources.json index 7d2a6c117..86ec7d10f 100644 --- a/loopback/server/datasources.json +++ b/loopback/server/datasources.json @@ -103,7 +103,7 @@ "name": "accessStorage", "connector": "loopback-component-storage", "provider": "filesystem", - "root": "./storage/access/branches", + "root": "./storage/access", "maxFileSize": "2621440000", "allowedContentTypes": [ "application/x-7z-compressed" diff --git a/modules/mdb/back/methods/mdbVersion/upload.js b/modules/mdb/back/methods/mdbVersion/upload.js index 2109f2b4f..fa32fca97 100644 --- a/modules/mdb/back/methods/mdbVersion/upload.js +++ b/modules/mdb/back/methods/mdbVersion/upload.js @@ -52,6 +52,7 @@ module.exports = Self => { myOptions.transaction = tx; } + let srcFile; try { const tempContainer = await TempContainer.container('access'); const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions); @@ -61,23 +62,64 @@ module.exports = Self => { const uploadedFile = files[0]; const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name); - const 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`); + srcFile = path.join(file.client.root, file.container, file.name); - await fs.move(srcFile, destinationFile, { - overwrite: true - }); + const accessContainer = await AccessContainer.container('.archive'); + const destinationFile = path.join( + accessContainer.client.root, accessContainer.name, appName, `${newVersion}.7z`); - await models.MdbVersion.create({ - app: appName, - version: newVersion, - branchFk: branch + if (process.env.NODE_ENV == 'test') { + try { + await fs.unlink(srcFile); + } catch (e) {} + } else { + await fs.move(srcFile, destinationFile, { + overwrite: true + }); + await fs.chmod(destinationFile, 0o644); + + 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); + } + } + + 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); + if (tx) await tx.commit(); } catch (e) { if (tx) await tx.rollback(); + + if (await fs.stat(srcFile)) + await fs.unlink(srcFile); + throw e; } }; diff --git a/modules/mdb/back/models/mdbVersion.json b/modules/mdb/back/models/mdbVersion.json index 0fd86e4a5..02635ff8a 100644 --- a/modules/mdb/back/models/mdbVersion.json +++ b/modules/mdb/back/models/mdbVersion.json @@ -9,7 +9,8 @@ "properties": { "app": { "type": "string", - "description": "The app name" + "description": "The app name", + "id": true }, "version": { "type": "number"