const fs=require("fs"),formidable=require("formidable"),StorageBaseService=require("./base");class UploadService extends StorageBaseService{async exec(){const{req:e}=this.ctx,r={},i=global.uniCloud.$scope.file,t=formidable({fileWriteStreamHandler:()=>{i.ensureCloudPath(r.key);const e=i.getFilePath(r.key);return fs.createWriteStream(e)}});t.on("field",(function(e,i){r[e]=i})).on("fileBegin",(function(){const e=r.key;if(!0!==i.verifyUploadSign(e,r.policy,r.signature))throw new Error("storage_permission_denied: "+e)})),t.parse(e,(e=>{e&&this.ctx.throw(e.message),this.ctx.send({})}))}}module.exports=UploadService;