fixes #5529 Fixes: missing awaits, buffer-to-file
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
e8f0a49f0c
commit
0372d44415
|
@ -56,7 +56,7 @@ module.exports = Self => {
|
|||
reference: invoiceOut.ref,
|
||||
recipientId: invoiceOut.clientFk
|
||||
});
|
||||
const stream = await invoiceReport.toPdfStream();
|
||||
const buffer = await invoiceReport.toPdfStream();
|
||||
|
||||
const issued = invoiceOut.issued;
|
||||
const year = issued.getFullYear().toString();
|
||||
|
@ -66,7 +66,7 @@ module.exports = Self => {
|
|||
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
||||
|
||||
// Store invoice
|
||||
print.storage.write(stream, {
|
||||
await print.storage.write(buffer, {
|
||||
type: 'invoice',
|
||||
path: `${year}/${month}/${day}`,
|
||||
fileName: fileName
|
||||
|
|
|
@ -100,16 +100,23 @@ class Controller extends Section {
|
|||
};
|
||||
|
||||
this.$http.post(`InvoiceOuts/invoiceClient`, params)
|
||||
.then(() => this.invoiceNext())
|
||||
.catch(res => {
|
||||
this.errors.unshift({
|
||||
address,
|
||||
message: res.data.error.message
|
||||
});
|
||||
const message = res.data?.error?.message || res.message;
|
||||
if (res.status >= 400 && res.status < 500) {
|
||||
this.errors.unshift({address, message});
|
||||
this.invoiceNext();
|
||||
} else {
|
||||
this.invoicing = false;
|
||||
this.status = 'done';
|
||||
throw new UserError(`Critical invoicing error, proccess stopped`);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
}
|
||||
|
||||
invoiceNext() {
|
||||
this.addressIndex++;
|
||||
this.invoiceOut();
|
||||
});
|
||||
}
|
||||
|
||||
get nAddresses() {
|
||||
|
|
|
@ -18,3 +18,4 @@ Invoice out: Facturar
|
|||
One client: Un solo cliente
|
||||
Choose a valid client: Selecciona un cliente válido
|
||||
Stop: Parar
|
||||
Critical invoicing error, proccess stopped: Error crítico al facturar, proceso detenido
|
|
@ -46,7 +46,7 @@ module.exports = async function(Self, tickets, reqArgs = {}) {
|
|||
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
||||
|
||||
// Store invoice
|
||||
storage.write(stream, {
|
||||
await storage.write(stream, {
|
||||
type: 'invoice',
|
||||
path: `${year}/${month}/${day}`,
|
||||
fileName: fileName
|
||||
|
|
|
@ -4,7 +4,7 @@ const {cpus} = require('os');
|
|||
|
||||
module.exports = {
|
||||
init() {
|
||||
if (!this.pool) {
|
||||
if (this.pool) return;
|
||||
Cluster.launch({
|
||||
concurrency: Cluster.CONCURRENCY_CONTEXT,
|
||||
maxConcurrency: cpus().length,
|
||||
|
@ -16,8 +16,7 @@ module.exports = {
|
|||
'--no-zygote'
|
||||
]
|
||||
}
|
||||
})
|
||||
.then(cluster => {
|
||||
}).then(cluster => {
|
||||
this.pool = cluster;
|
||||
|
||||
log4js.configure({
|
||||
|
@ -39,5 +38,4 @@ module.exports = {
|
|||
cluster.on('queue', () => logger.info('Printing task initialized by pool'));
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -32,8 +32,9 @@ class Report extends Component {
|
|||
if (fs.existsSync(fullPath))
|
||||
options = require(optionsPath);
|
||||
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve, reject) => {
|
||||
Cluster.pool.queue({}, async({page}) => {
|
||||
try {
|
||||
await page.emulateMediaType('screen');
|
||||
await page.setContent(template);
|
||||
|
||||
|
@ -51,9 +52,11 @@ class Report extends Component {
|
|||
options.headerTemplate = '\n';
|
||||
options.footerTemplate = footer;
|
||||
|
||||
const stream = await page.pdf(options);
|
||||
|
||||
resolve(stream);
|
||||
const buffer = await page.pdf(options);
|
||||
resolve(buffer);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3,26 +3,14 @@ const path = require('path');
|
|||
const fs = require('fs-extra');
|
||||
|
||||
module.exports = {
|
||||
async write(stream, options) {
|
||||
async write(buffer, options) {
|
||||
const storage = config.storage[options.type];
|
||||
|
||||
if (!storage) return;
|
||||
|
||||
const src = path.join(storage.root, options.path);
|
||||
const fileSrc = path.join(src, options.fileName);
|
||||
|
||||
await fs.mkdir(src, {recursive: true});
|
||||
|
||||
const writeStream = fs.createWriteStream(fileSrc);
|
||||
writeStream.on('open', () => writeStream.write(stream));
|
||||
writeStream.on('finish', () => writeStream.end());
|
||||
|
||||
return new Promise(resolve => {
|
||||
writeStream.on('close', () => resolve());
|
||||
});
|
||||
},
|
||||
|
||||
load(type, data) {
|
||||
|
||||
await fs.writeFile(fileSrc, buffer);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue