refs #6184 saveCmr #1788
|
@ -37,7 +37,6 @@ module.exports = Self => {
|
||||||
Self.downloadCmrsZip = async function(ctx, ids, options) {
|
Self.downloadCmrsZip = async function(ctx, ids, options) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
const token = ctx.req.accessToken;
|
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
|
@ -47,15 +46,17 @@ module.exports = Self => {
|
||||||
let totalSize = 0;
|
let totalSize = 0;
|
||||||
ids = ids.split(',');
|
ids = ids.split(',');
|
||||||
try {
|
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');
|
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(
|
const response = await axios.get(
|
||||||
guillermo marked this conversation as resolved
Outdated
alexm
commented
No he gastat mai .referer, pero crec que es millor gastar la funcio que crea pablo encomter de ctx.req.headers.origin No he gastat mai .referer, pero crec que es millor gastar la funcio que crea pablo encomter de ctx.req.headers.origin
back/methods/url/getUrl.js
guillermo
commented
El problema es que no quiero el "/#!/", ya que quiero apuntar a la API El problema es que no quiero el "/#!/", ya que quiero apuntar a la API
|
|||||||
`${baseUrl}/Routes/${id}/cmr?access_token=${token.id}`, {
|
`${baseUrl}Routes/${id}/cmr`, {
|
||||||
...myOptions,
|
...myOptions,
|
||||||
|
headers: {
|
||||||
|
Authorization: ctx.req.accessToken.id
|
||||||
|
},
|
||||||
responseType: 'arraybuffer',
|
responseType: 'arraybuffer',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
En javascript se puede hacer
const [data] = ...
y cojera el primer valor de la arrayAsi luego puedes hacer
zip.file(`${id}.pdf`, data, {binary: true});