blixify-server 0.1.8 → 0.1.9
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.
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import SecurityConfig from "../model/SecurityConfig";
|
|
2
|
+
interface UploadLib {
|
|
3
|
+
multer: any;
|
|
4
|
+
randomUUID: any;
|
|
5
|
+
express?: any;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @Wrapper
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export declare class UploadWrapper {
|
|
12
|
+
fbAdmin: any;
|
|
13
|
+
isProd: boolean;
|
|
14
|
+
config: SecurityConfig;
|
|
15
|
+
lib: UploadLib;
|
|
16
|
+
modelChecker: (obj: any) => boolean;
|
|
17
|
+
constructor(fbAdmin: any, isProd: boolean, config: SecurityConfig, lib: UploadLib);
|
|
18
|
+
initUpload: (req: any, res: any, type: "create" | "update") => Promise<void>;
|
|
19
|
+
initDelete: (req: any, res: any) => Promise<void>;
|
|
20
|
+
init: () => any;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=uploadWrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/uploadWrapper.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,UAAU,SAAS;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,EAAE,GAAG,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,EAAE,GAAG,CAAM;IAClB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,SAAS,CAAC;IACf,YAAY,QAAS,GAAG,aAMtB;gBAGA,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,SAAS;IAQhB,UAAU,QAAe,GAAG,OAAO,GAAG,QAAQ,QAAQ,GAAG,QAAQ,mBA4C/D;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA8BpC;IAEF,IAAI,YA0CF;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,l){return new(r=r||Promise)(function(t,i){function o(e){try{s(l.next(e))}catch(e){i(e)}}function a(e){try{s(l.throw(e))}catch(e){i(e)}}function s(e){var i;e.done?t(e.value):((i=e.value)instanceof r?i:new r(function(e){e(i)})).then(o,a)}s((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,i,t,o){this.fbAdmin="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!!(e.imageCollectionName&&e.imageFileName&&e.id),this.initUpload=(n,t,r)=>__awaiter(this,void 0,void 0,function*(){try{const o=n.body.data;if(this.modelChecker(o)&&n.file){var e=(0,QueryModel_1.checkBaseConfig)(this.config,n),i=(0,QueryModel_1.checkOpsConfig)(this.config,r,n,o);if(e&&i){const a=this.fbAdmin.storage().bucket(),s=this.lib.randomUUID();yield new Promise((e,i)=>{var t=a.file(`${o.imageCollectionName}/${o.id}/`+o.imageFileName).createWriteStream({metadata:{contentType:n.file.mimetype,customMetadata:{"file-name":n.file.originalname},metadata:{firebaseStorageDownloadTokens:s}}});t.end(n.file.buffer),t.on("error",i),t.on("finish",e)}),t.send({data:s})}else t.status(400).json({err:"Invalid Security Configuration"})}else t.status(400).json({err:"Invalid Fields"})}catch(e){t.status(400).json({err:e})}}),this.initDelete=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,i,t=o.body.data;this.modelChecker(t)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,o),i=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,t),e&&i?(yield this.fbAdmin.storage().bucket().file(`${t.imageCollectionName}/${t.id}/`+t.imageFileName).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,i)=>{this.initUpload(e,i,"create")}),e.post("/update",this.lib.multer.single("file"),(e,i)=>{this.initUpload(e,i,"update")}),e.post("/delete",this.initDelete),e},this.fbAdmin=e,this.isProd=i,this.config=t,this.lib=o}}exports.UploadWrapper=UploadWrapper;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blixify-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/apis/index.js",
|
|
6
6
|
"private": false,
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"helmet": "^6.0.0",
|
|
52
52
|
"husky": "^8.0.2",
|
|
53
53
|
"mongodb": "^4.11.0",
|
|
54
|
+
"multer": "^1.4.5-lts.1",
|
|
54
55
|
"typescript": "^4.6.4"
|
|
55
56
|
}
|
|
56
57
|
}
|