2020-04-03 15:52:47 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
2019-05-01 16:49:39 +00:00
|
|
|
module.exports = Self => {
|
2019-06-06 11:59:11 +00:00
|
|
|
Self.remoteMethodCtx('downloadFile', {
|
2019-05-01 16:49:39 +00:00
|
|
|
description: 'Download a document',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [
|
|
|
|
{
|
|
|
|
arg: 'id',
|
2019-06-26 11:35:38 +00:00
|
|
|
type: 'Number',
|
2019-05-01 16:49:39 +00:00
|
|
|
description: 'The document id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
returns: [
|
|
|
|
{
|
|
|
|
arg: 'body',
|
|
|
|
type: 'file',
|
|
|
|
root: true
|
|
|
|
}, {
|
|
|
|
arg: 'Content-Type',
|
|
|
|
type: 'String',
|
|
|
|
http: {target: 'header'}
|
|
|
|
}, {
|
|
|
|
arg: 'Content-Disposition',
|
|
|
|
type: 'String',
|
|
|
|
http: {target: 'header'}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
http: {
|
2019-06-06 11:59:11 +00:00
|
|
|
path: `/:id/downloadFile`,
|
2019-05-01 16:49:39 +00:00
|
|
|
verb: 'GET'
|
2024-02-26 05:57:17 +00:00
|
|
|
},
|
2024-04-04 08:13:56 +00:00
|
|
|
// accessScopes: ['read:multimedia']
|
2019-05-01 16:49:39 +00:00
|
|
|
});
|
|
|
|
|
2019-06-06 11:59:11 +00:00
|
|
|
Self.downloadFile = async function(ctx, id) {
|
2020-04-03 15:52:47 +00:00
|
|
|
if (!await Self.checkRole(ctx, id))
|
|
|
|
throw new UserError(`You don't have enough privileges`);
|
|
|
|
return await Self.getFile(id);
|
2019-05-01 16:49:39 +00:00
|
|
|
};
|
|
|
|
};
|