const fs=require("fs"),{promisify:promisify}=require("util"),mime=require("mime-types"),StorageBaseService=require("./base");class FileService extends StorageBaseService{async exec(){const{ctx:e}=this,t=global.uniCloud.$scope.file,i=new URL(e.req.url,"https://localhost/"),s=i.pathname.replace(/^\/storage\/file\//,"");t.verifySign(s,i.searchParams.get("expires"),i.searchParams.get("signature"))||this.ctx.throw("storage_permission_denied: "+s);const r=t.getFilePath(s);let o;try{o=await promisify(fs.stat)(r)}catch(e){const{code:t,message:i}=e;"ENOENT"===t&&this.ctx.throw("404","NOT_FOUND"),this.ctx.throw(i,"SYSTEM_ERROR")}e.respond=!1,e.res.writeHead(200,{"Content-Disposition":"inline","Content-Type":mime.lookup(s)||"application/octet-stream","Content-Length":o.size.toString()}),t.getFileStream(s).pipe(e.res)}}module.exports=FileService;