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' }, //accessScopes: ['read:multimedia'] }); 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); }; };