@dataclouder/nest-storage 0.0.2 → 0.0.3
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.
- package/controllers/storage.controller.d.ts +6 -0
- package/controllers/storage.controller.js +44 -0
- package/controllers/storage.controller.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/models/cloud.model.d.ts +30 -2
- package/nest-storage.module.js +18 -2
- package/nest-storage.module.js.map +1 -1
- package/package.json +4 -1
- package/services/cloud-storage.service.d.ts +9 -4
- package/services/cloud-storage.service.js +44 -24
- package/services/cloud-storage.service.js.map +1 -1
- package/services/cloudflare-r2.service.d.ts +27 -0
- package/services/cloudflare-r2.service.js +223 -0
- package/services/cloudflare-r2.service.js.map +1 -0
- package/services/storage.factory.d.ts +9 -0
- package/services/storage.factory.js +39 -0
- package/services/storage.factory.js.map +1 -0
- package/storage-utils.d.ts +1 -0
- package/storage-utils.js +15 -0
- package/storage-utils.js.map +1 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.StorageTestController = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const storage_factory_1 = require("../services/storage.factory");
|
|
15
|
+
const fs = require("fs");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
let StorageTestController = class StorageTestController {
|
|
18
|
+
storageFactory;
|
|
19
|
+
constructor(storageFactory) {
|
|
20
|
+
this.storageFactory = storageFactory;
|
|
21
|
+
}
|
|
22
|
+
async uploadTestFile() {
|
|
23
|
+
const storageService = this.storageFactory.getStorageService('CLOUDFLARE');
|
|
24
|
+
const filePath = path.join(process.cwd(), 'woman1.jpg');
|
|
25
|
+
const fileBuffer = fs.readFileSync(filePath);
|
|
26
|
+
const bucketName = 'polilan-bucket';
|
|
27
|
+
if (!bucketName) {
|
|
28
|
+
throw new Error('STORAGE_BUCKET environment variable not set.');
|
|
29
|
+
}
|
|
30
|
+
return storageService.uploadWebpImage({ bucketName, fileName: 'myfolder/mywoman1-test.jpg', imageBuffer: fileBuffer });
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.StorageTestController = StorageTestController;
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, common_1.Post)('upload'),
|
|
36
|
+
__metadata("design:type", Function),
|
|
37
|
+
__metadata("design:paramtypes", []),
|
|
38
|
+
__metadata("design:returntype", Promise)
|
|
39
|
+
], StorageTestController.prototype, "uploadTestFile", null);
|
|
40
|
+
exports.StorageTestController = StorageTestController = __decorate([
|
|
41
|
+
(0, common_1.Controller)('storage-test'),
|
|
42
|
+
__metadata("design:paramtypes", [storage_factory_1.StorageFactory])
|
|
43
|
+
], StorageTestController);
|
|
44
|
+
//# sourceMappingURL=storage.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.controller.js","sourceRoot":"","sources":["../../../../../libs/nest-storage/src/controllers/storage.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAkD;AAClD,iEAA6D;AAC7D,yBAAyB;AACzB,6BAA6B;AAGtB,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACH;IAA7B,YAA6B,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAAG,CAAC;IAGzD,AAAN,KAAK,CAAC,cAAc;QAClB,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAC3E,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;QACxD,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC7C,MAAM,UAAU,GAAG,gBAAgB,CAAC;QAEpC,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,cAAc,CAAC,eAAe,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,4BAA4B,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;IACzH,CAAC;CACF,CAAA;AAhBY,sDAAqB;AAI1B;IADL,IAAA,aAAI,EAAC,QAAQ,CAAC;;;;2DAYd;gCAfU,qBAAqB;IADjC,IAAA,mBAAU,EAAC,cAAc,CAAC;qCAEoB,gCAAc;GADhD,qBAAqB,CAgBjC"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -18,4 +18,5 @@ __exportStar(require("./nest-storage.module"), exports);
|
|
|
18
18
|
__exportStar(require("./models/cloud.model"), exports);
|
|
19
19
|
__exportStar(require("./services/cloud-storage.service"), exports);
|
|
20
20
|
__exportStar(require("./services/minio-storage.service"), exports);
|
|
21
|
+
__exportStar(require("./services/storage.factory"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nest-storage/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AAEtC,uDAAqC;AAErC,mEAAiD;AACjD,mEAAiD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nest-storage/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AAEtC,uDAAqC;AAErC,mEAAiD;AACjD,mEAAiD;AACjD,6DAA2C"}
|
package/models/cloud.model.d.ts
CHANGED
|
@@ -5,16 +5,44 @@ export interface BasicStorage {
|
|
|
5
5
|
export interface CloudStorage extends BasicStorage {
|
|
6
6
|
path?: string;
|
|
7
7
|
bucket?: string;
|
|
8
|
+
provider?: string;
|
|
8
9
|
}
|
|
9
10
|
export interface AudioStorage extends CloudStorage {
|
|
10
11
|
voice?: string;
|
|
11
12
|
transcription?: any;
|
|
12
13
|
}
|
|
13
|
-
export interface
|
|
14
|
+
export interface FileStorageData extends BasicStorage {
|
|
14
15
|
name?: string;
|
|
15
16
|
size?: number;
|
|
16
17
|
type?: string;
|
|
18
|
+
metadata?: any;
|
|
17
19
|
}
|
|
18
|
-
export interface
|
|
20
|
+
export interface ImgStorageData extends FileStorageData {
|
|
21
|
+
resolution?: string;
|
|
22
|
+
resolutions?: {
|
|
23
|
+
[key: string]: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface ImgGeneratedStorageData extends ImgStorageData {
|
|
27
|
+
model?: string;
|
|
28
|
+
prompt?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CloudFileStorage extends FileStorageData, CloudStorage {
|
|
19
31
|
auditable: IAuditable;
|
|
20
32
|
}
|
|
33
|
+
import { UploadWebpImageOptions } from '../services/cloud-storage.service';
|
|
34
|
+
export interface IStorageService {
|
|
35
|
+
uploadFile(fileName: string, fileBuffer: Buffer, auditable: IAuditable, contentType?: string, bucketName?: string): Promise<CloudFileStorage>;
|
|
36
|
+
uploadWebpImage(options: UploadWebpImageOptions): Promise<Partial<CloudFileStorage>>;
|
|
37
|
+
uploadFileAndMakePublic(bucketName: string, fileName: string, fileBuffer: Buffer, contentType?: string, metadata?: {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}): Promise<Partial<CloudFileStorage>>;
|
|
40
|
+
deleteStorageFile(bucketName: string, fileName: string): Promise<any>;
|
|
41
|
+
removeAllStorageFilesPresentInObject(obj: any): Promise<any>;
|
|
42
|
+
removeAllStorageFilesByUrl(obj: any): Promise<any>;
|
|
43
|
+
extractPath(file: BasicStorage): string | undefined;
|
|
44
|
+
getFile(bucketName: string, fileName: string): Promise<Buffer>;
|
|
45
|
+
generateSignedUrl(bucketName: string, fileName: string, expiresInMinutes?: number): Promise<string>;
|
|
46
|
+
listFiles(bucketName: string, prefix?: string): Promise<any[]>;
|
|
47
|
+
fileExists(bucketName: string, fileName: string): Promise<boolean>;
|
|
48
|
+
}
|
package/nest-storage.module.js
CHANGED
|
@@ -10,13 +10,29 @@ exports.NestStorageModule = void 0;
|
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const cloud_storage_service_1 = require("./services/cloud-storage.service");
|
|
12
12
|
const minio_storage_service_1 = require("./services/minio-storage.service");
|
|
13
|
+
const cloudflare_r2_service_1 = require("./services/cloudflare-r2.service");
|
|
14
|
+
const storage_factory_1 = require("./services/storage.factory");
|
|
15
|
+
const storage_controller_1 = require("./controllers/storage.controller");
|
|
16
|
+
const config_1 = require("@nestjs/config");
|
|
13
17
|
let NestStorageModule = class NestStorageModule {
|
|
14
18
|
};
|
|
15
19
|
exports.NestStorageModule = NestStorageModule;
|
|
16
20
|
exports.NestStorageModule = NestStorageModule = __decorate([
|
|
17
21
|
(0, common_1.Module)({
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
imports: [config_1.ConfigModule],
|
|
23
|
+
controllers: [storage_controller_1.StorageTestController],
|
|
24
|
+
providers: [
|
|
25
|
+
cloud_storage_service_1.CloudStorageService,
|
|
26
|
+
minio_storage_service_1.MinioStorageService,
|
|
27
|
+
cloudflare_r2_service_1.CloudflareR2Service,
|
|
28
|
+
storage_factory_1.StorageFactory,
|
|
29
|
+
{
|
|
30
|
+
provide: 'IStorageService',
|
|
31
|
+
useFactory: (factory) => factory.getStorageService(),
|
|
32
|
+
inject: [storage_factory_1.StorageFactory],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
exports: [cloud_storage_service_1.CloudStorageService, minio_storage_service_1.MinioStorageService, 'IStorageService', storage_factory_1.StorageFactory],
|
|
20
36
|
})
|
|
21
37
|
], NestStorageModule);
|
|
22
38
|
//# sourceMappingURL=nest-storage.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nest-storage.module.js","sourceRoot":"","sources":["../../../../libs/nest-storage/src/nest-storage.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,4EAAuE;AACvE,4EAAuE;
|
|
1
|
+
{"version":3,"file":"nest-storage.module.js","sourceRoot":"","sources":["../../../../libs/nest-storage/src/nest-storage.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,4EAAuE;AACvE,4EAAuE;AACvE,4EAAuE;AACvE,gEAA4D;AAC5D,yEAAyE;AACzE,2CAA8C;AAkBvC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CAAG,CAAA;AAApB,8CAAiB;4BAAjB,iBAAiB;IAhB7B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,qBAAY,CAAC;QACvB,WAAW,EAAE,CAAC,0CAAqB,CAAC;QACpC,SAAS,EAAE;YACT,2CAAmB;YACnB,2CAAmB;YACnB,2CAAmB;YACnB,gCAAc;YACd;gBACE,OAAO,EAAE,iBAAiB;gBAC1B,UAAU,EAAE,CAAC,OAAuB,EAAE,EAAE,CAAC,OAAO,CAAC,iBAAiB,EAAE;gBACpE,MAAM,EAAE,CAAC,gCAAc,CAAC;aACzB;SACF;QACD,OAAO,EAAE,CAAC,2CAAmB,EAAE,2CAAmB,EAAE,iBAAiB,EAAE,gCAAc,CAAC;KACvF,CAAC;GACW,iBAAiB,CAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataclouder/nest-storage",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "NestJS library for storage services",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"@nestjs/core": ">=11.0.0",
|
|
29
29
|
"rxjs": ">=7.0.0"
|
|
30
30
|
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"sharp": ">=0.32.6"
|
|
33
|
+
},
|
|
31
34
|
"publishConfig": {
|
|
32
35
|
"access": "public"
|
|
33
36
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IAuditable } from '@dataclouder/nest-core';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { BasicStorage, CloudFileStorage, IStorageService } from '../models/cloud.model';
|
|
2
4
|
export interface UploadWebpImageOptions {
|
|
3
5
|
bucketName?: string;
|
|
4
6
|
fileName: string;
|
|
@@ -9,10 +11,13 @@ export interface UploadWebpImageOptions {
|
|
|
9
11
|
[key: string]: any;
|
|
10
12
|
};
|
|
11
13
|
}
|
|
12
|
-
export declare class CloudStorageService {
|
|
14
|
+
export declare class CloudStorageService implements IStorageService {
|
|
15
|
+
private readonly configService;
|
|
13
16
|
private storage;
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
private readonly logger;
|
|
18
|
+
private readonly storageBucket;
|
|
19
|
+
constructor(configService: ConfigService);
|
|
20
|
+
uploadFile(fileName: string, fileBuffer: Buffer, auditable: IAuditable, contentType?: string, bucketName?: string): Promise<CloudFileStorage>;
|
|
16
21
|
uploadWebpImage(options: UploadWebpImageOptions): Promise<Partial<CloudFileStorage>>;
|
|
17
22
|
uploadFileAndMakePublic(bucketName: string, fileName: string, fileBuffer: Buffer, contentType?: string, metadata?: {
|
|
18
23
|
[key: string]: any;
|
|
@@ -8,20 +8,31 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var CloudStorageService_1;
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
13
|
exports.CloudStorageService = void 0;
|
|
13
14
|
const common_1 = require("@nestjs/common");
|
|
15
|
+
const config_1 = require("@nestjs/config");
|
|
14
16
|
const storage_1 = require("@google-cloud/storage");
|
|
15
17
|
const sharp = require("sharp");
|
|
16
18
|
const FIREBASE_STORAGE_URL_REGEX = /https:\/\/firebasestorage\.googleapis\.com\/v0\/b\/([^/]+)\/o\/([^?]+)/;
|
|
17
19
|
const GOOGLE_STORAGE_URL_REGEX = /https:\/\/storage\.googleapis\.com\/([^/]+)\/(.+)/;
|
|
18
|
-
let CloudStorageService = class CloudStorageService {
|
|
20
|
+
let CloudStorageService = CloudStorageService_1 = class CloudStorageService {
|
|
21
|
+
configService;
|
|
19
22
|
storage;
|
|
20
|
-
|
|
23
|
+
logger = new common_1.Logger(CloudStorageService_1.name);
|
|
24
|
+
storageBucket;
|
|
25
|
+
constructor(configService) {
|
|
26
|
+
this.configService = configService;
|
|
21
27
|
this.storage = new storage_1.Storage();
|
|
28
|
+
this.storageBucket = this.configService.get('STORAGE_BUCKET');
|
|
22
29
|
}
|
|
23
|
-
async uploadFile(
|
|
24
|
-
const
|
|
30
|
+
async uploadFile(fileName, fileBuffer, auditable, contentType, bucketName) {
|
|
31
|
+
const bucketToUse = bucketName || this.storageBucket;
|
|
32
|
+
if (!bucketToUse) {
|
|
33
|
+
throw new Error('Bucket name must be provided or set in the environment variables.');
|
|
34
|
+
}
|
|
35
|
+
const bucket = this.storage.bucket(bucketToUse);
|
|
25
36
|
const file = bucket.file(fileName);
|
|
26
37
|
const options = contentType ? { contentType } : undefined;
|
|
27
38
|
return new Promise((resolve, reject) => {
|
|
@@ -30,25 +41,33 @@ let CloudStorageService = class CloudStorageService {
|
|
|
30
41
|
reject(err);
|
|
31
42
|
});
|
|
32
43
|
stream.on('finish', async () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
try {
|
|
45
|
+
await file.makePublic();
|
|
46
|
+
this.logger.log(`gs://${bucketToUse}/${fileName} uploaded successfully`);
|
|
47
|
+
resolve({
|
|
48
|
+
url: file.publicUrl(),
|
|
49
|
+
path: file.name,
|
|
50
|
+
bucket: bucketToUse,
|
|
51
|
+
provider: 'google',
|
|
52
|
+
auditable,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
reject(error);
|
|
57
|
+
}
|
|
39
58
|
});
|
|
40
59
|
stream.end(fileBuffer);
|
|
41
60
|
});
|
|
42
61
|
}
|
|
43
62
|
async uploadWebpImage(options) {
|
|
44
|
-
const { bucketName: providedBucketName, fileName, imageBuffer, resizeWidth =
|
|
63
|
+
const { bucketName: providedBucketName, fileName, imageBuffer, resizeWidth = 900, contentType = 'image/webp', metadata, } = options;
|
|
45
64
|
const bucketToUse = providedBucketName || process.env.STORAGE_BUCKET;
|
|
46
65
|
if (!bucketToUse) {
|
|
47
66
|
throw new Error('Bucket name must be provided either in options or as STORAGE_BUCKET environment variable.');
|
|
48
67
|
}
|
|
49
68
|
const webpBuffer = await sharp(imageBuffer)
|
|
50
69
|
.resize(resizeWidth)
|
|
51
|
-
.webp({ quality:
|
|
70
|
+
.webp({ quality: 80 })
|
|
52
71
|
.toBuffer();
|
|
53
72
|
const result = await this.uploadFileAndMakePublic(bucketToUse, fileName, webpBuffer, contentType, metadata);
|
|
54
73
|
return result;
|
|
@@ -67,11 +86,12 @@ let CloudStorageService = class CloudStorageService {
|
|
|
67
86
|
stream.on('finish', async () => {
|
|
68
87
|
try {
|
|
69
88
|
await file.makePublic();
|
|
70
|
-
|
|
89
|
+
this.logger.log(`gs://${bucketName}/${fileName} uploaded and made public`);
|
|
71
90
|
resolve({
|
|
72
91
|
bucket: bucketName,
|
|
73
92
|
path: file.name,
|
|
74
93
|
url: file.publicUrl(),
|
|
94
|
+
provider: 'google',
|
|
75
95
|
});
|
|
76
96
|
}
|
|
77
97
|
catch (makePublicError) {
|
|
@@ -83,33 +103,33 @@ let CloudStorageService = class CloudStorageService {
|
|
|
83
103
|
}
|
|
84
104
|
async deleteStorageFile(bucketName, fileName) {
|
|
85
105
|
const _results = await this.storage.bucket(bucketName).file(fileName).delete();
|
|
86
|
-
|
|
106
|
+
this.logger.log(`gs://${bucketName}/${fileName} deleted`);
|
|
87
107
|
return _results;
|
|
88
108
|
}
|
|
89
109
|
async removeAllStorageFilesPresentInObject(obj) {
|
|
90
110
|
const pathsObjects = this.findAllObjectsWithPaths(obj);
|
|
91
|
-
|
|
111
|
+
this.logger.log('Removing items from storage: ', pathsObjects.length);
|
|
92
112
|
const promises = pathsObjects.map((obj) => this.deleteStorageFile(obj.bucket, obj.path));
|
|
93
113
|
try {
|
|
94
114
|
return await Promise.all(promises);
|
|
95
115
|
}
|
|
96
116
|
catch (error) {
|
|
97
|
-
|
|
117
|
+
this.logger.error('Error removing items from storage: ', error);
|
|
98
118
|
return null;
|
|
99
119
|
}
|
|
100
120
|
}
|
|
101
121
|
async removeAllStorageFilesByUrl(obj) {
|
|
102
122
|
const urlObjects = this.findAllObjectsWithUrls(obj);
|
|
103
|
-
|
|
123
|
+
this.logger.log(`Removing ${urlObjects.length} items from storage by URL`);
|
|
104
124
|
const promises = urlObjects
|
|
105
125
|
.map((obj) => {
|
|
106
126
|
const extracted = this.extractBucketAndPathFromUrl(obj.url);
|
|
107
127
|
if (extracted) {
|
|
108
|
-
|
|
128
|
+
this.logger.log(`Deleting ${extracted.bucket}/${extracted.path}...`);
|
|
109
129
|
return this.deleteStorageFile(extracted.bucket, extracted.path);
|
|
110
130
|
}
|
|
111
131
|
else {
|
|
112
|
-
|
|
132
|
+
this.logger.warn(`❌ Check URL format posible bug: Failed to extract bucket and path from URL: ${obj.url}`);
|
|
113
133
|
}
|
|
114
134
|
return null;
|
|
115
135
|
})
|
|
@@ -118,7 +138,7 @@ let CloudStorageService = class CloudStorageService {
|
|
|
118
138
|
return await Promise.all(promises);
|
|
119
139
|
}
|
|
120
140
|
catch (error) {
|
|
121
|
-
|
|
141
|
+
this.logger.error('Error removing items from storage by URL: ', error);
|
|
122
142
|
return null;
|
|
123
143
|
}
|
|
124
144
|
}
|
|
@@ -133,7 +153,7 @@ let CloudStorageService = class CloudStorageService {
|
|
|
133
153
|
return { bucket, path };
|
|
134
154
|
}
|
|
135
155
|
catch (e) {
|
|
136
|
-
|
|
156
|
+
this.logger.error(`Failed to decode URI component for path: '${match[2]}'`, e);
|
|
137
157
|
return { bucket: match[1], path: match[2] };
|
|
138
158
|
}
|
|
139
159
|
}
|
|
@@ -193,7 +213,7 @@ let CloudStorageService = class CloudStorageService {
|
|
|
193
213
|
return decodeURIComponent(match[2]);
|
|
194
214
|
}
|
|
195
215
|
catch (e) {
|
|
196
|
-
|
|
216
|
+
this.logger.error(`Failed to decode URI component for path: '${match[2]}'`, e);
|
|
197
217
|
return match[2];
|
|
198
218
|
}
|
|
199
219
|
}
|
|
@@ -235,8 +255,8 @@ let CloudStorageService = class CloudStorageService {
|
|
|
235
255
|
}
|
|
236
256
|
};
|
|
237
257
|
exports.CloudStorageService = CloudStorageService;
|
|
238
|
-
exports.CloudStorageService = CloudStorageService = __decorate([
|
|
258
|
+
exports.CloudStorageService = CloudStorageService = CloudStorageService_1 = __decorate([
|
|
239
259
|
(0, common_1.Injectable)(),
|
|
240
|
-
__metadata("design:paramtypes", [])
|
|
260
|
+
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
241
261
|
], CloudStorageService);
|
|
242
262
|
//# sourceMappingURL=cloud-storage.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud-storage.service.js","sourceRoot":"","sources":["../../../../../libs/nest-storage/src/services/cloud-storage.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cloud-storage.service.js","sourceRoot":"","sources":["../../../../../libs/nest-storage/src/services/cloud-storage.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,2CAAoD;AACpD,2CAA+C;AAC/C,mDAAgD;AAChD,+BAA+B;AAY/B,MAAM,0BAA0B,GAAG,wEAAwE,CAAC;AAC5G,MAAM,wBAAwB,GAAG,mDAAmD,CAAC;AAG9E,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAKD;IAJrB,OAAO,CAAU;IACR,MAAM,GAAG,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;IAC9C,aAAa,CAAS;IAEvC,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QACvD,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,gBAAgB,CAAC,CAAC;IACxE,CAAC;IAUM,KAAK,CAAC,UAAU,CACrB,QAAgB,EAChB,UAAkB,EAClB,SAAqB,EACrB,WAAoB,EACpB,UAAmB;QAEnB,MAAM,WAAW,GAAG,UAAU,IAAI,IAAI,CAAC,aAAa,CAAC;QACrD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;QACvF,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAChD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEnC,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,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,0 +1,27 @@
|
|
|
1
|
+
import { IAuditable } from '@dataclouder/nest-core';
|
|
2
|
+
import { IStorageService, BasicStorage, CloudFileStorage } from '../models/cloud.model';
|
|
3
|
+
import { UploadWebpImageOptions } from './cloud-storage.service';
|
|
4
|
+
import { ConfigService } from '@nestjs/config';
|
|
5
|
+
export declare class CloudflareR2Service implements IStorageService {
|
|
6
|
+
private readonly configService;
|
|
7
|
+
private s3Client;
|
|
8
|
+
private r2PublicDomain;
|
|
9
|
+
private storageBucket;
|
|
10
|
+
private logger;
|
|
11
|
+
constructor(configService: ConfigService);
|
|
12
|
+
uploadFile(fileName: string, fileBuffer: Buffer, auditable: IAuditable, contentType?: string, bucketName?: string): Promise<CloudFileStorage>;
|
|
13
|
+
uploadWebpImage(options: UploadWebpImageOptions): Promise<Partial<CloudFileStorage>>;
|
|
14
|
+
uploadFileAndMakePublic(bucketName: string, fileName: string, fileBuffer: Buffer, contentType?: string, metadata?: {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}): Promise<Partial<CloudFileStorage>>;
|
|
17
|
+
deleteStorageFile(bucketName: string, fileName: string): Promise<any>;
|
|
18
|
+
removeAllStorageFilesPresentInObject(_obj: any): Promise<any>;
|
|
19
|
+
removeAllStorageFilesByUrl(obj: any): Promise<any>;
|
|
20
|
+
private extractBucketAndPathFromUrl;
|
|
21
|
+
private findAllObjectsWithUrls;
|
|
22
|
+
extractPath(file: BasicStorage): string | undefined;
|
|
23
|
+
getFile(bucketName: string, fileName: string): Promise<Buffer>;
|
|
24
|
+
generateSignedUrl(bucketName: string, fileName: string, expiresInMinutes?: number): Promise<string>;
|
|
25
|
+
listFiles(bucketName: string, prefix?: string): Promise<any[]>;
|
|
26
|
+
fileExists(bucketName: string, fileName: string): Promise<boolean>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var CloudflareR2Service_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.CloudflareR2Service = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
16
|
+
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
17
|
+
const sharp = require("sharp");
|
|
18
|
+
const config_1 = require("@nestjs/config");
|
|
19
|
+
const storage_utils_1 = require("../storage-utils");
|
|
20
|
+
let CloudflareR2Service = CloudflareR2Service_1 = class CloudflareR2Service {
|
|
21
|
+
configService;
|
|
22
|
+
s3Client;
|
|
23
|
+
r2PublicDomain;
|
|
24
|
+
storageBucket;
|
|
25
|
+
logger = new common_1.Logger(CloudflareR2Service_1.name);
|
|
26
|
+
constructor(configService) {
|
|
27
|
+
this.configService = configService;
|
|
28
|
+
const accountId = this.configService.get('R2_ACCOUNT_ID');
|
|
29
|
+
const accessKeyId = this.configService.get('R2_ACCESS_KEY_ID');
|
|
30
|
+
const secretAccessKey = this.configService.get('R2_SECRET_ACCESS_KEY');
|
|
31
|
+
this.r2PublicDomain = this.configService.get('R2_PUBLIC_DOMAIN');
|
|
32
|
+
this.storageBucket = this.configService.get('R2_BUCKET_NAME');
|
|
33
|
+
this.logger.log('Cloudflare R2 Config:', {
|
|
34
|
+
accountId,
|
|
35
|
+
accessKeyId,
|
|
36
|
+
secretAccessKey: secretAccessKey ? 'Loaded' : 'Not Loaded',
|
|
37
|
+
r2PublicDomain: this.r2PublicDomain,
|
|
38
|
+
storageBucket: this.storageBucket,
|
|
39
|
+
endpoint: `https://${accountId}.r2.cloudflarestorage.com`,
|
|
40
|
+
});
|
|
41
|
+
this.s3Client = new client_s3_1.S3Client({
|
|
42
|
+
region: 'auto',
|
|
43
|
+
endpoint: `https://${accountId}.r2.cloudflarestorage.com`,
|
|
44
|
+
credentials: {
|
|
45
|
+
accessKeyId,
|
|
46
|
+
secretAccessKey,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async uploadFile(fileName, fileBuffer, auditable, contentType, bucketName) {
|
|
51
|
+
const bucketToUse = bucketName || this.storageBucket;
|
|
52
|
+
if (!bucketToUse) {
|
|
53
|
+
throw new Error('Bucket name must be provided or set in the environment variables.');
|
|
54
|
+
}
|
|
55
|
+
const sanitizedFileName = (0, storage_utils_1.sanitizeFilename)(fileName);
|
|
56
|
+
const command = new client_s3_1.PutObjectCommand({
|
|
57
|
+
Bucket: bucketToUse,
|
|
58
|
+
Key: sanitizedFileName,
|
|
59
|
+
Body: fileBuffer,
|
|
60
|
+
ContentType: contentType,
|
|
61
|
+
});
|
|
62
|
+
await this.s3Client.send(command);
|
|
63
|
+
const host = this.configService.get('R2_PUBLIC_DOMAIN');
|
|
64
|
+
const publicUrl = `${host}/${sanitizedFileName}`;
|
|
65
|
+
return {
|
|
66
|
+
url: publicUrl,
|
|
67
|
+
path: sanitizedFileName,
|
|
68
|
+
bucket: bucketToUse,
|
|
69
|
+
provider: 'cloudflare',
|
|
70
|
+
auditable,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async uploadWebpImage(options) {
|
|
74
|
+
const { fileName, imageBuffer, resizeWidth = 900, contentType = 'image/webp', metadata } = options;
|
|
75
|
+
const bucketToUse = process.env.R2_BUCKET_NAME;
|
|
76
|
+
if (!bucketToUse) {
|
|
77
|
+
throw new Error('Bucket name must be provided either in options or as R2_BUCKET_NAME environment variable.');
|
|
78
|
+
}
|
|
79
|
+
const nameWithoutExtension = fileName.split('.').slice(0, -1).join('.');
|
|
80
|
+
const webpFileName = `${nameWithoutExtension}.webp`;
|
|
81
|
+
const webpBuffer = await sharp(imageBuffer).resize(resizeWidth).webp({ quality: 85 }).toBuffer();
|
|
82
|
+
return this.uploadFileAndMakePublic(bucketToUse, webpFileName, webpBuffer, contentType, metadata);
|
|
83
|
+
}
|
|
84
|
+
async uploadFileAndMakePublic(bucketName, fileName, fileBuffer, contentType, metadata) {
|
|
85
|
+
const command = new client_s3_1.PutObjectCommand({
|
|
86
|
+
Bucket: bucketName,
|
|
87
|
+
Key: fileName,
|
|
88
|
+
Body: fileBuffer,
|
|
89
|
+
ContentType: contentType,
|
|
90
|
+
Metadata: metadata,
|
|
91
|
+
});
|
|
92
|
+
const response = await this.s3Client.send(command);
|
|
93
|
+
this.logger.log('Upload response:', response);
|
|
94
|
+
const publicUrl = `${this.r2PublicDomain}/${fileName}`;
|
|
95
|
+
return {
|
|
96
|
+
bucket: bucketName,
|
|
97
|
+
path: fileName,
|
|
98
|
+
url: publicUrl,
|
|
99
|
+
provider: 'cloudflare',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async deleteStorageFile(bucketName, fileName) {
|
|
103
|
+
const command = new client_s3_1.DeleteObjectCommand({
|
|
104
|
+
Bucket: bucketName,
|
|
105
|
+
Key: fileName,
|
|
106
|
+
});
|
|
107
|
+
return this.s3Client.send(command);
|
|
108
|
+
}
|
|
109
|
+
async removeAllStorageFilesPresentInObject(_obj) {
|
|
110
|
+
console.warn('removeAllStorageFilesPresentInObject for R2 might need a custom implementation based on your object structure.');
|
|
111
|
+
return Promise.resolve();
|
|
112
|
+
}
|
|
113
|
+
async removeAllStorageFilesByUrl(obj) {
|
|
114
|
+
const urlObjects = this.findAllObjectsWithUrls(obj);
|
|
115
|
+
const promises = urlObjects
|
|
116
|
+
.map((obj) => {
|
|
117
|
+
const extracted = this.extractBucketAndPathFromUrl(obj.url);
|
|
118
|
+
if (extracted) {
|
|
119
|
+
return this.deleteStorageFile(extracted.bucket, extracted.path);
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
})
|
|
123
|
+
.filter((p) => p !== null);
|
|
124
|
+
return Promise.all(promises);
|
|
125
|
+
}
|
|
126
|
+
extractBucketAndPathFromUrl(url) {
|
|
127
|
+
try {
|
|
128
|
+
const urlObject = new URL(url);
|
|
129
|
+
const bucket = this.storageBucket;
|
|
130
|
+
const path = urlObject.pathname.substring(1);
|
|
131
|
+
if (bucket && path) {
|
|
132
|
+
return { bucket, path };
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error(`Invalid URL: ${url}`, error);
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
findAllObjectsWithUrls(obj) {
|
|
142
|
+
if (!obj)
|
|
143
|
+
return [];
|
|
144
|
+
const objectsWithUrls = [];
|
|
145
|
+
const search = (current) => {
|
|
146
|
+
if (!current || typeof current !== 'object')
|
|
147
|
+
return;
|
|
148
|
+
if (current.url && typeof current.url === 'string') {
|
|
149
|
+
objectsWithUrls.push(current);
|
|
150
|
+
}
|
|
151
|
+
if (Array.isArray(current)) {
|
|
152
|
+
current.forEach((item) => search(item));
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
Object.values(current).forEach((value) => search(value));
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
search(obj);
|
|
159
|
+
return objectsWithUrls;
|
|
160
|
+
}
|
|
161
|
+
extractPath(file) {
|
|
162
|
+
if (file && file.url) {
|
|
163
|
+
try {
|
|
164
|
+
const url = new URL(file.url);
|
|
165
|
+
return url.pathname.substring(1);
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
console.error(`Failed to parse URL: '${file.url}'`, e);
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
async getFile(bucketName, fileName) {
|
|
175
|
+
const command = new client_s3_1.GetObjectCommand({
|
|
176
|
+
Bucket: bucketName,
|
|
177
|
+
Key: fileName,
|
|
178
|
+
});
|
|
179
|
+
const response = await this.s3Client.send(command);
|
|
180
|
+
return Buffer.from(await response.Body.transformToByteArray());
|
|
181
|
+
}
|
|
182
|
+
async generateSignedUrl(bucketName, fileName, expiresInMinutes = 15) {
|
|
183
|
+
const command = new client_s3_1.GetObjectCommand({
|
|
184
|
+
Bucket: bucketName,
|
|
185
|
+
Key: fileName,
|
|
186
|
+
});
|
|
187
|
+
return (0, s3_request_presigner_1.getSignedUrl)(this.s3Client, command, { expiresIn: expiresInMinutes * 60 });
|
|
188
|
+
}
|
|
189
|
+
async listFiles(bucketName, prefix) {
|
|
190
|
+
const command = new client_s3_1.ListObjectsV2Command({
|
|
191
|
+
Bucket: bucketName,
|
|
192
|
+
Prefix: prefix,
|
|
193
|
+
});
|
|
194
|
+
const response = await this.s3Client.send(command);
|
|
195
|
+
return response.Contents.map((file) => ({
|
|
196
|
+
name: file.Key,
|
|
197
|
+
size: file.Size,
|
|
198
|
+
updated: file.LastModified,
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
async fileExists(bucketName, fileName) {
|
|
202
|
+
try {
|
|
203
|
+
const command = new client_s3_1.HeadObjectCommand({
|
|
204
|
+
Bucket: bucketName,
|
|
205
|
+
Key: fileName,
|
|
206
|
+
});
|
|
207
|
+
await this.s3Client.send(command);
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
if (error.name === 'NotFound') {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
exports.CloudflareR2Service = CloudflareR2Service;
|
|
219
|
+
exports.CloudflareR2Service = CloudflareR2Service = CloudflareR2Service_1 = __decorate([
|
|
220
|
+
(0, common_1.Injectable)(),
|
|
221
|
+
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
222
|
+
], CloudflareR2Service);
|
|
223
|
+
//# sourceMappingURL=cloudflare-r2.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare-r2.service.js","sourceRoot":"","sources":["../../../../../libs/nest-storage/src/services/cloudflare-r2.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,2CAAoD;AACpD,kDAAgJ;AAChJ,wEAA6D;AAC7D,+BAA+B;AAG/B,2CAA+C;AAC/C,oDAAoD;AAG7C,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAMD;IALrB,QAAQ,CAAW;IACnB,cAAc,CAAS;IACvB,aAAa,CAAS;IACtB,MAAM,GAAG,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;IAEtD,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QACvD,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,eAAe,CAAC,CAAC;QAClE,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,kBAAkB,CAAC,CAAC;QACvE,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,sBAAsB,CAAC,CAAC;QAC/E,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,kBAAkB,CAAC,CAAC;QACzE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,gBAAgB,CAAC,CAAC;QAEtE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,uBAAuB,EAAE;YACvC,SAAS;YACT,WAAW;YACX,eAAe,EAAE,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CAAoB,CAAC;YACvC,MAAM,EAAE,UAAU;YAClB,MAAM,EAAE,MAAM;SACf,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnD,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACtC,IAAI,EAAE,IAAI,CAAC,GAAG;YACd,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,YAAY;SAC3B,CAAC,CAAC,CAAC;IACN,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,UAAkB,EAAE,QAAgB;QAC1D,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAI,6BAAiB,CAAC;gBACpC,MAAM,EAAE,UAAU;gBAClB,GAAG,EAAE,QAAQ;aACd,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBAC9B,OAAO,KAAK,CAAC;YACf,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAA;AA1OY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAOiC,sBAAa;GAN9C,mBAAmB,CA0O/B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CloudStorageService } from './cloud-storage.service';
|
|
2
|
+
import { CloudflareR2Service } from './cloudflare-r2.service';
|
|
3
|
+
import { IStorageService } from '../models/cloud.model';
|
|
4
|
+
export declare class StorageFactory {
|
|
5
|
+
private readonly googleCloudStorageService;
|
|
6
|
+
private readonly cloudflareR2Service;
|
|
7
|
+
constructor(googleCloudStorageService: CloudStorageService, cloudflareR2Service: CloudflareR2Service);
|
|
8
|
+
getStorageService(provider?: string): IStorageService;
|
|
9
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.StorageFactory = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const cloud_storage_service_1 = require("./cloud-storage.service");
|
|
15
|
+
const cloudflare_r2_service_1 = require("./cloudflare-r2.service");
|
|
16
|
+
let StorageFactory = class StorageFactory {
|
|
17
|
+
googleCloudStorageService;
|
|
18
|
+
cloudflareR2Service;
|
|
19
|
+
constructor(googleCloudStorageService, cloudflareR2Service) {
|
|
20
|
+
this.googleCloudStorageService = googleCloudStorageService;
|
|
21
|
+
this.cloudflareR2Service = cloudflareR2Service;
|
|
22
|
+
}
|
|
23
|
+
getStorageService(provider) {
|
|
24
|
+
if (provider === 'CLOUDFLARE') {
|
|
25
|
+
return this.cloudflareR2Service;
|
|
26
|
+
}
|
|
27
|
+
if (provider === 'GOOGLE') {
|
|
28
|
+
return this.googleCloudStorageService;
|
|
29
|
+
}
|
|
30
|
+
return this.googleCloudStorageService;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.StorageFactory = StorageFactory;
|
|
34
|
+
exports.StorageFactory = StorageFactory = __decorate([
|
|
35
|
+
(0, common_1.Injectable)(),
|
|
36
|
+
__metadata("design:paramtypes", [cloud_storage_service_1.CloudStorageService,
|
|
37
|
+
cloudflare_r2_service_1.CloudflareR2Service])
|
|
38
|
+
], StorageFactory);
|
|
39
|
+
//# sourceMappingURL=storage.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.factory.js","sourceRoot":"","sources":["../../../../../libs/nest-storage/src/services/storage.factory.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,mEAA8D;AAC9D,mEAA8D;AAIvD,IAAM,cAAc,GAApB,MAAM,cAAc;IAEN;IACA;IAFnB,YACmB,yBAA8C,EAC9C,mBAAwC;QADxC,8BAAyB,GAAzB,yBAAyB,CAAqB;QAC9C,wBAAmB,GAAnB,mBAAmB,CAAqB;IACxD,CAAC;IAEG,iBAAiB,CAAC,QAAiB;QACxC,IAAI,QAAQ,KAAK,YAAY,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,mBAAmB,CAAC;QAClC,CAAC;QACD,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,yBAAyB,CAAC;QACxC,CAAC;QAED,OAAO,IAAI,CAAC,yBAAyB,CAAC;IACxC,CAAC;CACF,CAAA;AAhBY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAGmC,2CAAmB;QACzB,2CAAmB;GAHhD,cAAc,CAgB1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sanitizeFilename: (filename: string) => string;
|
package/storage-utils.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitizeFilename = void 0;
|
|
4
|
+
const sanitizeFilename = (filename) => {
|
|
5
|
+
if (!filename) {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
const parts = filename.split('/');
|
|
9
|
+
const lastPart = parts.pop() || '';
|
|
10
|
+
const sanitizedLastPart = lastPart.replace(/ /g, '_').replace(/[^a-zA-Z0-9._-]/g, '');
|
|
11
|
+
parts.push(sanitizedLastPart);
|
|
12
|
+
return parts.join('/');
|
|
13
|
+
};
|
|
14
|
+
exports.sanitizeFilename = sanitizeFilename;
|
|
15
|
+
//# sourceMappingURL=storage-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-utils.js","sourceRoot":"","sources":["../../../../libs/nest-storage/src/storage-utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC3D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;IAEnC,MAAM,iBAAiB,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;IAEtF,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAE9B,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC,CAAC;AAbW,QAAA,gBAAgB,oBAa3B"}
|