pangea-server 3.3.55 → 3.3.56
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.
|
@@ -15,6 +15,8 @@ export declare abstract class FileStorage {
|
|
|
15
15
|
url: string;
|
|
16
16
|
fileName: string;
|
|
17
17
|
}[]>;
|
|
18
|
+
static GenerateDownloadUrl(fileName: string): Promise<string>;
|
|
19
|
+
static GenerateDownloadUrls(fileNames: string[]): Promise<string[]>;
|
|
18
20
|
static DeleteFile(fileName: string): Promise<void>;
|
|
19
21
|
static DeleteFiles(fileNames: string[]): Promise<void[]>;
|
|
20
22
|
}
|
|
@@ -19,6 +19,7 @@ const s3 = new aws_sdk_1.default.S3({
|
|
|
19
19
|
accessKeyId: (0, env_helpers_1.getEnvStr)('DIGITAL_OCEAN_SPACES_ACCESS_KEY'),
|
|
20
20
|
secretAccessKey: (0, env_helpers_1.getEnvStr)('DIGITAL_OCEAN_SPACES_SECRET_KEY'),
|
|
21
21
|
});
|
|
22
|
+
const expiresTime = 60;
|
|
22
23
|
class FileStorage {
|
|
23
24
|
static async UploadImage(image, folder, previousFile) {
|
|
24
25
|
if (previousFile)
|
|
@@ -44,13 +45,19 @@ class FileStorage {
|
|
|
44
45
|
return Promise.all(files.map((file) => this.UploadVideo(file, folder)));
|
|
45
46
|
}
|
|
46
47
|
static async GenerateUploadUrl(config) {
|
|
47
|
-
const params = { ...getGeneralUploadParams(config), Expires:
|
|
48
|
+
const params = { ...getGeneralUploadParams(config), Expires: expiresTime };
|
|
48
49
|
const url = await s3.getSignedUrlPromise('putObject', params);
|
|
49
50
|
return { url, fileName: params.Key };
|
|
50
51
|
}
|
|
51
|
-
static
|
|
52
|
+
static GenerateUploadUrls(folder, fileTypes) {
|
|
52
53
|
return Promise.all(fileTypes.map((fileType) => this.GenerateUploadUrl({ folder, fileType })));
|
|
53
54
|
}
|
|
55
|
+
static GenerateDownloadUrl(fileName) {
|
|
56
|
+
return s3.getSignedUrlPromise('getObject', { Bucket: bucketName, Key: fileName, Expires: expiresTime });
|
|
57
|
+
}
|
|
58
|
+
static GenerateDownloadUrls(fileNames) {
|
|
59
|
+
return Promise.all(fileNames.map((fileName) => this.GenerateDownloadUrl(fileName)));
|
|
60
|
+
}
|
|
54
61
|
static async DeleteFile(fileName) {
|
|
55
62
|
await s3.deleteObject({ Bucket: bucketName, Key: fileName }).promise();
|
|
56
63
|
(0, print_helpers_1.printInfo)('file', `file deleted from ${fileName}`);
|
|
@@ -63,7 +70,7 @@ exports.FileStorage = FileStorage;
|
|
|
63
70
|
// internal functions
|
|
64
71
|
function getGeneralUploadParams(config) {
|
|
65
72
|
const fileName = `${config.folder}/${(0, random_helpers_1.getRandomString)('short')}`;
|
|
66
|
-
return { Bucket: bucketName, Key: fileName, ContentType: config.fileType, ACL: '
|
|
73
|
+
return { Bucket: bucketName, Key: fileName, ContentType: config.fileType, ACL: 'private' };
|
|
67
74
|
}
|
|
68
75
|
async function uploadFile(body, config) {
|
|
69
76
|
const params = { ...getGeneralUploadParams(config), Body: body };
|