salix/back/methods/dms/downloadFile.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

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 => {
Self.remoteMethodCtx('downloadFile', {
2019-05-01 16:49:39 +00:00
description: 'Download a document',
accessType: 'READ',
accepts: [
{
arg: 'id',
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: {
path: `/:id/downloadFile`,
2019-05-01 16:49:39 +00:00
verb: 'GET'
},
// accessScopes: ['read:multimedia']
2019-05-01 16:49:39 +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
};
};