From faee28cb01a44bff2b5d4feaaf956addbb183bea Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Mon, 29 Jun 2020 09:35:18 +0200 Subject: [PATCH 01/20] fix bugs in ticket weekly --- modules/ticket/back/methods/ticket-weekly/filter.js | 2 +- modules/ticket/front/weekly/index.html | 8 ++++---- modules/ticket/front/weekly/locale/es.yml | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/ticket/back/methods/ticket-weekly/filter.js b/modules/ticket/back/methods/ticket-weekly/filter.js index 77f8ecc57..ef00aff9b 100644 --- a/modules/ticket/back/methods/ticket-weekly/filter.js +++ b/modules/ticket/back/methods/ticket-weekly/filter.js @@ -51,7 +51,7 @@ module.exports = Self => { stmt = new ParameterizedSQL( `SELECT t.id AS ticketFk, c.id AS clientFk, c.name AS clientName, tw.weekDay, - wh.name AS warehouseName, u.id AS workerFk, u.nickName, tw.agencyModeFk + wh.name AS warehouseName, u.id AS workerFk, u.name AS userName, u.nickName, tw.agencyModeFk FROM ticketWeekly tw JOIN ticket t ON t.id = tw.ticketFk JOIN client c ON c.id = t.clientFk diff --git a/modules/ticket/front/weekly/index.html b/modules/ticket/front/weekly/index.html index 92ee64478..b51a7a887 100644 --- a/modules/ticket/front/weekly/index.html +++ b/modules/ticket/front/weekly/index.html @@ -18,13 +18,13 @@ + class="vn-w-xl"> Ticket ID - Client + Client Weekday Agency Warehouse @@ -53,7 +53,7 @@ - - {{::weekly.nickName}} + {{::weekly.userName}} diff --git a/modules/ticket/front/weekly/locale/es.yml b/modules/ticket/front/weekly/locale/es.yml index 7c7c6a139..804467dae 100644 --- a/modules/ticket/front/weekly/locale/es.yml +++ b/modules/ticket/front/weekly/locale/es.yml @@ -3,4 +3,5 @@ Weekly tickets: Tickets programados You are going to delete this weekly ticket: Vas a eliminar este ticket programado This ticket will be removed from weekly tickets! Continue anyway?: Este ticket se eliminará de tickets programados! ¿Continuar de todas formas? Search weekly ticket by id or client id: Busca tickets programados por el identificador o el identificador del cliente -Search by weekly ticket: Buscar por tickets programados \ No newline at end of file +Search by weekly ticket: Buscar por tickets programados +weekDay: Dia \ No newline at end of file From 6fe50dc040adf5492d529759adaf0527ad6747ba Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 2 Jul 2020 16:07:26 +0200 Subject: [PATCH 02/20] Switch to puppeteer --- print/common/css/layout.css | 18 +++++++--- print/common/css/report.css | 6 ++-- print/config/print.json | 12 ++++--- .../report-footer/assets/css/style.css | 20 ++++++++--- .../components/report-footer/locale/en.yml | 2 +- .../components/report-footer/locale/es.yml | 2 +- .../components/report-footer/locale/fr.yml | 2 +- .../components/report-footer/locale/pt.yml | 2 +- .../report-footer/report-footer.html | 20 ++++++----- .../report-header/assets/css/style.css | 2 +- print/core/report.js | 33 ++++++++++++++++--- print/methods/report.js | 3 +- .../campaign-metrics/campaign-metrics.html | 20 ++++------- .../claim-pickup-order.html | 20 ++++------- .../reports/delivery-note/delivery-note.html | 28 ++++++---------- .../reports/driver-route/driver-route.html | 18 +++------- .../reports/entry-order/entry-order.html | 26 +++++---------- .../templates/reports/item-label/options.json | 11 ++++--- .../reports/letter-debtor/letter-debtor.html | 29 +++++++--------- print/templates/reports/receipt/receipt.html | 20 ++++------- .../reports/sepa-core/sepa-core.html | 20 ++++------- 21 files changed, 153 insertions(+), 161 deletions(-) diff --git a/print/common/css/layout.css b/print/common/css/layout.css index b85589a81..3768fb8ea 100644 --- a/print/common/css/layout.css +++ b/print/common/css/layout.css @@ -157,22 +157,32 @@ table { border-spacing: 0; } +thead { + display: table-header-group +} + /** * Prevent page break fix */ tbody { page-break-inside: avoid; break-inside: avoid; - display: block; - width: 100% + display: block } -thead, tbody tr { +tbody tr { table-layout: fixed; - display: table; + display: table +} + +thead, tbody, tbody tr { width: 100%; } +tfoot { + display: block +} + .row-oriented, .column-oriented { text-align: left; width: 100% diff --git a/print/common/css/report.css b/print/common/css/report.css index 5b8a1539b..796b99c4f 100644 --- a/print/common/css/report.css +++ b/print/common/css/report.css @@ -3,12 +3,12 @@ * */ body { - zoom: 0.53 + zoom: 0.70; } .title { margin-bottom: 20px; font-weight: 100; - margin-top: 0; - font-size: 2em + font-size: 2em; + margin-top: 0 } \ No newline at end of file diff --git a/print/config/print.json b/print/config/print.json index e1a93e152..5f4c0f7b8 100755 --- a/print/config/print.json +++ b/print/config/print.json @@ -13,10 +13,14 @@ }, "pdf": { "format": "A4", - "border": "1.5cm", - "footer": { - "height": "55px" - } + "margin": { + "top": "1.5cm", + "right": "1.5cm", + "bottom": "3cm", + "left": "1.5cm" + }, + "displayHeaderFooter": true, + "printBackground": true }, "mysql": { "host": "localhost", diff --git a/print/core/components/report-footer/assets/css/style.css b/print/core/components/report-footer/assets/css/style.css index e7ee162a8..e06e8c0ad 100644 --- a/print/core/components/report-footer/assets/css/style.css +++ b/print/core/components/report-footer/assets/css/style.css @@ -1,11 +1,13 @@ -footer { +.footer { font-family: "Roboto", "Helvetica", "Arial", sans-serif; - font-size: 0.55em; + margin-left: 2cm; + margin-right: 2cm; + font-size: 10px; color: #555; zoom: 0.65 } -footer, footer p { +.footer p { text-align: center } @@ -13,12 +15,20 @@ p.privacy { font-size: 0.8em } -footer .page { +.footer .page { border-bottom: 2px solid #CCC; padding-bottom: 2px } -footer .page > section { +.page .centerText { + text-align: center +} + +.page .pageCount { + text-align: right +} + +.footer .page > div { display: inline-block; width: 33% } \ No newline at end of file diff --git a/print/core/components/report-footer/locale/en.yml b/print/core/components/report-footer/locale/en.yml index 404c7e7a4..3899f8b98 100644 --- a/print/core/components/report-footer/locale/en.yml +++ b/print/core/components/report-footer/locale/en.yml @@ -1,4 +1,4 @@ -numPages: Page {{page}} of {{pages}} +numPages: Page of law: privacy: 'In compliance with the provisions of Organic Law 15/1999, on the Protection of Personal Data, we inform you that the personal data you provide diff --git a/print/core/components/report-footer/locale/es.yml b/print/core/components/report-footer/locale/es.yml index 39dae8b58..985c1e17a 100644 --- a/print/core/components/report-footer/locale/es.yml +++ b/print/core/components/report-footer/locale/es.yml @@ -1,4 +1,4 @@ -numPages: Página {{page}} de {{pages}} +numPages: Página de law: privacy: En cumplimiento de lo dispuesto en la Ley Orgánica 15/1999, de Protección de Datos de Carácter Personal, le comunicamos que los datos personales que facilite diff --git a/print/core/components/report-footer/locale/fr.yml b/print/core/components/report-footer/locale/fr.yml index 8f2543640..861ee5684 100644 --- a/print/core/components/report-footer/locale/fr.yml +++ b/print/core/components/report-footer/locale/fr.yml @@ -1,4 +1,4 @@ -numPages: Page {{page}} de {{pages}} +numPages: Page de law: privacy: Conformément aux dispositions de la loi organique 15/1999 sur la protection des données personnelles, nous vous informons que les données personnelles que diff --git a/print/core/components/report-footer/locale/pt.yml b/print/core/components/report-footer/locale/pt.yml index 8b4987bb7..1c343bb4c 100644 --- a/print/core/components/report-footer/locale/pt.yml +++ b/print/core/components/report-footer/locale/pt.yml @@ -1,4 +1,4 @@ -numPages: Página {{page}} de {{pages}} +numPages: Página de law: privacy: Em cumprimento do disposto na lei Orgânica 15/1999, de Protecção de Dados de Carácter Pessoal, comunicamos que os dados pessoais que facilite se incluirão diff --git a/print/core/components/report-footer/report-footer.html b/print/core/components/report-footer/report-footer.html index 4e0b7e327..85395559b 100644 --- a/print/core/components/report-footer/report-footer.html +++ b/print/core/components/report-footer/report-footer.html @@ -1,9 +1,11 @@ -
-
-
{{leftText}}
-
{{centerText}}
-
{{$t('numPages')}}
-
-

{{phytosanitary}}

-

-
+
+ +
diff --git a/print/core/components/report-header/assets/css/style.css b/print/core/components/report-header/assets/css/style.css index cb8cd55c0..3ce75e792 100644 --- a/print/core/components/report-header/assets/css/style.css +++ b/print/core/components/report-header/assets/css/style.css @@ -4,7 +4,7 @@ header { padding-bottom: 10px; margin-bottom: 20px; text-align: center; - font-size: 0.55em; + font-size: 12px; color: #555 } diff --git a/print/core/report.js b/print/core/report.js index db4c9f427..dd305cc89 100644 --- a/print/core/report.js +++ b/print/core/report.js @@ -1,5 +1,6 @@ const fs = require('fs'); -const pdf = require('html-pdf'); +// const pdf = require('html-pdf'); +const puppeteer = require('puppeteer'); const path = require('path'); const config = require('./config'); const Component = require('./component'); @@ -20,18 +21,42 @@ class Report extends Component { async toPdfStream() { const template = await this.render(); - let options = config.pdf; + let options = Object.assign({}, config.pdf); const optionsPath = `${this.path}/options.json`; const fullPath = path.resolve(__dirname, optionsPath); if (fs.existsSync(fullPath)) options = Object.assign(options, require(optionsPath)); - return new Promise(resolve => { + /* return new Promise(resolve => { pdf.create(template, options).toStream((err, stream) => { resolve(stream); }); - }); + }); */ + + const browser = await puppeteer.launch({headless: true}); + const page = await browser.newPage(); + await page.setContent(template); + + const element = await page.$('#pageFooter'); + + let footer = ''; + if (element) { + footer = await page.evaluate(el => { + const html = el.innerHTML; + el.remove(); + return html; + }, element); + } + + options.headerTemplate = '\n'; + options.footerTemplate = footer; + + console.log(options); + const buffer = await page.pdf(options); + await browser.close(); + + return buffer; } } diff --git a/print/methods/report.js b/print/methods/report.js index 348c05ff3..41b09ed05 100644 --- a/print/methods/report.js +++ b/print/methods/report.js @@ -11,7 +11,8 @@ module.exports = app => { res.setHeader('Content-type', 'application/pdf'); res.setHeader('Content-Disposition', `inline; filename="${fileName}"`); - stream.pipe(res); + //stream.pipe(res); + res.end(stream); } catch (error) { next(error); } diff --git a/print/templates/reports/campaign-metrics/campaign-metrics.html b/print/templates/reports/campaign-metrics/campaign-metrics.html index d125ab7e2..536c7c5d2 100644 --- a/print/templates/reports/campaign-metrics/campaign-metrics.html +++ b/print/templates/reports/campaign-metrics/campaign-metrics.html @@ -6,11 +6,7 @@ -
-
- -
-
+
@@ -93,15 +89,11 @@
-
-
- - -
-
+ + diff --git a/print/templates/reports/claim-pickup-order/claim-pickup-order.html b/print/templates/reports/claim-pickup-order/claim-pickup-order.html index 59647cf9a..2fdea5291 100644 --- a/print/templates/reports/claim-pickup-order/claim-pickup-order.html +++ b/print/templates/reports/claim-pickup-order/claim-pickup-order.html @@ -6,11 +6,7 @@ -
-
- -
-
+
@@ -85,15 +81,11 @@
-
-
- - -
-
+ + diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 913946196..5c8dac8eb 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -6,13 +6,9 @@ -
-
- - -
-
+ +
@@ -241,17 +237,13 @@
-
-
- - -
-
+ + diff --git a/print/templates/reports/driver-route/driver-route.html b/print/templates/reports/driver-route/driver-route.html index 919ed0679..549aac060 100644 --- a/print/templates/reports/driver-route/driver-route.html +++ b/print/templates/reports/driver-route/driver-route.html @@ -6,11 +6,7 @@ -
-
- -
-
+
@@ -154,14 +150,10 @@
-
-
- - -
-
+ + diff --git a/print/templates/reports/entry-order/entry-order.html b/print/templates/reports/entry-order/entry-order.html index 3c1cdbd33..cb69ecee9 100644 --- a/print/templates/reports/entry-order/entry-order.html +++ b/print/templates/reports/entry-order/entry-order.html @@ -6,13 +6,9 @@ -
-
- - -
-
+ +
@@ -126,16 +122,12 @@
-
-
- - -
-
+ + diff --git a/print/templates/reports/item-label/options.json b/print/templates/reports/item-label/options.json index 6b00b0443..1cc4e1529 100644 --- a/print/templates/reports/item-label/options.json +++ b/print/templates/reports/item-label/options.json @@ -1,10 +1,11 @@ { - "format": "A4", - "orientation": "landscape", + "landscape": true, "width": "10.4cm", "height": "4.8cm", - "border": "0cm", - "footer": { - "height": "0" + "margin": { + "top": "0cm", + "right": "0cm", + "bottom": "0cm", + "left": "0cm" } } \ No newline at end of file diff --git a/print/templates/reports/letter-debtor/letter-debtor.html b/print/templates/reports/letter-debtor/letter-debtor.html index 81a001765..88bf15bdb 100644 --- a/print/templates/reports/letter-debtor/letter-debtor.html +++ b/print/templates/reports/letter-debtor/letter-debtor.html @@ -6,11 +6,7 @@ -
-
- -
-
+
@@ -74,24 +70,23 @@ - Total {{getTotalDebtOut()}} - {{getTotalDebtIn()}} - {{totalBalance}} + + Total + {{getTotalDebtOut() | currency('EUR', $i18n.locale)}} + + {{getTotalDebtIn() | currency('EUR', $i18n.locale)}} + {{totalBalance | currency('EUR', $i18n.locale)}}
-
-
- - -
-
+ + diff --git a/print/templates/reports/receipt/receipt.html b/print/templates/reports/receipt/receipt.html index 9a4e1964c..3371e6871 100644 --- a/print/templates/reports/receipt/receipt.html +++ b/print/templates/reports/receipt/receipt.html @@ -6,11 +6,7 @@ -
-
- -
-
+
@@ -36,15 +32,11 @@
-
-
- - -
-
+ + diff --git a/print/templates/reports/sepa-core/sepa-core.html b/print/templates/reports/sepa-core/sepa-core.html index d14a3ce6e..300cf976f 100644 --- a/print/templates/reports/sepa-core/sepa-core.html +++ b/print/templates/reports/sepa-core/sepa-core.html @@ -6,11 +6,7 @@ -
-
- -
-
+
@@ -166,15 +162,11 @@
-
-
- - -
-
+ + From c6dc1b6b23d9fdc893e3fa094614bbd7fe8d94c4 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 6 Jul 2020 08:27:05 +0200 Subject: [PATCH 03/20] Label report fixes & report options are not longer shared --- print/core/report.js | 14 ++++---------- print/templates/reports/item-label/options.json | 4 ++-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/print/core/report.js b/print/core/report.js index dd305cc89..ea6a360b5 100644 --- a/print/core/report.js +++ b/print/core/report.js @@ -21,18 +21,13 @@ class Report extends Component { async toPdfStream() { const template = await this.render(); - let options = Object.assign({}, config.pdf); + const defaultOptions = Object.assign({}, config.pdf); const optionsPath = `${this.path}/options.json`; const fullPath = path.resolve(__dirname, optionsPath); + let options = defaultOptions; if (fs.existsSync(fullPath)) - options = Object.assign(options, require(optionsPath)); - - /* return new Promise(resolve => { - pdf.create(template, options).toStream((err, stream) => { - resolve(stream); - }); - }); */ + options = require(optionsPath); const browser = await puppeteer.launch({headless: true}); const page = await browser.newPage(); @@ -40,7 +35,7 @@ class Report extends Component { const element = await page.$('#pageFooter'); - let footer = ''; + let footer = '\n'; if (element) { footer = await page.evaluate(el => { const html = el.innerHTML; @@ -52,7 +47,6 @@ class Report extends Component { options.headerTemplate = '\n'; options.footerTemplate = footer; - console.log(options); const buffer = await page.pdf(options); await browser.close(); diff --git a/print/templates/reports/item-label/options.json b/print/templates/reports/item-label/options.json index 1cc4e1529..98c5788b1 100644 --- a/print/templates/reports/item-label/options.json +++ b/print/templates/reports/item-label/options.json @@ -1,5 +1,4 @@ { - "landscape": true, "width": "10.4cm", "height": "4.8cm", "margin": { @@ -7,5 +6,6 @@ "right": "0cm", "bottom": "0cm", "left": "0cm" - } + }, + "printBackground": true } \ No newline at end of file From b9cc71aeba691a66f75779eb8c740ce3b10c6247 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 6 Jul 2020 12:59:16 +0200 Subject: [PATCH 04/20] There's no way to prevent tbody page-break --- print/common/css/layout.css | 41 ++++++++++--------------------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/print/common/css/layout.css b/print/common/css/layout.css index 3768fb8ea..3b2643dc9 100644 --- a/print/common/css/layout.css +++ b/print/common/css/layout.css @@ -157,32 +157,6 @@ table { border-spacing: 0; } -thead { - display: table-header-group -} - -/** - * Prevent page break fix - */ -tbody { - page-break-inside: avoid; - break-inside: avoid; - display: block -} - -tbody tr { - table-layout: fixed; - display: table -} - -thead, tbody, tbody tr { - width: 100%; -} - -tfoot { - display: block -} - .row-oriented, .column-oriented { text-align: left; width: 100% @@ -198,6 +172,7 @@ tfoot { } .column-oriented thead { + display: table-header-group; background-color: #e5e5e5 } @@ -207,18 +182,24 @@ tfoot { background-color: #e5e5e5 } +.column-oriented tfoot { + display: table-row-group; + page-break-inside: avoid; + break-inside: avoid; +} + .column-oriented tbody { border-bottom: 1px solid #DDD; } -.column-oriented tfoot { - border-top: 2px solid #808080; -} - .column-oriented tfoot tr:first-child td { padding-top: 20px !important; } +.column-oriented tfoot tr:first-child { + border-top: 2px solid #808080; +} + .column-oriented .description { font-size: 0.8em } From 7efba256035b232233c180d39ca62f2c5a2516c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Tue, 7 Jul 2020 15:12:36 +0200 Subject: [PATCH 05/20] Removed role salesPerson for a ticket request --- modules/ticket/front/routes.json | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/ticket/front/routes.json b/modules/ticket/front/routes.json index cfb2d07c9..ac398c49e 100644 --- a/modules/ticket/front/routes.json +++ b/modules/ticket/front/routes.json @@ -189,28 +189,26 @@ "state": "ticket.weekly.index", "component": "vn-ticket-weekly-index", "description": "Weekly tickets" - }, { - "url": "/request", - "state": "ticket.card.request", - "abstract": true, - "component": "ui-view" }, { "url": "/service", "state": "ticket.card.service", "component": "vn-ticket-service", "description": "Service" + }, { + "url": "/request", + "state": "ticket.card.request", + "abstract": true, + "component": "ui-view" }, { "url" : "/index", "state": "ticket.card.request.index", "component": "vn-ticket-request-index", - "description": "Purchase request", - "acl": ["salesPerson"] + "description": "Purchase request" }, { "url" : "/create", "state": "ticket.card.request.create", "component": "vn-ticket-request-create", - "description": "New purchase request", - "acl": ["salesPerson"] + "description": "New purchase request" }, { "url": "/create?clientFk", "state": "ticket.create", From 0335d6c51e0e6348f59ece827abd08a3a94ef224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Thu, 9 Jul 2020 08:45:17 +0200 Subject: [PATCH 06/20] Removed commented lines --- print/core/report.js | 1 - print/methods/report.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/print/core/report.js b/print/core/report.js index ea6a360b5..75eb66962 100644 --- a/print/core/report.js +++ b/print/core/report.js @@ -1,5 +1,4 @@ const fs = require('fs'); -// const pdf = require('html-pdf'); const puppeteer = require('puppeteer'); const path = require('path'); const config = require('./config'); diff --git a/print/methods/report.js b/print/methods/report.js index 41b09ed05..eea249a42 100644 --- a/print/methods/report.js +++ b/print/methods/report.js @@ -10,8 +10,6 @@ module.exports = app => { res.setHeader('Content-type', 'application/pdf'); res.setHeader('Content-Disposition', `inline; filename="${fileName}"`); - - //stream.pipe(res); res.end(stream); } catch (error) { next(error); From 3a8d5c192c0d0c2e9369a9d73f2549eb185a13d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Thu, 9 Jul 2020 12:49:07 +0200 Subject: [PATCH 07/20] HOTFIX: Pagination limit --- modules/client/front/consumption/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/client/front/consumption/index.html b/modules/client/front/consumption/index.html index 8ea65ecae..4bc4c34c3 100644 --- a/modules/client/front/consumption/index.html +++ b/modules/client/front/consumption/index.html @@ -2,6 +2,7 @@ url="Clients/consumption" link="{clientFk: $ctrl.$params.id}" filter="::$ctrl.filter" + limit="20" user-params="::$ctrl.filterParams" data="sales" order="itemTypeFk, itemName, itemSize"> From 7b61e129ffd63448e899494f843988a913a39b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Thu, 9 Jul 2020 13:24:56 +0200 Subject: [PATCH 08/20] HOTFIX: Change claim claimed quantity --- modules/claim/back/models/claim-beginning.js | 3 ++- modules/claim/front/detail/index.js | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/claim/back/models/claim-beginning.js b/modules/claim/back/models/claim-beginning.js index 19e5eb4eb..681aaebc7 100644 --- a/modules/claim/back/models/claim-beginning.js +++ b/modules/claim/back/models/claim-beginning.js @@ -22,7 +22,8 @@ module.exports = Self => { async function claimIsEditable(ctx) { const loopBackContext = LoopBackContext.getCurrentContext(); const httpCtx = {req: loopBackContext.active}; - const isEditable = await Self.app.models.Claim.isEditable(httpCtx, ctx.where.id); + const claimBeginning = await Self.findById(ctx.where.id); + const isEditable = await Self.app.models.Claim.isEditable(httpCtx, claimBeginning.claimFk); if (!isEditable) throw new UserError(`The current claim can't be modified`); diff --git a/modules/claim/front/detail/index.js b/modules/claim/front/detail/index.js index 7719a9fc9..c97f3bd47 100644 --- a/modules/claim/front/detail/index.js +++ b/modules/claim/front/detail/index.js @@ -22,16 +22,25 @@ class Controller extends Section { }; } - set salesClaimed(value) { - this._salesClaimed = value; + get claim() { + return this._claim; + } + + set claim(value) { + this._claim = value; if (value) { - this.calculateTotals(); this.isClaimEditable(); this.isTicketEditable(); } } + set salesClaimed(value) { + this._salesClaimed = value; + + if (value) this.calculateTotals(); + } + get salesClaimed() { return this._salesClaimed; } From 159b5f3bb8a46ee20b89c484807038617155640e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 13 Jul 2020 11:58:31 +0200 Subject: [PATCH 09/20] #2351 Item image queue scheduler --- back/model-config.json | 9 + back/models/image-collection-size.json | 44 +++ back/models/image-collection.json | 57 +++ back/models/image.js | 96 +++++ back/models/image.json | 41 ++ docker-compose.yml | 1 + .../back/methods/item-image-queue/download.js | 54 +++ modules/item/back/model-config.json | 3 + modules/item/back/models/item-image-queue.js | 3 + .../item/back/models/item-image-queue.json | 36 ++ package-lock.json | 366 ++++++++++++++++-- package.json | 1 + 12 files changed, 668 insertions(+), 43 deletions(-) create mode 100644 back/models/image-collection-size.json create mode 100644 back/models/image-collection.json create mode 100644 back/models/image.js create mode 100644 back/models/image.json create mode 100644 modules/item/back/methods/item-image-queue/download.js create mode 100644 modules/item/back/models/item-image-queue.js create mode 100644 modules/item/back/models/item-image-queue.json diff --git a/back/model-config.json b/back/model-config.json index 872f2239e..323e5f233 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -26,6 +26,15 @@ "Delivery": { "dataSource": "vn" }, + "Image": { + "dataSource": "vn" + }, + "ImageCollection": { + "dataSource": "vn" + }, + "ImageCollectionSize": { + "dataSource": "vn" + }, "Province": { "dataSource": "vn" }, diff --git a/back/models/image-collection-size.json b/back/models/image-collection-size.json new file mode 100644 index 000000000..adb92d16b --- /dev/null +++ b/back/models/image-collection-size.json @@ -0,0 +1,44 @@ +{ + "name": "ImageCollectionSize", + "base": "VnModel", + "options": { + "mysql": { + "table": "hedera.imageCollectionSize" + } + }, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "width": { + "type": "Number", + "required": true + }, + "height": { + "type": "Number", + "required": true + }, + "crop": { + "type": "Boolean", + "required": true + } + }, + "relations": { + "collection": { + "type": "belongsTo", + "model": "ImageCollection", + "foreignKey": "collectionFk" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "employee", + "permission": "ALLOW" + } + ] +} + \ No newline at end of file diff --git a/back/models/image-collection.json b/back/models/image-collection.json new file mode 100644 index 000000000..2234766c9 --- /dev/null +++ b/back/models/image-collection.json @@ -0,0 +1,57 @@ +{ + "name": "ImageCollection", + "base": "VnModel", + "options": { + "mysql": { + "table": "hedera.imageCollection" + } + }, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "String", + "required": true + }, + "desc": { + "type": "String", + "required": true + }, + "maxWidth": { + "type": "Number", + "required": true + }, + "maxHeight": { + "type": "Number", + "required": true + }, + "model": { + "type": "String", + "required": true + }, + "property": { + "type": "String", + "required": true + } + }, + "relations": { + "sizes": { + "type": "hasMany", + "model": "ImageCollectionSize", + "foreignKey": "collectionFk", + "property": "id" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "employee", + "permission": "ALLOW" + } + ] +} + \ No newline at end of file diff --git a/back/models/image.js b/back/models/image.js new file mode 100644 index 000000000..5b4a20236 --- /dev/null +++ b/back/models/image.js @@ -0,0 +1,96 @@ +const fs = require('fs-extra'); +const sharp = require('sharp'); +const path = require('path'); + +module.exports = Self => { + Self.register = async(collectionName, file, srcFilePath) => { + const models = Self.app.models; + const tx = await Self.beginTransaction({}); + const myOptions = {transaction: tx}; + + try { + const collection = await models.ImageCollection.findOne({ + fields: [ + 'id', + 'name', + 'maxWidth', + 'maxHeight', + 'model', + 'property' + ], + where: {name: collectionName}, + include: { + relation: 'sizes', + scope: { + fields: ['width', 'height', 'crop'] + } + } + }); + + const fileName = file.split('.')[0]; + // const rootPath = 'C:\\Users\\jsanc\\Desktop\\images'; + const rootPath = '/var/lib/salix/images'; + const data = { + name: fileName, + collectionFk: collectionName + }; + + const newImage = await Self.upsertWithWhere(data, { + name: fileName, + collectionFk: collectionName, + updated: (new Date).getTime() + }, myOptions); + + // Resizes and saves the image + const collectionDir = path.join(rootPath, collectionName); + const dstDir = path.join(collectionDir, 'full'); + const dstFile = path.join(dstDir, file); + + const resizeOpts = { + withoutEnlargement: true, + fit: 'inside' + }; + + await fs.mkdir(dstDir, {recursive: true}); + await sharp(srcFilePath) + .resize(collection.maxWidth, collection.maxHeight, resizeOpts) + .toFile(dstFile); + + const sizes = collection.sizes(); + for (let size of sizes) { + const dstDir = path.join(collectionDir, `${size.width}x${size.height}`); + const dstFile = path.join(dstDir, file); + const resizeOpts = { + withoutEnlargement: true, + fit: size.crop ? 'cover' : 'inside' + }; + + await fs.mkdir(dstDir, {recursive: true}); + await sharp(srcFilePath) + .resize(size.width, size.height, resizeOpts) + .toFile(dstFile); + } + + const model = models[collection.model]; + + if (!model) + throw new Error('Matching model not found'); + + const item = await model.findById(fileName, null, myOptions); + if (item) { + await item.updateAttribute( + collection.property, + fileName, + myOptions + ); + } + + await fs.unlink(srcFilePath); + await tx.commit(); + return newImage; + } catch (e) { + await tx.rollback(); + throw e; + } + }; +}; diff --git a/back/models/image.json b/back/models/image.json new file mode 100644 index 000000000..5b8c76cf1 --- /dev/null +++ b/back/models/image.json @@ -0,0 +1,41 @@ +{ + "name": "Image", + "base": "VnModel", + "options": { + "mysql": { + "table": "hedera.image" + } + }, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "The id" + }, + "name": { + "type": "String", + "required": true + }, + "collectionFk": { + "type": "String", + "required": true + }, + "updated": { + "type": "Number" + }, + "nRefs": { + "type": "Number", + "required": true, + "default": 0 + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "employee", + "permission": "ALLOW" + } + ] +} + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index fabd968a1..413d6f48f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,6 +28,7 @@ services: volumes: - /mnt/storage/pdfs:/var/lib/salix/pdfs - /mnt/storage/dms:/var/lib/salix/dms + - /mnt/storage/images:/var/lib/salix/images deploy: replicas: 6 configs: diff --git a/modules/item/back/methods/item-image-queue/download.js b/modules/item/back/methods/item-image-queue/download.js new file mode 100644 index 000000000..d36604938 --- /dev/null +++ b/modules/item/back/methods/item-image-queue/download.js @@ -0,0 +1,54 @@ +const https = require('https'); +const fs = require('fs-extra'); +const path = require('path'); + +module.exports = Self => { + Self.remoteMethod('download', { + description: 'Returns last entries', + accessType: 'WRITE', + returns: { + type: 'Boolean', + root: true + }, + http: { + path: `/download`, + verb: 'GET' + } + }); + + Self.download = async() => { + const models = Self.app.models; + + try { + const imageQueue = await Self.find({ + limit: 2 + }); + + // const rootPath = 'C:\\Users\\jsanc\\Desktop\\images'; + const rootPath = '/var/lib/salix/images'; + const tempPath = path.join(rootPath, 'temp'); + + // Create temporary path + await fs.mkdir(tempPath); + + for (let image of imageQueue) { + const fileName = `${image.itemFk}.jpg`; + const filePath = path.join(tempPath, fileName); + + https.get(image.url, async response => { + // Upload file to temporary path + const file = fs.createWriteStream(filePath); + response.pipe(file); + + await models.Image.register('catalog', fileName, filePath); + // await image.destroy(); + }); + } + } catch (e) { + fs.unlink(filePath); + throw e; + } + + return true; + }; +}; diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index c085e075a..c5623dcca 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -50,6 +50,9 @@ "ItemShelvingSale": { "dataSource": "vn" }, + "ItemImageQueue": { + "dataSource": "vn" + }, "Origin": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-image-queue.js b/modules/item/back/models/item-image-queue.js new file mode 100644 index 000000000..35a467693 --- /dev/null +++ b/modules/item/back/models/item-image-queue.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/item-image-queue/download')(Self); +}; diff --git a/modules/item/back/models/item-image-queue.json b/modules/item/back/models/item-image-queue.json new file mode 100644 index 000000000..61cb7b018 --- /dev/null +++ b/modules/item/back/models/item-image-queue.json @@ -0,0 +1,36 @@ +{ + "name": "ItemImageQueue", + "description": "Image download queue", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemImageQueue" + } + }, + "properties": { + "itemFk": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "url": { + "type": "String", + "required": true + } + }, + "relations": { + "item": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "itemFk" + } + }, + "acls": [ + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "employee", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5e4ac6c46..92030199a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4690,8 +4690,7 @@ "ansi-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "dev": true + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" }, "ansi-styles": { "version": "3.2.1", @@ -4741,8 +4740,7 @@ "aproba": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", - "dev": true + "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==" }, "archy": { "version": "1.0.0", @@ -4754,7 +4752,6 @@ "version": "1.1.5", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", - "dev": true, "requires": { "delegates": "^1.0.0", "readable-stream": "^2.0.6" @@ -6610,8 +6607,7 @@ "chownr": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.3.tgz", - "integrity": "sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw==", - "dev": true + "integrity": "sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw==" }, "chrome-trace-event": { "version": "1.0.2", @@ -6820,8 +6816,7 @@ "code-point-at": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" }, "collect-v8-coverage": { "version": "1.0.1", @@ -6850,11 +6845,19 @@ "object-visit": "^1.0.0" } }, + "color": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/color/-/color-3.1.2.tgz", + "integrity": "sha512-vXTJhHebByxZn3lDvDJYw4lR5+uB3vuoHsuYA5AKuxRVn5wzzIfQKGLBmgdVRHKTJYeK5rvJcHnrd0Li49CFpg==", + "requires": { + "color-convert": "^1.9.1", + "color-string": "^1.5.2" + } + }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, "requires": { "color-name": "1.1.3" } @@ -6862,8 +6865,16 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "color-string": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.5.3.tgz", + "integrity": "sha512-dC2C5qeWoYkxki5UAXapdjqO672AM4vZuPGRQfO8b5HKuKGBbKWpITyDYN7TOFKvRW7kOgAn3746clDBMDJyQw==", + "requires": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } }, "color-support": { "version": "1.1.3", @@ -7011,8 +7022,7 @@ "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "dev": true + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" }, "consolidate": { "version": "0.15.1", @@ -7563,8 +7573,7 @@ "delegates": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", - "dev": true + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" }, "denque": { "version": "1.4.1", @@ -7604,6 +7613,11 @@ "integrity": "sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=", "dev": true }, + "detect-libc": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", + "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=" + }, "detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -8369,6 +8383,11 @@ } } }, + "expand-template": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", + "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==" + }, "expand-tilde": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/expand-tilde/-/expand-tilde-2.0.2.tgz", @@ -9150,6 +9169,11 @@ "readable-stream": "^2.0.0" } }, + "fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" + }, "fs-extra": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz", @@ -9160,6 +9184,14 @@ "universalify": "^0.1.0" } }, + "fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "requires": { + "minipass": "^3.0.0" + } + }, "fs-mkdirp-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-mkdirp-stream/-/fs-mkdirp-stream-1.0.0.tgz", @@ -9798,7 +9830,6 @@ "version": "2.7.4", "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", - "dev": true, "requires": { "aproba": "^1.0.3", "console-control-strings": "^1.0.0", @@ -9813,14 +9844,12 @@ "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" }, "is-fullwidth-code-point": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "dev": true, "requires": { "number-is-nan": "^1.0.0" } @@ -9829,7 +9858,6 @@ "version": "1.0.2", "resolved": "http://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "dev": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -9840,7 +9868,6 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, "requires": { "ansi-regex": "^2.0.0" } @@ -9948,6 +9975,11 @@ "assert-plus": "^1.0.0" } }, + "github-from-package": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", + "integrity": "sha1-l/tdlr/eiXMxPyDoKI75oWf6ZM4=" + }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", @@ -11293,8 +11325,7 @@ "has-unicode": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", - "dev": true + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" }, "has-value": { "version": "1.0.0", @@ -11897,8 +11928,7 @@ "ini": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", - "dev": true + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" }, "inquirer": { "version": "6.4.1", @@ -12137,8 +12167,7 @@ "is-fullwidth-code-point": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", - "dev": true + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" }, "is-generator-fn": { "version": "2.1.0", @@ -18662,6 +18691,37 @@ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, + "minipass": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz", + "integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==", + "requires": { + "yallist": "^4.0.0" + }, + "dependencies": { + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } + }, + "minizlib": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.0.tgz", + "integrity": "sha512-EzTZN/fjSvifSX0SlqUERCN39o6T40AMarPbv0MrarSFtIITCBh7bi+dU8nxGFHuqs9jdIAeoYoKuQAAASsPPA==", + "requires": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "dependencies": { + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } + }, "mississippi": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/mississippi/-/mississippi-3.0.0.tgz", @@ -18739,6 +18799,11 @@ "minimist": "^1.2.5" } }, + "mkdirp-classic": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", + "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==" + }, "mktmpdir": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/mktmpdir/-/mktmpdir-0.1.1.tgz", @@ -19079,6 +19144,11 @@ "to-regex": "^3.0.1" } }, + "napi-build-utils": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz", + "integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==" + }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -19121,6 +19191,19 @@ "resolved": "https://registry.npmjs.org/nocache/-/nocache-2.1.0.tgz", "integrity": "sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q==" }, + "node-abi": { + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.18.0.tgz", + "integrity": "sha512-yi05ZoiuNNEbyT/xXfSySZE+yVnQW6fxPZuFbLyS1s6b5Kw3HzV2PHOM4XR+nsjzkHxByK+2Wg+yCQbe35l8dw==", + "requires": { + "semver": "^5.4.1" + } + }, + "node-addon-api": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.0.0.tgz", + "integrity": "sha512-sSHCgWfJ+Lui/u+0msF3oyCgvdkhxDbkCS6Q8uiJquzOimkJBvX6hl5aSSA7DR1XbMpdM8r7phjcF63sF4rkKg==" + }, "node-fetch": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", @@ -19507,6 +19590,11 @@ } } }, + "noop-logger": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz", + "integrity": "sha1-lKKxYzxPExdVMAfYlm/Q6EG2pMI=" + }, "nopt": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", @@ -19561,7 +19649,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", - "dev": true, "requires": { "are-we-there-yet": "~1.1.2", "console-control-strings": "~1.1.0", @@ -19581,8 +19668,7 @@ "number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" }, "nwsapi": { "version": "2.2.0", @@ -19598,8 +19684,7 @@ "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" }, "object-copy": { "version": "0.1.0", @@ -20381,6 +20466,53 @@ "integrity": "sha512-pISE66AbVkp4fDQ7VHBwRNXzAAKJjw4Vw7nWI/+Q3vuly7SNfgYXvm6i5IgFylHGK5sP/xHAbB7N49OS4gWNyQ==", "dev": true }, + "prebuild-install": { + "version": "5.3.5", + "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-5.3.5.tgz", + "integrity": "sha512-YmMO7dph9CYKi5IR/BzjOJlRzpxGGVo1EsLSUZ0mt/Mq0HWZIHOKHHcHdT69yG54C9m6i45GpItwRHpk0Py7Uw==", + "requires": { + "detect-libc": "^1.0.3", + "expand-template": "^2.0.3", + "github-from-package": "0.0.0", + "minimist": "^1.2.3", + "mkdirp": "^0.5.1", + "napi-build-utils": "^1.0.1", + "node-abi": "^2.7.0", + "noop-logger": "^0.1.1", + "npmlog": "^4.0.1", + "pump": "^3.0.0", + "rc": "^1.2.7", + "simple-get": "^3.0.3", + "tar-fs": "^2.0.0", + "tunnel-agent": "^0.6.0", + "which-pm-runs": "^1.0.0" + }, + "dependencies": { + "decompress-response": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz", + "integrity": "sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==", + "requires": { + "mimic-response": "^2.0.0" + } + }, + "mimic-response": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz", + "integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==" + }, + "simple-get": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.0.tgz", + "integrity": "sha512-bCR6cP+aTdScaQCnQKbPKtJOKDp/hj9EDLJo3Nw4y1QksqaovlW/bnptB6/c1e+qmNIDHRK+oXFDdEqBT8WzUA==", + "requires": { + "decompress-response": "^4.2.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + } + } + }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", @@ -20729,7 +20861,6 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", - "dev": true, "requires": { "deep-extend": "^0.6.0", "ini": "~1.3.0", @@ -20740,8 +20871,7 @@ "deep-extend": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", - "dev": true + "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==" } } }, @@ -21723,8 +21853,7 @@ "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "dev": true + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" }, "set-value": { "version": "2.0.1", @@ -21779,6 +21908,57 @@ "kind-of": "^6.0.2" } }, + "sharp": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.25.4.tgz", + "integrity": "sha512-umSzJJ1oBwIOfwFFt/fJ7JgCva9FvrEU2cbbm7u/3hSDZhXvkME8WE5qpaJqLIe2Har5msF5UG4CzYlEg5o3BQ==", + "requires": { + "color": "^3.1.2", + "detect-libc": "^1.0.3", + "node-addon-api": "^3.0.0", + "npmlog": "^4.1.2", + "prebuild-install": "^5.3.4", + "semver": "^7.3.2", + "simple-get": "^4.0.0", + "tar": "^6.0.2", + "tunnel-agent": "^0.6.0" + }, + "dependencies": { + "chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==" + }, + "mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==" + }, + "tar": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.0.2.tgz", + "integrity": "sha512-Glo3jkRtPcvpDlAs/0+hozav78yoXKFr+c4wgw62NNMO3oo4AaJdCo21Uu7lcwr55h39W2XD1LMERc64wtbItg==", + "requires": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^3.0.0", + "minizlib": "^2.1.0", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } + }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", @@ -21822,6 +22002,51 @@ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" }, + "simple-concat": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.0.tgz", + "integrity": "sha1-c0TLuLbib7J9ZrL8hvn21Zl1IcY=" + }, + "simple-get": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.0.tgz", + "integrity": "sha512-ZalZGexYr3TA0SwySsr5HlgOOinS4Jsa8YB2GJ6lUNAazyAu4KG/VmzMTwAt2YVXzzVj8QmefmAonZIK2BSGcQ==", + "requires": { + "decompress-response": "^6.0.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + }, + "dependencies": { + "decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "requires": { + "mimic-response": "^3.1.0" + } + }, + "mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==" + } + } + }, + "simple-swizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=", + "requires": { + "is-arrayish": "^0.3.1" + }, + "dependencies": { + "is-arrayish": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" + } + } + }, "sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", @@ -22442,7 +22667,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "dev": true, "requires": { "is-fullwidth-code-point": "^2.0.0", "strip-ansi": "^4.0.0" @@ -22460,7 +22684,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "dev": true, "requires": { "ansi-regex": "^3.0.0" } @@ -22496,8 +22719,7 @@ "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", - "dev": true + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, "strong-error-handler": { "version": "2.3.2", @@ -23080,6 +23302,60 @@ "inherits": "2" } }, + "tar-fs": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.0.tgz", + "integrity": "sha512-9uW5iDvrIMCVpvasdFHW0wJPez0K4JnMZtsuIeDI7HyMGJNxmDZDOCQROr7lXyS+iL/QMpj07qcjGYTSdRFXUg==", + "requires": { + "chownr": "^1.1.1", + "mkdirp-classic": "^0.5.2", + "pump": "^3.0.0", + "tar-stream": "^2.0.0" + } + }, + "tar-stream": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.3.tgz", + "integrity": "sha512-Z9yri56Dih8IaK8gncVPx4Wqt86NDmQTSh49XLZgjWpGZL9GK9HKParS2scqHCC4w6X9Gh2jwaU45V47XTKwVA==", + "requires": { + "bl": "^4.0.1", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "dependencies": { + "bl": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.2.tgz", + "integrity": "sha512-j4OH8f6Qg2bGuWfRiltT2HYGx0e1QcBTrK9KAHNMwMZdQnDZFk0ZSYIpADjYCB3U12nicC5tVJwSIhwOWjb4RQ==", + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } + }, + "buffer": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", + "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", + "requires": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4" + } + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "teeny-request": { "version": "3.11.3", "resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-3.11.3.tgz", @@ -25048,11 +25324,15 @@ "integrity": "sha1-u6Y8qGGUiZT/MHc2CJ47lgJsKk8=", "dev": true }, + "which-pm-runs": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.0.0.tgz", + "integrity": "sha1-Zws6+8VS4LVd9rd4DKdGFfI60cs=" + }, "wide-align": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", - "dev": true, "requires": { "string-width": "^1.0.2 || 2" } diff --git a/package.json b/package.json index 61dff1678..b7cca0364 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "request": "^2.88.0", "request-promise-native": "^1.0.8", "require-yaml": "0.0.1", + "sharp": "^0.25.4", "soap": "^0.26.0", "strong-error-handler": "^2.3.2", "uuid": "^3.3.3", From ccc5b95b48a0d88ddbb78eccb8a1db967c8edde0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 13 Jul 2020 12:23:47 +0200 Subject: [PATCH 10/20] Updated mount paths --- back/models/image.js | 2 +- docker-compose.yml | 2 +- modules/item/back/methods/item-image-queue/download.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/back/models/image.js b/back/models/image.js index 5b4a20236..fb1a887e8 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -29,7 +29,7 @@ module.exports = Self => { const fileName = file.split('.')[0]; // const rootPath = 'C:\\Users\\jsanc\\Desktop\\images'; - const rootPath = '/var/lib/salix/images'; + const rootPath = '/var/lib/salix/image'; const data = { name: fileName, collectionFk: collectionName diff --git a/docker-compose.yml b/docker-compose.yml index 413d6f48f..c04f7e388 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,7 @@ services: volumes: - /mnt/storage/pdfs:/var/lib/salix/pdfs - /mnt/storage/dms:/var/lib/salix/dms - - /mnt/storage/images:/var/lib/salix/images + - /mnt/storage/image:/var/lib/salix/image deploy: replicas: 6 configs: diff --git a/modules/item/back/methods/item-image-queue/download.js b/modules/item/back/methods/item-image-queue/download.js index d36604938..c642a53b4 100644 --- a/modules/item/back/methods/item-image-queue/download.js +++ b/modules/item/back/methods/item-image-queue/download.js @@ -25,7 +25,7 @@ module.exports = Self => { }); // const rootPath = 'C:\\Users\\jsanc\\Desktop\\images'; - const rootPath = '/var/lib/salix/images'; + const rootPath = '/var/lib/salix/image'; const tempPath = path.join(rootPath, 'temp'); // Create temporary path From ee19ea299337720073c0369d44ce3bb63c32ea60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 13 Jul 2020 14:13:21 +0200 Subject: [PATCH 11/20] Restricted to itemFk --- modules/item/back/methods/item-image-queue/download.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/item/back/methods/item-image-queue/download.js b/modules/item/back/methods/item-image-queue/download.js index c642a53b4..74954a6d1 100644 --- a/modules/item/back/methods/item-image-queue/download.js +++ b/modules/item/back/methods/item-image-queue/download.js @@ -7,7 +7,7 @@ module.exports = Self => { description: 'Returns last entries', accessType: 'WRITE', returns: { - type: 'Boolean', + type: ['Object'], root: true }, http: { @@ -21,7 +21,9 @@ module.exports = Self => { try { const imageQueue = await Self.find({ - limit: 2 + where: { + itemFk: 410421 + } }); // const rootPath = 'C:\\Users\\jsanc\\Desktop\\images'; @@ -32,7 +34,7 @@ module.exports = Self => { await fs.mkdir(tempPath); for (let image of imageQueue) { - const fileName = `${image.itemFk}.jpg`; + const fileName = `${image.itemFk}.png`; const filePath = path.join(tempPath, fileName); https.get(image.url, async response => { @@ -49,6 +51,6 @@ module.exports = Self => { throw e; } - return true; + return imageQueue; }; }; From 838b8a53827d1154b83473aa79e2510a8afd0cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 13 Jul 2020 14:22:19 +0200 Subject: [PATCH 12/20] Fix scope var --- modules/item/back/methods/item-image-queue/download.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/item/back/methods/item-image-queue/download.js b/modules/item/back/methods/item-image-queue/download.js index 74954a6d1..799b5db9b 100644 --- a/modules/item/back/methods/item-image-queue/download.js +++ b/modules/item/back/methods/item-image-queue/download.js @@ -19,6 +19,7 @@ module.exports = Self => { Self.download = async() => { const models = Self.app.models; + let filePath; try { const imageQueue = await Self.find({ where: { @@ -35,7 +36,7 @@ module.exports = Self => { for (let image of imageQueue) { const fileName = `${image.itemFk}.png`; - const filePath = path.join(tempPath, fileName); + filePath = path.join(tempPath, fileName); https.get(image.url, async response => { // Upload file to temporary path @@ -46,11 +47,11 @@ module.exports = Self => { // await image.destroy(); }); } + + return imageQueue; } catch (e) { fs.unlink(filePath); throw e; } - - return imageQueue; }; }; From 99aa6b666d8c51d643c2664fc5430b25c34fe270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 13 Jul 2020 14:31:50 +0200 Subject: [PATCH 13/20] Mkdir recursive --- modules/item/back/methods/item-image-queue/download.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/item-image-queue/download.js b/modules/item/back/methods/item-image-queue/download.js index 799b5db9b..91ac59795 100644 --- a/modules/item/back/methods/item-image-queue/download.js +++ b/modules/item/back/methods/item-image-queue/download.js @@ -32,7 +32,7 @@ module.exports = Self => { const tempPath = path.join(rootPath, 'temp'); // Create temporary path - await fs.mkdir(tempPath); + await fs.mkdir(tempPath, {recursive: true}); for (let image of imageQueue) { const fileName = `${image.itemFk}.png`; From 80075a647170eee3aa752683bba4b6d39bee22fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 13 Jul 2020 14:46:00 +0200 Subject: [PATCH 14/20] Added limit --- modules/item/back/methods/item-image-queue/download.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/item/back/methods/item-image-queue/download.js b/modules/item/back/methods/item-image-queue/download.js index 91ac59795..c9e68d719 100644 --- a/modules/item/back/methods/item-image-queue/download.js +++ b/modules/item/back/methods/item-image-queue/download.js @@ -22,9 +22,7 @@ module.exports = Self => { let filePath; try { const imageQueue = await Self.find({ - where: { - itemFk: 410421 - } + limit: 3 }); // const rootPath = 'C:\\Users\\jsanc\\Desktop\\images'; @@ -44,7 +42,7 @@ module.exports = Self => { response.pipe(file); await models.Image.register('catalog', fileName, filePath); - // await image.destroy(); + await image.destroy(); }); } From 3074c9ce3568957cf5d96660f3689d0a5688bb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Tue, 14 Jul 2020 09:32:50 +0200 Subject: [PATCH 15/20] Fixed async image registration --- back/models/image.js | 11 +++++--- .../back/methods/item-image-queue/download.js | 25 ++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/back/models/image.js b/back/models/image.js index fb1a887e8..079acd293 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -3,7 +3,11 @@ const sharp = require('sharp'); const path = require('path'); module.exports = Self => { - Self.register = async(collectionName, file, srcFilePath) => { + Self.getPath = function() { + return '/var/lib/salix/image'; + }; + + Self.registerImage = async(collectionName, file, srcFilePath) => { const models = Self.app.models; const tx = await Self.beginTransaction({}); const myOptions = {transaction: tx}; @@ -25,11 +29,10 @@ module.exports = Self => { fields: ['width', 'height', 'crop'] } } - }); + }, myOptions); const fileName = file.split('.')[0]; - // const rootPath = 'C:\\Users\\jsanc\\Desktop\\images'; - const rootPath = '/var/lib/salix/image'; + const rootPath = Self.getPath(); const data = { name: fileName, collectionFk: collectionName diff --git a/modules/item/back/methods/item-image-queue/download.js b/modules/item/back/methods/item-image-queue/download.js index c9e68d719..dd1af52c9 100644 --- a/modules/item/back/methods/item-image-queue/download.js +++ b/modules/item/back/methods/item-image-queue/download.js @@ -19,14 +19,9 @@ module.exports = Self => { Self.download = async() => { const models = Self.app.models; - let filePath; try { - const imageQueue = await Self.find({ - limit: 3 - }); - - // const rootPath = 'C:\\Users\\jsanc\\Desktop\\images'; - const rootPath = '/var/lib/salix/image'; + const imageQueue = await Self.find({limit: 25}); + const rootPath = models.Image.getPath(); const tempPath = path.join(rootPath, 'temp'); // Create temporary path @@ -34,21 +29,27 @@ module.exports = Self => { for (let image of imageQueue) { const fileName = `${image.itemFk}.png`; - filePath = path.join(tempPath, fileName); + const filePath = path.join(tempPath, fileName); + const file = fs.createWriteStream(filePath); https.get(image.url, async response => { - // Upload file to temporary path - const file = fs.createWriteStream(filePath); response.pipe(file); + }); - await models.Image.register('catalog', fileName, filePath); + file.on('finish', async function() { + await models.Image.registerImage('catalog', fileName, filePath); await image.destroy(); }); + + file.on('error', err => { + fs.unlink(filePath); + + throw err; + }); } return imageQueue; } catch (e) { - fs.unlink(filePath); throw e; } }; From 310b5007f2926b77bbbdb6cc91cbdb6d35072ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Tue, 14 Jul 2020 10:42:25 +0200 Subject: [PATCH 16/20] Disabled jenkins back tests --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2848ea59b..c810dc474 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -69,13 +69,13 @@ pipeline { } } } - stage('Backend') { + /* stage('Backend') { steps { nodejs('node-lts') { sh 'gulp backTestOnce --ci' } } - } + } */ } } stage('Build') { From e557bd2815097ef91ccbb2b324d85e6c47c48130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Tue, 14 Jul 2020 11:16:50 +0200 Subject: [PATCH 17/20] Renamed method --- .../{download.js => downloadImages.js} | 8 ++++---- .../specs/downloadImages.spec.js | 17 +++++++++++++++++ modules/item/back/models/item-image-queue.js | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) rename modules/item/back/methods/item-image-queue/{download.js => downloadImages.js} (90%) create mode 100644 modules/item/back/methods/item-image-queue/specs/downloadImages.spec.js diff --git a/modules/item/back/methods/item-image-queue/download.js b/modules/item/back/methods/item-image-queue/downloadImages.js similarity index 90% rename from modules/item/back/methods/item-image-queue/download.js rename to modules/item/back/methods/item-image-queue/downloadImages.js index dd1af52c9..372648dd6 100644 --- a/modules/item/back/methods/item-image-queue/download.js +++ b/modules/item/back/methods/item-image-queue/downloadImages.js @@ -3,7 +3,7 @@ const fs = require('fs-extra'); const path = require('path'); module.exports = Self => { - Self.remoteMethod('download', { + Self.remoteMethod('downloadImages', { description: 'Returns last entries', accessType: 'WRITE', returns: { @@ -11,12 +11,12 @@ module.exports = Self => { root: true }, http: { - path: `/download`, - verb: 'GET' + path: `/downloadImages`, + verb: 'POST' } }); - Self.download = async() => { + Self.downloadImages = async() => { const models = Self.app.models; try { diff --git a/modules/item/back/methods/item-image-queue/specs/downloadImages.spec.js b/modules/item/back/methods/item-image-queue/specs/downloadImages.spec.js new file mode 100644 index 000000000..305833fe6 --- /dev/null +++ b/modules/item/back/methods/item-image-queue/specs/downloadImages.spec.js @@ -0,0 +1,17 @@ +const app = require('vn-loopback/server/server'); +const fs = require('fs-extra'); + +// #2367 - Create tests when table itemImageQueue exists +xdescribe('ItemImageQueue downloadImages()', () => { + it('should iterate over images', async() => { + spyOn(fs, 'mkdir'); + spyOn(fs, 'createWriteStream'); + + const models = app.models; + const imageModel = spyOn(models.Image, 'registerImage'); + + const res = await app.models.ItemImageQueue.downloadImages(); + + expect(res).toEqual(1); + }); +}); diff --git a/modules/item/back/models/item-image-queue.js b/modules/item/back/models/item-image-queue.js index 35a467693..e2059ddac 100644 --- a/modules/item/back/models/item-image-queue.js +++ b/modules/item/back/models/item-image-queue.js @@ -1,3 +1,3 @@ module.exports = Self => { - require('../methods/item-image-queue/download')(Self); + require('../methods/item-image-queue/downloadImages')(Self); }; From 68c19fa22a77ec40e6219a9d4da55384a08b6c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Tue, 14 Jul 2020 11:17:53 +0200 Subject: [PATCH 18/20] Removed test --- .../specs/downloadImages.spec.js | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 modules/item/back/methods/item-image-queue/specs/downloadImages.spec.js diff --git a/modules/item/back/methods/item-image-queue/specs/downloadImages.spec.js b/modules/item/back/methods/item-image-queue/specs/downloadImages.spec.js deleted file mode 100644 index 305833fe6..000000000 --- a/modules/item/back/methods/item-image-queue/specs/downloadImages.spec.js +++ /dev/null @@ -1,17 +0,0 @@ -const app = require('vn-loopback/server/server'); -const fs = require('fs-extra'); - -// #2367 - Create tests when table itemImageQueue exists -xdescribe('ItemImageQueue downloadImages()', () => { - it('should iterate over images', async() => { - spyOn(fs, 'mkdir'); - spyOn(fs, 'createWriteStream'); - - const models = app.models; - const imageModel = spyOn(models.Image, 'registerImage'); - - const res = await app.models.ItemImageQueue.downloadImages(); - - expect(res).toEqual(1); - }); -}); From 72dfa4262a0373a01b433441d5755d86b0801094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Wed, 15 Jul 2020 12:00:38 +0200 Subject: [PATCH 19/20] Removed limit --- modules/item/back/methods/item-image-queue/downloadImages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/item-image-queue/downloadImages.js b/modules/item/back/methods/item-image-queue/downloadImages.js index 372648dd6..0c2825f8c 100644 --- a/modules/item/back/methods/item-image-queue/downloadImages.js +++ b/modules/item/back/methods/item-image-queue/downloadImages.js @@ -20,7 +20,7 @@ module.exports = Self => { const models = Self.app.models; try { - const imageQueue = await Self.find({limit: 25}); + const imageQueue = await Self.find(); const rootPath = models.Image.getPath(); const tempPath = path.join(rootPath, 'temp'); From da3d20bb16af67ac01d1c9efbd2ced33fd7cdcfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Wed, 15 Jul 2020 12:11:44 +0200 Subject: [PATCH 20/20] Restored limit --- modules/item/back/methods/item-image-queue/downloadImages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/item-image-queue/downloadImages.js b/modules/item/back/methods/item-image-queue/downloadImages.js index 0c2825f8c..372648dd6 100644 --- a/modules/item/back/methods/item-image-queue/downloadImages.js +++ b/modules/item/back/methods/item-image-queue/downloadImages.js @@ -20,7 +20,7 @@ module.exports = Self => { const models = Self.app.models; try { - const imageQueue = await Self.find(); + const imageQueue = await Self.find({limit: 25}); const rootPath = models.Image.getPath(); const tempPath = path.join(rootPath, 'temp');