Added axios as http package
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
352c3205bf
commit
0b2d62b2bf
|
@ -119,5 +119,6 @@
|
||||||
"The PDF document does not exists": "The PDF document does not exists. Try regenerating it from 'Regenerate invoice PDF' option",
|
"The PDF document does not exists": "The PDF document does not exists. Try regenerating it from 'Regenerate invoice PDF' option",
|
||||||
"This item is not available": "This item is not available",
|
"This item is not available": "This item is not available",
|
||||||
"Deny buy request": "Purchase request for ticket id [{{ticketId}}]({{{url}}}) has been rejected. Reason: {{observation}}",
|
"Deny buy request": "Purchase request for ticket id [{{ticketId}}]({{{url}}}) has been rejected. Reason: {{observation}}",
|
||||||
"The type of business must be filled in basic data": "The type of business must be filled in basic data"
|
"The type of business must be filled in basic data": "The type of business must be filled in basic data",
|
||||||
|
"The worker has hours recorded that day": "The worker has hours recorded that day"
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const got = require('got');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const axios = require('axios');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('createPdf', {
|
Self.remoteMethodCtx('createPdf', {
|
||||||
|
@ -57,13 +57,13 @@ module.exports = Self => {
|
||||||
hasPdf: true
|
hasPdf: true
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const response = got.stream(`${origin}/api/report/invoice`, {
|
return axios.get(`${origin}/api/report/invoice`, {
|
||||||
searchParams: {
|
responseType: 'stream',
|
||||||
|
params: {
|
||||||
authorization: auth.id,
|
authorization: auth.id,
|
||||||
invoiceId: id
|
invoiceId: id
|
||||||
}
|
}
|
||||||
});
|
}).then(async response => {
|
||||||
|
|
||||||
const issued = invoiceOut.issued;
|
const issued = invoiceOut.issued;
|
||||||
const year = issued.getFullYear().toString();
|
const year = issued.getFullYear().toString();
|
||||||
const month = (issued.getMonth() + 1).toString();
|
const month = (issued.getMonth() + 1).toString();
|
||||||
|
@ -79,17 +79,13 @@ module.exports = Self => {
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
const writeStream = fs.createWriteStream(fileSrc);
|
response.data.pipe(fs.createWriteStream(fileSrc));
|
||||||
writeStream.on('open', () => response.pipe(writeStream));
|
}).catch(async() => {
|
||||||
writeStream.on('finish', () => writeStream.end());
|
if (fs.existsSync(fileSrc))
|
||||||
|
await fs.unlink(fileSrc);
|
||||||
return new Promise(resolve => {
|
|
||||||
writeStream.on('close', () => resolve(invoiceOut));
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
if (fs.existsSync(fileSrc))
|
|
||||||
await fs.unlink(fileSrc);
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -12,6 +12,7 @@
|
||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^0.25.0",
|
||||||
"bmp-js": "^0.1.0",
|
"bmp-js": "^0.1.0",
|
||||||
"compression": "^1.7.3",
|
"compression": "^1.7.3",
|
||||||
"fs-extra": "^5.0.0",
|
"fs-extra": "^5.0.0",
|
||||||
|
|
|
@ -76,75 +76,4 @@ module.exports = app => {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// app.use('/api/email', require('../methods/email'));
|
|
||||||
/* const methodsPath = path.resolve(__dirname, '../methods');
|
|
||||||
const methodsDir = fs.readdirSync(methodsPath);
|
|
||||||
const methods = [];
|
|
||||||
|
|
||||||
// Get all methods
|
|
||||||
for (let method of methodsDir) {
|
|
||||||
if (method.includes('.js'))
|
|
||||||
methods.push(method.replace('.js', ''));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auth middleware
|
|
||||||
const paths = [];
|
|
||||||
for (let method of methods)
|
|
||||||
paths.push(`/api/${method}/*`);
|
|
||||||
|
|
||||||
app.use(paths, async function(req, res, next) {
|
|
||||||
const token = getToken(req);
|
|
||||||
const query = `SELECT at.id, at.userId, eu.email, u.lang, at.ttl, at.created
|
|
||||||
FROM salix.AccessToken at
|
|
||||||
JOIN account.user u ON u.id = at.userid
|
|
||||||
JOIN account.emailUser eu ON eu.userFk = u.id
|
|
||||||
WHERE at.id = ?`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const auth = await db.findOne(query, [token]);
|
|
||||||
|
|
||||||
if (!auth || isTokenExpired(auth.created, auth.ttl))
|
|
||||||
throw new Error('Invalid authorization token');
|
|
||||||
|
|
||||||
const args = Object.assign({}, req.query);
|
|
||||||
const props = Object.assign(args, req.body);
|
|
||||||
props.authorization = auth.id;
|
|
||||||
|
|
||||||
req.args = props;
|
|
||||||
req.args.auth = {
|
|
||||||
userId: auth.userId,
|
|
||||||
token: auth.id,
|
|
||||||
email: auth.email,
|
|
||||||
locale: auth.lang
|
|
||||||
};
|
|
||||||
|
|
||||||
next();
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function getToken(request) {
|
|
||||||
const headers = request.headers;
|
|
||||||
const queryParams = request.query;
|
|
||||||
|
|
||||||
return headers.authorization || queryParams.authorization;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isTokenExpired(created, ttl) {
|
|
||||||
const date = new Date(created);
|
|
||||||
const currentDate = new Date();
|
|
||||||
|
|
||||||
date.setSeconds(date.getSeconds() + ttl);
|
|
||||||
|
|
||||||
if (currentDate > date)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mount methods
|
|
||||||
for (let method of methods)
|
|
||||||
require(`../methods/${method}`)(app); */
|
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue