blixify-server 0.3.3 → 0.3.4
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.
|
@@ -16,11 +16,14 @@ export declare class UploadWrapper {
|
|
|
16
16
|
lib: UploadLib;
|
|
17
17
|
storageType: string;
|
|
18
18
|
modelChecker: (obj: any, isDeleteDirectory?: boolean) => boolean;
|
|
19
|
-
constructor(uploadAdmin: any, isProd: boolean, config: SecurityConfig, lib: UploadLib, storageType?: "firebase" | "aws");
|
|
19
|
+
constructor(uploadAdmin: any, isProd: boolean, config: SecurityConfig, lib: UploadLib, storageType?: "firebase" | "aws" | "file");
|
|
20
|
+
private ensureDirectoryExists;
|
|
21
|
+
private getLocalFilePath;
|
|
20
22
|
initUpload: (req: any, res: any, type: "create" | "update") => Promise<void>;
|
|
21
23
|
initDelete: (req: any, res: any) => Promise<void>;
|
|
22
24
|
deleteGoogleFolderContents: (folderRef: any) => Promise<void>;
|
|
23
25
|
deleteAWSFolderContent: (bucketName: string, directoryPrefix: string) => Promise<void>;
|
|
26
|
+
deleteLocalFolderContents: (folderPath: string) => Promise<void>;
|
|
24
27
|
initDeleteDirectory: (req: any, res: any) => Promise<void>;
|
|
25
28
|
initBatchDeleteDirectory: (req: any, res: any) => Promise<void>;
|
|
26
29
|
initGet: (req: any, res: any) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/uploadWrapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uploadWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/uploadWrapper.ts"],"names":[],"mappings":"AAKA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,UAAU,SAAS;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,EAAE,GAAG,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,WAAW,EAAE,GAAG,CAAM;IACtB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,SAAS,CAAC;IACf,WAAW,SAAc;IAEzB,YAAY,QAAS,GAAG,sBAAsB,OAAO,aAUnD;gBAGA,WAAW,EAAE,GAAG,EAChB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,SAAS,EACd,WAAW,CAAC,EAAE,UAAU,GAAG,KAAK,GAAG,MAAM;IAS3C,OAAO,CAAC,qBAAqB;IAM7B,OAAO,CAAC,gBAAgB;IAkBxB,UAAU,QAAe,GAAG,OAAO,GAAG,QAAQ,QAAQ,GAAG,QAAQ,mBA4H/D;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAiDpC;IAEF,0BAA0B,cAAqB,GAAG,mBAwBhD;IAEF,sBAAsB,eACR,MAAM,mBACD,MAAM,mBAiBvB;IAEF,yBAAyB,eAAsB,MAAM,mBAenD;IAEF,mBAAmB,QAAe,GAAG,OAAO,GAAG,mBA6C7C;IAEF,wBAAwB,QAAe,GAAG,OAAO,GAAG,mBAmDlD;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA2DjC;IAEF,IAAI,YA6EF;CACH"}
|
|
@@ -14,7 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.UploadWrapper = void 0;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
18
|
const mime_1 = __importDefault(require("mime"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
18
20
|
const QueryModel_1 = require("../model/QueryModel");
|
|
19
21
|
/**
|
|
20
22
|
* @Wrapper
|
|
@@ -101,6 +103,24 @@ class UploadWrapper {
|
|
|
101
103
|
yield s3UploadPromise("file");
|
|
102
104
|
res.send({ data: token });
|
|
103
105
|
}
|
|
106
|
+
else if (this.storageType === "file") {
|
|
107
|
+
if (respData.downloadLink) {
|
|
108
|
+
const response = yield (0, axios_1.default)({
|
|
109
|
+
method: "GET",
|
|
110
|
+
url: respData.downloadLink,
|
|
111
|
+
responseType: "arraybuffer",
|
|
112
|
+
});
|
|
113
|
+
if (response.data) {
|
|
114
|
+
const filePath = this.getLocalFilePath(respData.bucketName, respData.assetCollectionName, respData.assetParentId, respData.assetFileName);
|
|
115
|
+
fs_1.default.writeFileSync(filePath, response.data);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (req.file) {
|
|
119
|
+
const filePath = this.getLocalFilePath(respData.bucketName, respData.assetCollectionName, respData.assetParentId, respData.assetFileName);
|
|
120
|
+
fs_1.default.writeFileSync(filePath, req.file.buffer);
|
|
121
|
+
}
|
|
122
|
+
res.send({ data: token });
|
|
123
|
+
}
|
|
104
124
|
else {
|
|
105
125
|
const firebaseBucket = this.uploadAdmin.storage().bucket();
|
|
106
126
|
const uploadFilePromise = (type, response) => {
|
|
@@ -169,6 +189,12 @@ class UploadWrapper {
|
|
|
169
189
|
};
|
|
170
190
|
yield s3.deleteObject(params).promise();
|
|
171
191
|
}
|
|
192
|
+
else if (this.storageType === "file") {
|
|
193
|
+
const filePath = this.getLocalFilePath(respData.bucketName, respData.assetCollectionName, respData.assetParentId, respData.assetFileName);
|
|
194
|
+
if (fs_1.default.existsSync(filePath)) {
|
|
195
|
+
fs_1.default.unlinkSync(filePath);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
172
198
|
else {
|
|
173
199
|
const firebaseBucket = this.uploadAdmin.storage().bucket();
|
|
174
200
|
yield firebaseBucket
|
|
@@ -224,6 +250,24 @@ class UploadWrapper {
|
|
|
224
250
|
}
|
|
225
251
|
catch (error) { }
|
|
226
252
|
});
|
|
253
|
+
this.deleteLocalFolderContents = (folderPath) => __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
try {
|
|
255
|
+
if (fs_1.default.existsSync(folderPath)) {
|
|
256
|
+
const files = fs_1.default.readdirSync(folderPath);
|
|
257
|
+
for (const file of files) {
|
|
258
|
+
const curPath = path_1.default.join(folderPath, file);
|
|
259
|
+
if (fs_1.default.lstatSync(curPath).isDirectory()) {
|
|
260
|
+
yield this.deleteLocalFolderContents(curPath);
|
|
261
|
+
fs_1.default.rmdirSync(curPath);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
fs_1.default.unlinkSync(curPath);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
catch (error) { }
|
|
270
|
+
});
|
|
227
271
|
this.initDeleteDirectory = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
228
272
|
try {
|
|
229
273
|
const respData = req.body.data;
|
|
@@ -239,6 +283,10 @@ class UploadWrapper {
|
|
|
239
283
|
if (this.storageType === "aws") {
|
|
240
284
|
yield this.deleteAWSFolderContent(`${respData.bucketName}`, `${respData.assetCollectionName}/${respData.assetParentId}/`);
|
|
241
285
|
}
|
|
286
|
+
else if (this.storageType === "file") {
|
|
287
|
+
const folderPath = path_1.default.join(this.uploadAdmin, respData.bucketName, respData.assetCollectionName, respData.assetParentId);
|
|
288
|
+
yield this.deleteLocalFolderContents(folderPath);
|
|
289
|
+
}
|
|
242
290
|
else {
|
|
243
291
|
const folderRef = this.uploadAdmin
|
|
244
292
|
.storage()
|
|
@@ -273,6 +321,10 @@ class UploadWrapper {
|
|
|
273
321
|
if (this.storageType === "aws") {
|
|
274
322
|
yield this.deleteAWSFolderContent(`${respData.bucketName}`, `${respData.assetCollectionName}/${eachId}/`);
|
|
275
323
|
}
|
|
324
|
+
else if (this.storageType === "file") {
|
|
325
|
+
const folderPath = path_1.default.join(this.uploadAdmin, respData.bucketName, respData.assetCollectionName, eachId);
|
|
326
|
+
yield this.deleteLocalFolderContents(folderPath);
|
|
327
|
+
}
|
|
276
328
|
else {
|
|
277
329
|
const folderRef = this.uploadAdmin
|
|
278
330
|
.storage()
|
|
@@ -324,6 +376,24 @@ class UploadWrapper {
|
|
|
324
376
|
}
|
|
325
377
|
}));
|
|
326
378
|
}
|
|
379
|
+
else if (this.storageType === "file") {
|
|
380
|
+
const filePath = path_1.default.join(this.uploadAdmin, bucketName, assetCollectionName, assetParentId, nestedPath);
|
|
381
|
+
if (fs_1.default.existsSync(filePath)) {
|
|
382
|
+
const extension = nestedPath.split(".").pop();
|
|
383
|
+
let contentType;
|
|
384
|
+
if (extension === "mbtiles") {
|
|
385
|
+
contentType = "application/vnd.mapbox-vector-tile";
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
contentType = mime_1.default.getType(extension) || "application/octet-stream";
|
|
389
|
+
}
|
|
390
|
+
res.set("Content-Type", contentType);
|
|
391
|
+
res.sendFile(filePath);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
res.status(404).send({ message: "File not found" });
|
|
395
|
+
}
|
|
396
|
+
}
|
|
327
397
|
}
|
|
328
398
|
catch (error) {
|
|
329
399
|
res.status(400).json({ err: error });
|
|
@@ -396,5 +466,16 @@ class UploadWrapper {
|
|
|
396
466
|
this.lib = lib;
|
|
397
467
|
this.storageType = storageType !== null && storageType !== void 0 ? storageType : "firebase";
|
|
398
468
|
}
|
|
469
|
+
ensureDirectoryExists(dirPath) {
|
|
470
|
+
if (!fs_1.default.existsSync(dirPath)) {
|
|
471
|
+
fs_1.default.mkdirSync(dirPath, { recursive: true });
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
getLocalFilePath(bucketName, assetCollectionName, assetParentId, assetFileName) {
|
|
475
|
+
const basePath = this.uploadAdmin;
|
|
476
|
+
const fullPath = path_1.default.join(basePath, bucketName, assetCollectionName, assetParentId, assetFileName);
|
|
477
|
+
this.ensureDirectoryExists(path_1.default.dirname(fullPath));
|
|
478
|
+
return fullPath;
|
|
479
|
+
}
|
|
399
480
|
}
|
|
400
481
|
exports.UploadWrapper = UploadWrapper;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blixify-server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.04",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/apis/index.js",
|
|
6
6
|
"private": false,
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"start:mongo": "cd dist && node mongoServer.js",
|
|
26
26
|
"start:fb": "cd dist && node firebaseServer.js",
|
|
27
27
|
"start:auth": "cd dist && node authServer.js",
|
|
28
|
+
"start:file": "cd dist && node fileServer.js",
|
|
28
29
|
"start:aws": "cd dist && node awsServer.js",
|
|
29
30
|
"start:monday": "cd dist && node mondayServer.js",
|
|
30
31
|
"start:trackVision": "cd dist && node trackVisionServer.js",
|