UNPKG

decentralized-internet

Version:

An NPM library of programs to create decentralized web and distributed computing projects

1 lines 994 B
var request=require("request"),_=require("underscore"),Promise=require("bluebird"),Stream=require("stream"),Boom=require("boom");module.exports=function(e,r){var o=require("clusterpost-model"),t=require("@hapi/joi");e.method({name:"clusterprovider.isJobDocument",method:function(e){return t.assert(e,o.job),Promise.resolve(e)},options:{}});e.method({name:"clusterprovider.validateJobOwnership",method:function(e,r){return new Promise(function(o,t){var i,n;e.userEmail===r.email||r.scope.indexOf("admin")>=0||r.scope.indexOf("executionserver")>=0||(i=r.scope,n=e.scope,i&&n&&_.intersection(i,n).length>0)?o(e):t(Boom.unauthorized("You are not allowed to access this job document!"))})},options:{}});e.method({name:"clusterprovider.downloadAttachment",method:function(e,r){return t.assert(r,t.string()),new Promise(function(o,t){try{var i=fs.createWriteStream(r);request(e).pipe(i),i.on("finish",function(e){e?t({path:r,status:!1,error:e}):o({path:r,status:!0})})}catch(e){t(e)}})},options:{}})};