refactor refs #6184 Changed downloadCmrsZip
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2023-11-13 09:57:25 +01:00
parent 2792efa9cd
commit 64ca72b1f4
1 changed files with 8 additions and 7 deletions

View File

@ -37,7 +37,6 @@ module.exports = Self => {
Self.downloadCmrsZip = async function(ctx, ids, options) {
const models = Self.app.models;
const myOptions = {};
const token = ctx.req.accessToken;
const zip = new JSZip();
if (typeof options == 'object')
@ -47,18 +46,20 @@ module.exports = Self => {
let totalSize = 0;
ids = ids.split(',');
try {
for (let id of ids) {
const baseUrl = (await Self.app.models.Url.getUrl()).replace('#!', 'api');
for (const id of ids) {
if (zipConfig && totalSize > zipConfig.maxSize) throw new UserError('Files are too large');
const baseUrl = (ctx.req.headers.origin)
? `${ctx.req.headers.origin}/api`
: `${ctx.req.headers.referer}api`
const response = await axios.get(
`${baseUrl}/Routes/${id}/cmr?access_token=${token.id}`, {
`${baseUrl}Routes/${id}/cmr`, {
...myOptions,
headers: {
Authorization: ctx.req.accessToken.id
},
responseType: 'arraybuffer',
});
if (response.headers['content-type'] !== 'application/pdf')
throw new UserError(`The response is not a PDF`);