blixify-server 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,l){return new(r=r||Promise)(function(t
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,l){return new(r=r||Promise)(function(i,t){function s(e){try{o(l.next(e))}catch(e){t(e)}}function a(e){try{o(l.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,a)}o((l=l.apply(e,n||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UploadWrapper=void 0;const QueryModel_1=require("../model/QueryModel");class UploadWrapper{constructor(e,t,i,s){this.fbAdmin="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!!(e.assetCollectionName&&e.assetParentId&&e.assetFileName),this.initUpload=(n,i,r)=>__awaiter(this,void 0,void 0,function*(){try{const s=n.body.data;if(this.modelChecker(s)&&n.file){var e=(0,QueryModel_1.checkBaseConfig)(this.config,n),t=(0,QueryModel_1.checkOpsConfig)(this.config,r,n,s);if(e&&t){const a=this.fbAdmin.storage().bucket(),o=this.lib.randomUUID();yield new Promise((e,t)=>{var i=a.file(`${s.assetCollectionName}/${s.assetParentId}/`+s.assetFileName).createWriteStream({metadata:{contentType:n.file.mimetype,customMetadata:{"file-name":n.file.originalname},metadata:{firebaseStorageDownloadTokens:o}}});i.end(n.file.buffer),i.on("error",t),i.on("finish",e)}),i.send({data:o})}else i.status(400).json({err:"Invalid Security Configuration"})}else i.status(400).json({err:"Invalid Fields"})}catch(e){i.status(400).json({err:e})}}),this.initDelete=(s,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i=s.body.data;this.modelChecker(i)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,s),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",s,i),e&&t?(yield this.fbAdmin.storage().bucket().file(`${i.assetCollectionName}/${i.assetParentId}/`+i.assetFileName).delete(),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"})):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/upload",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"create")}),e.post("/update",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"update")}),e.post("/delete",this.initDelete),e},this.fbAdmin=e,this.isProd=t,this.config=i,this.lib=s}}exports.UploadWrapper=UploadWrapper;
|