2152 - Show identifier at file name on downloads
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
16cdc419ea
commit
676033060d
|
@ -13,12 +13,49 @@ module.exports = app => {
|
||||||
if (!hasRequiredArgs)
|
if (!hasRequiredArgs)
|
||||||
throw new Error(`Required properties not found [${argList}]`);
|
throw new Error(`Required properties not found [${argList}]`);
|
||||||
|
|
||||||
const report = new Report(req.params.name, args);
|
const reportName = req.params.name;
|
||||||
|
const fileName = getFileName(reportName, args);
|
||||||
|
const report = new Report(reportName, args);
|
||||||
const stream = await report.toPdfStream();
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
res.setHeader('Content-type', 'application/pdf');
|
res.setHeader('Content-type', 'application/pdf');
|
||||||
|
res.setHeader('Content-Disposition', `inline; filename="${fileName}"`);
|
||||||
|
|
||||||
stream.pipe(res);
|
stream.pipe(res);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all the params that ends with id
|
||||||
|
* @param {object} args - Params object
|
||||||
|
*
|
||||||
|
* @return {array} List of identifiers
|
||||||
|
*/
|
||||||
|
function getIdentifiers(args) {
|
||||||
|
const identifiers = [];
|
||||||
|
const keys = Object.keys(args);
|
||||||
|
|
||||||
|
for (let arg of keys) {
|
||||||
|
// FIXME: #2197 - Remove clientId as a required param
|
||||||
|
if (arg != 'clientId' && arg.endsWith('Id'))
|
||||||
|
identifiers.push(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return identifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileName(name, args) {
|
||||||
|
const identifiers = getIdentifiers(args);
|
||||||
|
const params = [];
|
||||||
|
params.push(name);
|
||||||
|
|
||||||
|
for (let id of identifiers)
|
||||||
|
params.push(args[id]);
|
||||||
|
|
||||||
|
const fileName = params.join('_');
|
||||||
|
|
||||||
|
return `${fileName}.pdf`;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue