proteum 1.0.2 → 2.0.0-1
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/AGENTS.md +101 -0
- package/agents/codex/AGENTS.md +95 -0
- package/agents/codex/CODING_STYLE.md +71 -0
- package/agents/codex/agents.md.zip +0 -0
- package/agents/codex/client/AGENTS.md +102 -0
- package/agents/codex/client/pages/AGENTS.md +35 -0
- package/agents/codex/server/routes/AGENTS.md +12 -0
- package/agents/codex/server/services/AGENTS.md +137 -0
- package/agents/codex/tests/AGENTS.md +8 -0
- package/cli/app/config.ts +13 -11
- package/cli/app/index.ts +74 -82
- package/cli/bin.js +1 -1
- package/cli/commands/build.ts +51 -14
- package/cli/commands/check.ts +19 -0
- package/cli/commands/deploy/app.ts +4 -8
- package/cli/commands/deploy/web.ts +16 -20
- package/cli/commands/dev.ts +189 -64
- package/cli/commands/devEvents.ts +106 -0
- package/cli/commands/init.ts +63 -57
- package/cli/commands/lint.ts +21 -0
- package/cli/commands/refresh.ts +18 -0
- package/cli/commands/typecheck.ts +18 -0
- package/cli/compiler/client/identite.ts +80 -53
- package/cli/compiler/client/index.ts +139 -213
- package/cli/compiler/common/bundleAnalysis.ts +94 -0
- package/cli/compiler/common/clientManifest.ts +67 -0
- package/cli/compiler/common/controllers.ts +288 -0
- package/cli/compiler/common/files/autres.ts +7 -18
- package/cli/compiler/common/files/images.ts +40 -37
- package/cli/compiler/common/files/style.ts +11 -22
- package/cli/compiler/common/generatedRouteModules.ts +368 -0
- package/cli/compiler/common/index.ts +31 -65
- package/cli/compiler/common/loaders/forbid-ssr-import.js +13 -0
- package/cli/compiler/common/rspackAliases.ts +13 -0
- package/cli/compiler/common/scripts.ts +37 -0
- package/cli/compiler/index.ts +781 -230
- package/cli/compiler/server/index.ts +59 -75
- package/cli/compiler/writeIfChanged.ts +21 -0
- package/cli/index.ts +71 -72
- package/cli/paths.ts +51 -57
- package/cli/print.ts +17 -11
- package/cli/tsconfig.json +5 -4
- package/cli/utils/agents.ts +100 -0
- package/cli/utils/check.ts +71 -0
- package/cli/utils/index.ts +1 -3
- package/cli/utils/keyboard.ts +8 -25
- package/cli/utils/runProcess.ts +30 -0
- package/client/app/component.tsx +29 -29
- package/client/app/index.ts +36 -57
- package/client/app/service.ts +7 -12
- package/client/app.tsconfig.json +2 -2
- package/client/components/Dialog/Manager.ssr.tsx +40 -0
- package/client/components/Dialog/Manager.tsx +119 -150
- package/client/components/Dialog/status.tsx +3 -3
- package/client/components/index.ts +1 -1
- package/client/components/types.d.ts +1 -3
- package/client/dev/hmr.ts +65 -0
- package/client/global.d.ts +2 -2
- package/client/hooks.ts +6 -9
- package/client/index.ts +2 -1
- package/client/islands/index.ts +7 -0
- package/client/islands/useDeferredModule.ts +199 -0
- package/client/pages/_layout/index.tsx +4 -12
- package/client/pages/useHeader.tsx +14 -21
- package/client/router.ts +27 -0
- package/client/services/router/components/Link.tsx +34 -27
- package/client/services/router/components/Page.tsx +6 -14
- package/client/services/router/components/router.ssr.tsx +36 -0
- package/client/services/router/components/router.tsx +63 -83
- package/client/services/router/index.tsx +185 -220
- package/client/services/router/request/api.ts +97 -119
- package/client/services/router/request/history.ts +2 -2
- package/client/services/router/request/index.ts +13 -12
- package/client/services/router/request/multipart.ts +72 -62
- package/client/services/router/response/index.tsx +68 -61
- package/client/services/router/response/page.ts +28 -32
- package/client/utils/dom.ts +17 -33
- package/common/app/index.ts +3 -3
- package/common/data/chaines/index.ts +22 -23
- package/common/data/dates.ts +35 -70
- package/common/data/markdown.ts +42 -39
- package/common/dev/serverHotReload.ts +26 -0
- package/common/errors/index.tsx +110 -142
- package/common/router/contracts.ts +29 -0
- package/common/router/index.ts +89 -108
- package/common/router/layouts.ts +34 -47
- package/common/router/pageSetup.ts +50 -0
- package/common/router/register.ts +53 -24
- package/common/router/request/api.ts +30 -36
- package/common/router/request/index.ts +2 -8
- package/common/router/response/index.ts +8 -15
- package/common/router/response/page.ts +70 -58
- package/common/utils.ts +1 -1
- package/doc/TODO.md +1 -1
- package/eslint.js +62 -0
- package/package.json +14 -49
- package/prettier.config.cjs +9 -0
- package/scripts/cleanup-generated-controllers.ts +62 -0
- package/scripts/fix-reference-app-typing.ts +490 -0
- package/scripts/refactor-client-app-imports.ts +244 -0
- package/scripts/refactor-client-pages.ts +587 -0
- package/scripts/refactor-server-controllers.ts +470 -0
- package/scripts/refactor-server-runtime-aliases.ts +360 -0
- package/scripts/restore-client-app-import-files.ts +41 -0
- package/scripts/restore-files-from-git-head.ts +20 -0
- package/scripts/update-codex-agents.ts +35 -0
- package/server/app/commands.ts +35 -64
- package/server/app/container/config.ts +48 -59
- package/server/app/container/console/index.ts +202 -248
- package/server/app/container/index.ts +33 -71
- package/server/app/controller/index.ts +61 -0
- package/server/app/index.ts +39 -105
- package/server/app/service/container.ts +41 -42
- package/server/app/service/index.ts +120 -147
- package/server/context.ts +1 -1
- package/server/index.ts +25 -1
- package/server/services/auth/index.ts +75 -115
- package/server/services/auth/router/index.ts +31 -32
- package/server/services/auth/router/request.ts +14 -16
- package/server/services/cron/CronTask.ts +13 -26
- package/server/services/cron/index.ts +14 -36
- package/server/services/disks/driver.ts +40 -58
- package/server/services/disks/drivers/local/index.ts +79 -90
- package/server/services/disks/drivers/s3/index.ts +116 -163
- package/server/services/disks/index.ts +23 -38
- package/server/services/email/index.ts +45 -104
- package/server/services/email/utils.ts +14 -27
- package/server/services/fetch/index.ts +53 -85
- package/server/services/prisma/Facet.ts +39 -91
- package/server/services/prisma/index.ts +74 -110
- package/server/services/router/generatedRuntime.ts +29 -0
- package/server/services/router/http/index.ts +78 -73
- package/server/services/router/http/multipart.ts +19 -42
- package/server/services/router/index.ts +378 -365
- package/server/services/router/request/api.ts +26 -25
- package/server/services/router/request/index.ts +44 -51
- package/server/services/router/request/service.ts +7 -11
- package/server/services/router/request/validation/zod.ts +111 -148
- package/server/services/router/response/index.ts +110 -125
- package/server/services/router/response/mask/Filter.ts +31 -72
- package/server/services/router/response/mask/index.ts +8 -15
- package/server/services/router/response/mask/selecteurs.ts +11 -25
- package/server/services/router/response/page/clientManifest.ts +25 -0
- package/server/services/router/response/page/document.tsx +199 -127
- package/server/services/router/response/page/index.tsx +89 -94
- package/server/services/router/service.ts +13 -15
- package/server/services/schema/index.ts +17 -26
- package/server/services/schema/request.ts +19 -33
- package/server/services/schema/router/index.ts +8 -11
- package/server/services/security/encrypt/aes/index.ts +15 -35
- package/server/utils/slug.ts +29 -35
- package/skills/clean-project-code/SKILL.md +63 -0
- package/skills/clean-project-code/agents/openai.yaml +4 -0
- package/tsconfig.common.json +4 -3
- package/tsconfig.json +4 -1
- package/types/aliases.d.ts +17 -21
- package/types/controller-input.test.ts +48 -0
- package/types/express-extra.d.ts +6 -0
- package/types/global/constants.d.ts +13 -0
- package/types/global/express-extra.d.ts +6 -0
- package/types/global/modules.d.ts +13 -16
- package/types/global/utils.d.ts +17 -49
- package/types/global/vendors.d.ts +62 -0
- package/types/icons.d.ts +65 -1
- package/types/uuid.d.ts +3 -0
- package/types/vendors.d.ts +62 -0
- package/cli/compiler/common/babel/index.ts +0 -170
- package/cli/compiler/common/babel/plugins/index.ts +0 -0
- package/cli/compiler/common/babel/plugins/services.ts +0 -586
- package/cli/compiler/common/babel/routes/imports.ts +0 -127
- package/cli/compiler/common/babel/routes/routes.ts +0 -1130
- package/client/services/captcha/index.ts +0 -67
- package/client/services/socket/index.ts +0 -147
- package/common/data/rte/nodes.ts +0 -83
- package/common/data/stats.ts +0 -90
- package/common/utils/rte.ts +0 -183
- package/server/services/auth/old.ts +0 -277
- package/server/services/cache/commands.ts +0 -41
- package/server/services/cache/index.ts +0 -297
- package/server/services/cache/service.json +0 -6
- package/server/services/socket/index.ts +0 -162
- package/server/services/socket/scope.ts +0 -226
- package/server/services/socket/service.json +0 -6
- package/server/services_old/SocketClient.ts +0 -92
- package/server/services_old/Token.old.ts +0 -97
|
@@ -12,17 +12,14 @@ import path from 'path';
|
|
|
12
12
|
import AWS from 'aws-sdk';
|
|
13
13
|
import dayjs from 'dayjs';
|
|
14
14
|
|
|
15
|
-
// Core
|
|
16
|
-
import type { Application } from '@server/app';
|
|
17
|
-
import type { TServiceArgs } from '@server/app/service';
|
|
18
|
-
|
|
19
15
|
// Specific
|
|
20
|
-
import DiskDriver, {
|
|
21
|
-
TDrivercnfig,
|
|
22
|
-
SourceFile,
|
|
16
|
+
import DiskDriver, {
|
|
17
|
+
TDrivercnfig,
|
|
18
|
+
SourceFile,
|
|
23
19
|
TOutputFileOptions,
|
|
24
|
-
TReadFileOptions
|
|
20
|
+
TReadFileOptions,
|
|
25
21
|
} from '@server/services/disks/driver';
|
|
22
|
+
import type { TSetupConfig } from '@server/app/service';
|
|
26
23
|
|
|
27
24
|
/*----------------------------------
|
|
28
25
|
- CONFIG
|
|
@@ -34,268 +31,224 @@ const debug = false;
|
|
|
34
31
|
- TYPES
|
|
35
32
|
----------------------------------*/
|
|
36
33
|
|
|
37
|
-
export type TConfig = TDrivercnfig & {
|
|
38
|
-
accessKeyId: string,
|
|
39
|
-
secretAccessKey: string,
|
|
40
|
-
region: string,
|
|
41
|
-
}
|
|
34
|
+
export type TConfig = TDrivercnfig & { accessKeyId: string; secretAccessKey: string; region: string };
|
|
42
35
|
|
|
43
36
|
/*----------------------------------
|
|
44
37
|
- SERVICE
|
|
45
38
|
----------------------------------*/
|
|
46
39
|
export default class S3Driver<
|
|
47
40
|
Config extends TConfig = TConfig,
|
|
48
|
-
TBucketName = keyof Config[
|
|
49
|
-
> extends DiskDriver<
|
|
50
|
-
|
|
51
|
-
public s3: AWS.S3;
|
|
41
|
+
TBucketName extends Extract<keyof Config['buckets'], string> = Extract<keyof Config['buckets'], string>,
|
|
42
|
+
> extends DiskDriver<Config, TBucketName> {
|
|
43
|
+
public s3: AWS.S3;
|
|
52
44
|
|
|
53
|
-
|
|
45
|
+
private getBucketName(bucketName: TBucketName) {
|
|
46
|
+
const bucket = this.config.buckets[bucketName];
|
|
47
|
+
if (bucket === undefined) throw new Error(`Bucket "${bucketName}" not found in configuration`);
|
|
48
|
+
return bucket;
|
|
49
|
+
}
|
|
54
50
|
|
|
51
|
+
public constructor(config: TSetupConfig<Config>, app: DiskDriver<Config, TBucketName>['app']) {
|
|
55
52
|
super(config, app);
|
|
56
53
|
|
|
57
|
-
AWS.config.update({
|
|
58
|
-
accessKeyId: this.config.accessKeyId,
|
|
59
|
-
secretAccessKey: this.config.secretAccessKey,
|
|
60
|
-
});
|
|
54
|
+
AWS.config.update({ accessKeyId: this.config.accessKeyId, secretAccessKey: this.config.secretAccessKey });
|
|
61
55
|
|
|
62
|
-
this.s3 = new AWS.S3();
|
|
56
|
+
this.s3 = new AWS.S3();
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
|
|
59
|
+
/*----------------------------------
|
|
66
60
|
- DISK LIFECYCLE
|
|
67
61
|
----------------------------------*/
|
|
68
62
|
|
|
69
|
-
public async mount() {
|
|
70
|
-
|
|
71
|
-
}
|
|
63
|
+
public async mount() {}
|
|
72
64
|
|
|
73
|
-
public async unmount() {
|
|
74
|
-
|
|
75
|
-
}
|
|
65
|
+
public async unmount() {}
|
|
76
66
|
|
|
77
67
|
/*----------------------------------
|
|
78
68
|
- ACTIONS
|
|
79
69
|
----------------------------------*/
|
|
80
70
|
|
|
81
|
-
public getFileUrl(
|
|
82
|
-
|
|
83
|
-
filename
|
|
84
|
-
) {
|
|
85
|
-
|
|
86
|
-
const bucket = this.config.buckets[bucketName];
|
|
87
|
-
if (bucket === undefined)
|
|
88
|
-
throw new Error(`Bucket "${bucketName}" not found in configuration`);
|
|
89
|
-
return `https://${bucket}.s3.${this.config.region}.amazonaws.com/${filename}`
|
|
71
|
+
public getFileUrl(bucketName: TBucketName, filename: string) {
|
|
72
|
+
const bucket = this.getBucketName(bucketName);
|
|
73
|
+
return `https://${bucket}.s3.${this.config.region}.amazonaws.com/${filename}`;
|
|
90
74
|
}
|
|
91
75
|
|
|
92
|
-
public readDir(
|
|
93
|
-
const bucket = this.
|
|
76
|
+
public readDir(bucketName: TBucketName, dirname?: string) {
|
|
77
|
+
const bucket = this.getBucketName(bucketName);
|
|
94
78
|
return new Promise<SourceFile[]>((resolve, reject) => {
|
|
95
|
-
|
|
79
|
+
debug && console.log(`readDir ` + (dirname === undefined ? bucket : path.join(bucket, dirname)));
|
|
96
80
|
this.s3.listObjectsV2({ Bucket: bucket }, async (err, data) => {
|
|
97
|
-
|
|
98
81
|
if (err) return reject(err);
|
|
99
82
|
|
|
100
83
|
const files: SourceFile[] = [];
|
|
101
|
-
for (const file of data.Contents) {
|
|
102
|
-
|
|
84
|
+
for (const file of data.Contents || []) {
|
|
85
|
+
if (!file.Key) continue;
|
|
86
|
+
|
|
103
87
|
const [source, ...hierarchy] = file.Key.split('/');
|
|
104
|
-
if (hierarchy.length > 1)
|
|
88
|
+
if (hierarchy.length > 1)
|
|
89
|
+
// Take only direct childs
|
|
105
90
|
continue;
|
|
106
91
|
|
|
107
92
|
const filename = hierarchy.join('/');
|
|
108
|
-
if (!filename.endsWith('.csv'))
|
|
109
|
-
continue;
|
|
93
|
+
if (!filename.endsWith('.csv')) continue;
|
|
110
94
|
|
|
111
95
|
debug && console.log('-', file.Key);
|
|
112
96
|
|
|
113
|
-
const fileContent = await this.readFile(
|
|
114
|
-
const rowsCount = (fileContent
|
|
97
|
+
const fileContent = await this.readFile(bucketName, file.Key, { encoding: 'string' });
|
|
98
|
+
const rowsCount = String(fileContent).split('\n').length - 1;
|
|
115
99
|
|
|
116
|
-
const name =
|
|
117
|
-
|
|
118
|
-
|
|
100
|
+
const name =
|
|
101
|
+
dayjs(file.LastModified).format('DD/MM HH:mm:ss') +
|
|
102
|
+
' : ' +
|
|
103
|
+
path.join(source, filename) +
|
|
104
|
+
' : ' +
|
|
105
|
+
rowsCount +
|
|
106
|
+
' contacts';
|
|
119
107
|
|
|
120
108
|
files.push({
|
|
121
109
|
name,
|
|
122
110
|
path: file.Key,
|
|
123
111
|
source: source,
|
|
124
|
-
modified: file.LastModified,
|
|
125
|
-
parentFolder: source
|
|
112
|
+
modified: file.LastModified?.getTime() || 0,
|
|
113
|
+
parentFolder: source,
|
|
126
114
|
});
|
|
127
|
-
|
|
128
115
|
}
|
|
129
|
-
|
|
116
|
+
|
|
130
117
|
debug && console.log(`readDir ${bucket}/${dirname || ''}: ${files.length} objects`);
|
|
131
118
|
resolve(files);
|
|
132
119
|
});
|
|
133
120
|
});
|
|
134
121
|
}
|
|
135
122
|
|
|
136
|
-
public readFile(
|
|
137
|
-
|
|
138
|
-
filename: string,
|
|
139
|
-
options: TReadFileOptions = {}
|
|
140
|
-
) {
|
|
141
|
-
const bucket = this.config.buckets[bucketName];
|
|
123
|
+
public readFile(bucketName: TBucketName, filename: string, options: TReadFileOptions = {}) {
|
|
124
|
+
const bucket = this.getBucketName(bucketName);
|
|
142
125
|
debug && console.log(`readFile ${bucket}/${filename}`);
|
|
143
|
-
return new Promise<string>((
|
|
144
|
-
this.s3.getObject({
|
|
145
|
-
Bucket: bucket,
|
|
146
|
-
Key: filename
|
|
147
|
-
}, (err, data) => {
|
|
148
|
-
|
|
126
|
+
return new Promise<Buffer | string>((resolve, reject) => {
|
|
127
|
+
this.s3.getObject({ Bucket: bucket, Key: filename }, (err, data) => {
|
|
149
128
|
if (err) return reject(err);
|
|
150
129
|
|
|
151
130
|
let body: any;
|
|
152
131
|
switch (options.encoding) {
|
|
153
132
|
case 'string':
|
|
154
|
-
body = data.Body?.toString()
|
|
133
|
+
body = data.Body?.toString();
|
|
155
134
|
break;
|
|
156
135
|
default:
|
|
157
136
|
body = data.Body;
|
|
158
137
|
break;
|
|
159
138
|
}
|
|
160
139
|
|
|
161
|
-
resolve(
|
|
140
|
+
resolve(body);
|
|
162
141
|
});
|
|
163
|
-
})
|
|
142
|
+
});
|
|
164
143
|
}
|
|
165
144
|
|
|
166
|
-
public createReadStream(
|
|
167
|
-
const bucket = this.
|
|
145
|
+
public createReadStream(bucketName: TBucketName, filename: string) {
|
|
146
|
+
const bucket = this.getBucketName(bucketName);
|
|
168
147
|
debug && console.log(`createReadStream ${bucket}/${filename}`);
|
|
169
|
-
return this.s3.getObject({
|
|
170
|
-
Bucket: bucket,
|
|
171
|
-
Key: filename
|
|
172
|
-
}).createReadStream();
|
|
148
|
+
return this.s3.getObject({ Bucket: bucket, Key: filename }).createReadStream();
|
|
173
149
|
}
|
|
174
150
|
|
|
175
|
-
public exists(
|
|
176
|
-
const bucket = this.
|
|
151
|
+
public exists(bucketName: TBucketName, filename: string) {
|
|
152
|
+
const bucket = this.getBucketName(bucketName);
|
|
177
153
|
debug && console.log(`exists`, path.join(bucket, filename));
|
|
178
|
-
return new Promise<boolean>((
|
|
179
|
-
this.s3.headObject({
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (!err)
|
|
185
|
-
resolve(true);
|
|
186
|
-
else if (err.name === 'NotFound')
|
|
187
|
-
resolve(false);
|
|
188
|
-
else
|
|
189
|
-
reject(err);
|
|
154
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
155
|
+
this.s3.headObject({ Bucket: bucket, Key: filename }, (err, metadata) => {
|
|
156
|
+
if (!err) resolve(true);
|
|
157
|
+
else if (err.name === 'NotFound') resolve(false);
|
|
158
|
+
else reject(err);
|
|
190
159
|
});
|
|
191
|
-
})
|
|
160
|
+
});
|
|
192
161
|
}
|
|
193
162
|
|
|
194
|
-
public async move(
|
|
195
|
-
|
|
163
|
+
public async move(
|
|
164
|
+
bucketName: TBucketName,
|
|
165
|
+
source: string,
|
|
166
|
+
destination: string,
|
|
167
|
+
options: { overwrite?: boolean } = {},
|
|
168
|
+
) {
|
|
169
|
+
const bucket = this.getBucketName(bucketName);
|
|
196
170
|
debug && console.log(`move ${bucket}/${source} to ${bucket}/${destination}`);
|
|
197
171
|
|
|
198
|
-
if (options.overwrite)
|
|
199
|
-
await this.s3.deleteObject({
|
|
200
|
-
Bucket: bucket,
|
|
201
|
-
Key: destination,
|
|
202
|
-
}).promise();
|
|
203
|
-
|
|
204
|
-
await this.s3.copyObject({
|
|
205
|
-
Bucket: bucket,
|
|
206
|
-
CopySource: source,
|
|
207
|
-
Key: destination
|
|
208
|
-
}).promise();
|
|
172
|
+
if (options.overwrite) await this.s3.deleteObject({ Bucket: bucket, Key: destination }).promise();
|
|
209
173
|
|
|
210
|
-
|
|
174
|
+
await this.s3.copyObject({ Bucket: bucket, CopySource: source, Key: destination }).promise();
|
|
211
175
|
|
|
176
|
+
debug && console.log(`Move ${bucket}/${source} to ${bucket}/${destination}: OK`);
|
|
212
177
|
}
|
|
213
178
|
|
|
214
|
-
public outputFile(
|
|
215
|
-
bucketName: TBucketName,
|
|
216
|
-
filename: string,
|
|
217
|
-
content: string | Buffer,
|
|
218
|
-
options?: TOutputFileOptions
|
|
179
|
+
public outputFile(
|
|
180
|
+
bucketName: TBucketName,
|
|
181
|
+
filename: string,
|
|
182
|
+
content: string | Buffer,
|
|
183
|
+
options?: TOutputFileOptions,
|
|
219
184
|
) {
|
|
220
|
-
const bucket = this.
|
|
185
|
+
const bucket = this.getBucketName(bucketName);
|
|
221
186
|
debug && console.log(`outputFile ${bucket}/${filename}`);
|
|
222
|
-
return new Promise((
|
|
223
|
-
this.s3.upload(
|
|
224
|
-
Bucket: bucket,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
path: data.Location
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
})
|
|
187
|
+
return new Promise<{ path: string }>((resolve, reject) => {
|
|
188
|
+
this.s3.upload(
|
|
189
|
+
{ Bucket: bucket, Key: filename, Body: content },
|
|
190
|
+
(err: Error | null, data: AWS.S3.ManagedUpload.SendData) => {
|
|
191
|
+
if (err) return reject(err);
|
|
192
|
+
debug && console.log(`outputFile ${bucket}/${filename}: OK (${data.Location})`);
|
|
193
|
+
|
|
194
|
+
resolve({ path: data.Location || `s3://${bucket}/${filename}` });
|
|
195
|
+
},
|
|
196
|
+
);
|
|
197
|
+
});
|
|
237
198
|
}
|
|
238
199
|
|
|
239
|
-
public async readJSON(
|
|
240
|
-
const bucket = this.
|
|
200
|
+
public async readJSON(bucketName: TBucketName, filename: string) {
|
|
201
|
+
const bucket = this.getBucketName(bucketName);
|
|
241
202
|
debug && console.log(`readJSON ${bucket}/${filename}`);
|
|
242
203
|
const filecontent = await this.readFile(bucketName, filename);
|
|
243
204
|
try {
|
|
244
205
|
debug && console.log(`readJSON: ${bucket}/${filename} : PARSE JSON`);
|
|
245
|
-
return JSON.parse(filecontent);
|
|
206
|
+
return JSON.parse(String(filecontent));
|
|
246
207
|
} catch (error) {
|
|
247
208
|
console.error(`Failed to parse file "${filename}" as JSON: `, error);
|
|
248
209
|
throw new Error(`Failed to parse file "${filename}" as JSON: ` + error);
|
|
249
210
|
}
|
|
250
211
|
}
|
|
251
212
|
|
|
252
|
-
public delete(
|
|
253
|
-
const bucket = this.
|
|
213
|
+
public delete(bucketName: TBucketName, filename: string) {
|
|
214
|
+
const bucket = this.getBucketName(bucketName);
|
|
254
215
|
debug && console.log(`delete ${bucket}/${filename}`);
|
|
255
|
-
return new Promise<boolean>((
|
|
256
|
-
this.s3.deleteObject({
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (!err)
|
|
262
|
-
resolve(true);
|
|
263
|
-
else if (err.name === 'NotFound')
|
|
264
|
-
resolve(false);
|
|
265
|
-
else
|
|
266
|
-
reject(err);
|
|
216
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
217
|
+
this.s3.deleteObject({ Bucket: bucket, Key: filename }, (err, metadata) => {
|
|
218
|
+
if (!err) resolve(true);
|
|
219
|
+
else if (err.name === 'NotFound') resolve(false);
|
|
220
|
+
else reject(err);
|
|
267
221
|
});
|
|
268
|
-
})
|
|
222
|
+
});
|
|
269
223
|
}
|
|
270
224
|
|
|
271
|
-
public async deleteDir(
|
|
272
|
-
const bucket = this.
|
|
225
|
+
public async deleteDir(bucketName: TBucketName, directoryPath: string) {
|
|
226
|
+
const bucket = this.getBucketName(bucketName);
|
|
273
227
|
debug && console.log(`delete ${bucket}/${directoryPath}`);
|
|
274
228
|
try {
|
|
275
229
|
// Liste des objets dans le répertoire
|
|
276
|
-
const listedObjects = await this.s3.listObjectsV2({
|
|
277
|
-
Bucket: bucket,
|
|
278
|
-
Prefix: directoryPath
|
|
279
|
-
}).promise();
|
|
230
|
+
const listedObjects = await this.s3.listObjectsV2({ Bucket: bucket, Prefix: directoryPath }).promise();
|
|
280
231
|
|
|
281
|
-
if (!listedObjects.Contents?.length) return;
|
|
232
|
+
if (!listedObjects.Contents?.length) return false;
|
|
282
233
|
|
|
283
234
|
// Supprimer les objets
|
|
284
|
-
await this.s3
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
235
|
+
await this.s3
|
|
236
|
+
.deleteObjects({
|
|
237
|
+
Bucket: bucket,
|
|
238
|
+
Delete: {
|
|
239
|
+
Objects: listedObjects.Contents.flatMap(({ Key }) => (Key ? [{ Key }] : [])),
|
|
240
|
+
},
|
|
241
|
+
})
|
|
242
|
+
.promise();
|
|
290
243
|
|
|
291
244
|
// Récursivement, traiter d'autres pages d'objets si elles existent
|
|
292
245
|
//if (listedObjects.IsTruncated) await deleteDirectory();
|
|
293
246
|
|
|
294
247
|
console.log(`Le répertoire ${directoryPath} a été supprimé.`);
|
|
295
|
-
|
|
248
|
+
return true;
|
|
296
249
|
} catch (error) {
|
|
297
|
-
console.error(
|
|
250
|
+
console.error('Erreur lors de la suppression :', error);
|
|
251
|
+
throw error;
|
|
298
252
|
}
|
|
299
253
|
}
|
|
300
|
-
|
|
301
|
-
}
|
|
254
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
----------------------------------*/
|
|
4
4
|
|
|
5
5
|
// Core
|
|
6
|
-
import type { Application } from '@server/app';
|
|
6
|
+
import type { Application } from '@server/app/index';
|
|
7
7
|
import Service, { AnyService, TRegisteredServicesIndex, TServiceArgs } from '@server/app/service';
|
|
8
8
|
|
|
9
9
|
// Specific
|
|
@@ -15,76 +15,61 @@ export type { default as Driver } from './driver';
|
|
|
15
15
|
----------------------------------*/
|
|
16
16
|
|
|
17
17
|
type Config = {
|
|
18
|
-
debug: boolean
|
|
19
|
-
default: string
|
|
20
|
-
drivers: {
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}
|
|
18
|
+
debug: boolean;
|
|
19
|
+
default: string; //keyof MountpointList,
|
|
20
|
+
drivers: { [driverId: string]: Driver };
|
|
21
|
+
};
|
|
24
22
|
|
|
25
|
-
export type Hooks = {
|
|
23
|
+
export type Hooks = {};
|
|
26
24
|
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type Services = {
|
|
30
|
-
[diskId: string]: Driver
|
|
31
|
-
}
|
|
25
|
+
export type Services = { [diskId: string]: Driver };
|
|
32
26
|
|
|
33
27
|
/*----------------------------------
|
|
34
28
|
- SERVICE
|
|
35
29
|
----------------------------------*/
|
|
36
30
|
export default class DisksManager<
|
|
37
31
|
MountpointList extends Services,
|
|
38
|
-
TConfig extends Config,
|
|
39
|
-
TApplication extends Application
|
|
32
|
+
TConfig extends Config & { default: keyof MountpointList & string; drivers: MountpointList },
|
|
33
|
+
TApplication extends Application,
|
|
40
34
|
> extends Service<TConfig, Hooks, TApplication, TApplication> {
|
|
41
|
-
|
|
42
|
-
public default!: Driver;
|
|
35
|
+
public default!: MountpointList[keyof MountpointList & string];
|
|
43
36
|
|
|
44
37
|
/*----------------------------------
|
|
45
38
|
- LIFECYCLE
|
|
46
39
|
----------------------------------*/
|
|
47
40
|
|
|
48
|
-
public constructor(
|
|
49
|
-
|
|
41
|
+
public constructor(...args: TServiceArgs<DisksManager<MountpointList, TConfig, TApplication>>) {
|
|
50
42
|
super(...args);
|
|
51
43
|
|
|
52
44
|
const drivers = this.config.drivers;
|
|
53
|
-
|
|
54
|
-
if (Object.keys(
|
|
55
|
-
throw new Error("At least one disk driver should be mounted.");
|
|
45
|
+
|
|
46
|
+
if (Object.keys(drivers).length === 0) throw new Error('At least one disk driver should be mounted.');
|
|
56
47
|
|
|
57
48
|
// Bind current instance of the service as parent
|
|
58
49
|
/*for (const driverId in drivers) {
|
|
59
50
|
drivers[driverId].parent = this;
|
|
60
51
|
}*/
|
|
61
52
|
|
|
62
|
-
const defaultDisk = drivers[
|
|
63
|
-
if (defaultDisk === undefined)
|
|
64
|
-
console.log(`Default disk "${this.config.default as string}" not mounted.`);
|
|
53
|
+
const defaultDisk = drivers[this.config.default];
|
|
54
|
+
if (defaultDisk === undefined) console.log(`Default disk "${this.config.default as string}" not mounted.`);
|
|
65
55
|
|
|
66
56
|
this.default = defaultDisk;
|
|
67
|
-
|
|
68
57
|
}
|
|
69
58
|
|
|
70
|
-
public async shutdown() {
|
|
71
|
-
|
|
72
|
-
}
|
|
59
|
+
public async shutdown() {}
|
|
73
60
|
|
|
74
61
|
/*----------------------------------
|
|
75
62
|
- LIFECYCLE
|
|
76
63
|
----------------------------------*/
|
|
77
64
|
|
|
78
|
-
public get(
|
|
65
|
+
public get(diskName?: 'default' | keyof MountpointList) {
|
|
66
|
+
const disk =
|
|
67
|
+
diskName === 'default' || diskName === undefined
|
|
68
|
+
? this.default
|
|
69
|
+
: this.config.drivers[diskName as keyof MountpointList];
|
|
79
70
|
|
|
80
|
-
|
|
81
|
-
? this.default
|
|
82
|
-
: this.config.drivers[diskName];
|
|
83
|
-
|
|
84
|
-
if (disk === undefined)
|
|
85
|
-
throw new Error(`Disk "${diskName as string}" not found.`);
|
|
71
|
+
if (disk === undefined) throw new Error(`Disk "${diskName as string}" not found.`);
|
|
86
72
|
|
|
87
73
|
return disk;
|
|
88
74
|
}
|
|
89
|
-
|
|
90
|
-
}
|
|
75
|
+
}
|