@programisto/edrm-storage 1.0.2 → 1.0.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.
- package/dist/bin/www.js +1 -1
- package/dist/modules/edrm-storage/models/file.model.d.ts +1 -1
- package/dist/modules/edrm-storage/models/file.model.js +1 -1
- package/dist/modules/edrm-storage/providers/s3-storage.provider.d.ts +6 -0
- package/dist/modules/edrm-storage/providers/s3-storage.provider.js +24 -1
- package/dist/modules/edrm-storage/routes/edrm-storage.router.d.ts +1 -1
- package/dist/modules/edrm-storage/routes/edrm-storage.router.js +1 -1
- package/dist/modules/edrm-storage/services/edrm-storage.service.js +1 -1
- package/package.json +2 -2
package/dist/bin/www.js
CHANGED
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
/* eslint-disable @typescript-eslint/no-unused-vars, no-use-before-define */
|
|
11
|
-
import { EnduranceSchema, EnduranceModelType } from '@programisto/endurance
|
|
11
|
+
import { EnduranceSchema, EnduranceModelType } from '@programisto/endurance';
|
|
12
12
|
// Enums pour les statuts de fichiers
|
|
13
13
|
export var FileStatus;
|
|
14
14
|
(function (FileStatus) {
|
|
@@ -7,6 +7,12 @@ export declare class S3StorageProvider implements StorageProvider {
|
|
|
7
7
|
constructor(region: string, accessKeyId?: string, secretAccessKey?: string);
|
|
8
8
|
initUpload(bucket: string, key: string, contentType: string, expiresIn?: number): Promise<UploadInitResponse>;
|
|
9
9
|
getFileMetadata(bucket: string, key: string): Promise<FileMetadata>;
|
|
10
|
+
/**
|
|
11
|
+
* Encode un nom de fichier pour l'en-tête Content-Disposition selon RFC 6266
|
|
12
|
+
* Gère les caractères spéciaux (accents, etc.) en utilisant l'encodage UTF-8
|
|
13
|
+
* AWS S3 nécessite un encodage strict pour éviter l'erreur "Header value cannot be represented using ISO-8859-1"
|
|
14
|
+
*/
|
|
15
|
+
private encodeContentDispositionFilename;
|
|
10
16
|
getDownloadUrl(bucket: string, key: string, filename?: string, expiresIn?: number): Promise<DownloadUrlResponse>;
|
|
11
17
|
deleteFile(bucket: string, key: string): Promise<void>;
|
|
12
18
|
copyFile(sourceBucket: string, sourceKey: string, destBucket: string, destKey: string): Promise<void>;
|
|
@@ -48,11 +48,34 @@ export class S3StorageProvider {
|
|
|
48
48
|
metadata: response.Metadata
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Encode un nom de fichier pour l'en-tête Content-Disposition selon RFC 6266
|
|
53
|
+
* Gère les caractères spéciaux (accents, etc.) en utilisant l'encodage UTF-8
|
|
54
|
+
* AWS S3 nécessite un encodage strict pour éviter l'erreur "Header value cannot be represented using ISO-8859-1"
|
|
55
|
+
*/
|
|
56
|
+
encodeContentDispositionFilename(filename) {
|
|
57
|
+
// Vérifier si le nom de fichier contient des caractères non-ASCII
|
|
58
|
+
const hasNonAscii = /[^\x20-\x7E]/.test(filename);
|
|
59
|
+
if (hasNonAscii) {
|
|
60
|
+
// Pour les noms avec caractères non-ASCII, utiliser uniquement filename* avec UTF-8
|
|
61
|
+
// Cela évite les problèmes avec S3 qui rejette les caractères non-ASCII dans filename
|
|
62
|
+
const encodedFilename = encodeURIComponent(filename)
|
|
63
|
+
.replace(/'/g, '%27')
|
|
64
|
+
.replace(/\(/g, '%28')
|
|
65
|
+
.replace(/\)/g, '%29');
|
|
66
|
+
// Format RFC 6266 : utiliser uniquement filename* pour éviter les erreurs S3
|
|
67
|
+
return `attachment; filename*=UTF-8''${encodedFilename}`;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Pour les noms ASCII uniquement, utiliser le format simple
|
|
71
|
+
return `attachment; filename="${filename}"`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
51
74
|
async getDownloadUrl(bucket, key, filename, expiresIn = 3600) {
|
|
52
75
|
const command = new GetObjectCommand({
|
|
53
76
|
Bucket: bucket,
|
|
54
77
|
Key: key,
|
|
55
|
-
ResponseContentDisposition: filename ?
|
|
78
|
+
ResponseContentDisposition: filename ? this.encodeContentDispositionFilename(filename) : undefined
|
|
56
79
|
});
|
|
57
80
|
const url = await getSignedUrl(this.client, command, {
|
|
58
81
|
expiresIn
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { enduranceEmitter, enduranceEventTypes } from '@programisto/endurance
|
|
1
|
+
import { enduranceEmitter, enduranceEventTypes } from '@programisto/endurance';
|
|
2
2
|
import FileModel, { FileStatus, FileProvider, FileType } from '../models/file.model.js';
|
|
3
3
|
import { S3StorageProvider } from '../providers/s3-storage.provider.js';
|
|
4
4
|
import crypto from 'crypto';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@programisto/edrm-storage",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.4",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@aws-sdk/client-s3": "^3.879.0",
|
|
21
21
|
"@aws-sdk/s3-request-presigner": "^3.879.0",
|
|
22
|
-
"@programisto/endurance
|
|
22
|
+
"@programisto/endurance": "^1.0.2",
|
|
23
23
|
"aws-sdk": "^2.1692.0",
|
|
24
24
|
"debug": "^4.3.7",
|
|
25
25
|
"fs": "^0.0.1-security",
|