2020-04-03 15:52:47 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('downloadFile', {
|
|
|
|
description: 'Download a worker document',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [
|
|
|
|
{
|
|
|
|
arg: 'id',
|
|
|
|
type: 'Number',
|
|
|
|
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`,
|
|
|
|
verb: 'GET'
|
2024-02-26 05:57:17 +00:00
|
|
|
},
|
|
|
|
accessScopes: ['read:multimedia']
|
2020-04-03 15:52:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Self.downloadFile = async function(ctx, id) {
|
|
|
|
if (!await Self.app.models.Dms.checkRole(ctx, id) && !await Self.isMine(ctx, id))
|
|
|
|
throw new UserError(`You don't have enough privileges`);
|
|
|
|
return await Self.app.models.Dms.getFile(id);
|
|
|
|
};
|
|
|
|
};
|