@geek-fun/serverlessinsight 0.6.14 → 0.7.0
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 +405 -10
- package/README.md +1 -0
- package/dist/package.json +8 -2
- package/dist/src/commands/deploy.js +4 -0
- package/dist/src/commands/destroy.js +4 -0
- package/dist/src/common/credentials.js +12 -0
- package/dist/src/common/providerEnum.js +1 -0
- package/dist/src/common/runtimeMapper.js +24 -3
- package/dist/src/common/volcengineClient/apigwOperations.js +271 -0
- package/dist/src/common/volcengineClient/iamOperations.js +349 -0
- package/dist/src/common/volcengineClient/index.js +99 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +256 -0
- package/dist/src/common/volcengineClient/tosOperations.js +440 -0
- package/dist/src/common/volcengineClient/types.js +26 -0
- package/dist/src/common/volcengineClient/vefaasOperations.js +386 -0
- package/dist/src/lang/en.js +120 -0
- package/dist/src/lang/zh-CN.js +119 -0
- package/dist/src/stack/aliyunStack/fc3Resource.js +18 -3
- package/dist/src/stack/deploy.js +4 -0
- package/dist/src/stack/volcengineStack/apigwExecutor.js +87 -0
- package/dist/src/stack/volcengineStack/apigwPlanner.js +110 -0
- package/dist/src/stack/volcengineStack/apigwResource.js +302 -0
- package/dist/src/stack/volcengineStack/apigwTypes.js +106 -0
- package/dist/src/stack/volcengineStack/deployer.js +59 -0
- package/dist/src/stack/volcengineStack/destroyer.js +72 -0
- package/dist/src/stack/volcengineStack/index.js +44 -0
- package/dist/src/stack/volcengineStack/planner.js +27 -0
- package/dist/src/stack/volcengineStack/tosExecutor.js +106 -0
- package/dist/src/stack/volcengineStack/tosPlanner.js +96 -0
- package/dist/src/stack/volcengineStack/tosResource.js +103 -0
- package/dist/src/stack/volcengineStack/tosTypes.js +65 -0
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +102 -0
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +84 -0
- package/dist/src/stack/volcengineStack/vefaasResource.js +513 -0
- package/dist/src/stack/volcengineStack/vefaasTypes.js +75 -0
- package/dist/src/types/domains/state.js +3 -0
- package/dist/src/validator/functionSchema.js +13 -0
- package/dist/src/validator/rootSchema.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -2
- package/samples/volcengine-poc-advanced.yml +59 -0
- package/samples/volcengine-poc-api.yml +31 -0
- package/samples/volcengine-poc-bucket.yml +17 -0
- package/samples/volcengine-poc-function.yml +19 -0
- package/samples/volcengine-poc-vpc.yml +34 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createTosOperations = void 0;
|
|
37
|
+
const fs = __importStar(require("node:fs"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const logger_1 = require("../logger");
|
|
40
|
+
const lang_1 = require("../../lang");
|
|
41
|
+
const TOS_ACL_VALUES = ['private', 'public-read', 'public-read-write'];
|
|
42
|
+
const getContentType = (filePath) => {
|
|
43
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
44
|
+
const contentTypes = {
|
|
45
|
+
'.html': 'text/html',
|
|
46
|
+
'.css': 'text/css',
|
|
47
|
+
'.js': 'application/javascript',
|
|
48
|
+
'.json': 'application/json',
|
|
49
|
+
'.png': 'image/png',
|
|
50
|
+
'.jpg': 'image/jpeg',
|
|
51
|
+
'.jpeg': 'image/jpeg',
|
|
52
|
+
'.gif': 'image/gif',
|
|
53
|
+
'.svg': 'image/svg+xml',
|
|
54
|
+
'.ico': 'image/x-icon',
|
|
55
|
+
'.woff': 'font/woff',
|
|
56
|
+
'.woff2': 'font/woff2',
|
|
57
|
+
'.ttf': 'font/ttf',
|
|
58
|
+
'.eot': 'application/vnd.ms-fontobject',
|
|
59
|
+
'.mp4': 'video/mp4',
|
|
60
|
+
'.webm': 'video/webm',
|
|
61
|
+
'.mp3': 'audio/mpeg',
|
|
62
|
+
'.pdf': 'application/pdf',
|
|
63
|
+
'.zip': 'application/zip',
|
|
64
|
+
'.xml': 'application/xml',
|
|
65
|
+
'.txt': 'text/plain',
|
|
66
|
+
};
|
|
67
|
+
return contentTypes[ext] || 'application/octet-stream';
|
|
68
|
+
};
|
|
69
|
+
const createTosOperations = (client, _region) => {
|
|
70
|
+
return {
|
|
71
|
+
createBucket: async (config) => {
|
|
72
|
+
if (!client) {
|
|
73
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
74
|
+
}
|
|
75
|
+
const params = {
|
|
76
|
+
Bucket: config.bucketName,
|
|
77
|
+
};
|
|
78
|
+
if (config.acl && TOS_ACL_VALUES.includes(config.acl)) {
|
|
79
|
+
params.ACL = config.acl;
|
|
80
|
+
}
|
|
81
|
+
if (config.storageClass) {
|
|
82
|
+
params.StorageClass = config.storageClass;
|
|
83
|
+
}
|
|
84
|
+
await client.fetchOpenAPI({
|
|
85
|
+
Action: 'CreateBucket',
|
|
86
|
+
Version: '2018-08-01',
|
|
87
|
+
method: 'PUT',
|
|
88
|
+
headers: {
|
|
89
|
+
'content-type': 'application/xml',
|
|
90
|
+
},
|
|
91
|
+
query: params,
|
|
92
|
+
});
|
|
93
|
+
logger_1.logger.info(lang_1.lang.__('TOS_BUCKET_CREATED', { bucketName: config.bucketName }));
|
|
94
|
+
if (config.websiteConfig) {
|
|
95
|
+
await client.fetchOpenAPI({
|
|
96
|
+
Action: 'PutBucketWebsite',
|
|
97
|
+
Version: '2018-08-01',
|
|
98
|
+
method: 'PUT',
|
|
99
|
+
headers: {
|
|
100
|
+
'content-type': 'application/xml',
|
|
101
|
+
},
|
|
102
|
+
query: {
|
|
103
|
+
Bucket: config.bucketName,
|
|
104
|
+
},
|
|
105
|
+
data: {
|
|
106
|
+
IndexDocument: {
|
|
107
|
+
Suffix: config.websiteConfig.indexDocument,
|
|
108
|
+
},
|
|
109
|
+
...(config.websiteConfig.errorDocument && {
|
|
110
|
+
ErrorDocument: {
|
|
111
|
+
Key: config.websiteConfig.errorDocument,
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
logger_1.logger.info(lang_1.lang.__('TOS_BUCKET_WEBSITE_CONFIGURED', { bucketName: config.bucketName }));
|
|
117
|
+
}
|
|
118
|
+
const bucketInfo = await (async () => {
|
|
119
|
+
const response = await client.fetchOpenAPI({
|
|
120
|
+
Action: 'GetBucketInfo',
|
|
121
|
+
Version: '2018-08-01',
|
|
122
|
+
method: 'GET',
|
|
123
|
+
query: {
|
|
124
|
+
Bucket: config.bucketName,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
const result = (response.Result || {});
|
|
128
|
+
const bucketData = (result.BucketInfo || {});
|
|
129
|
+
return {
|
|
130
|
+
name: config.bucketName,
|
|
131
|
+
location: bucketData.Location,
|
|
132
|
+
creationDate: bucketData.CreationDate,
|
|
133
|
+
storageClass: bucketData.StorageClass,
|
|
134
|
+
extranetEndpoint: bucketData.ExtranetEndpoint,
|
|
135
|
+
intranetEndpoint: bucketData.IntranetEndpoint,
|
|
136
|
+
acl: bucketData.ACL,
|
|
137
|
+
};
|
|
138
|
+
})();
|
|
139
|
+
return bucketInfo;
|
|
140
|
+
},
|
|
141
|
+
getBucket: async (bucketName) => {
|
|
142
|
+
if (!client) {
|
|
143
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const response = await client.fetchOpenAPI({
|
|
147
|
+
Action: 'GetBucketInfo',
|
|
148
|
+
Version: '2018-08-01',
|
|
149
|
+
method: 'GET',
|
|
150
|
+
query: {
|
|
151
|
+
Bucket: bucketName,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
const result = (response.Result || {});
|
|
155
|
+
const bucketData = (result.BucketInfo || {});
|
|
156
|
+
let websiteConfig;
|
|
157
|
+
try {
|
|
158
|
+
const websiteResponse = await client.fetchOpenAPI({
|
|
159
|
+
Action: 'GetBucketWebsite',
|
|
160
|
+
Version: '2018-08-01',
|
|
161
|
+
method: 'GET',
|
|
162
|
+
query: {
|
|
163
|
+
Bucket: bucketName,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
const websiteResult = (websiteResponse.Result || {});
|
|
167
|
+
if (websiteResult.IndexDocument) {
|
|
168
|
+
const indexDoc = websiteResult.IndexDocument;
|
|
169
|
+
websiteConfig = {
|
|
170
|
+
indexDocument: indexDoc.Suffix,
|
|
171
|
+
};
|
|
172
|
+
if (websiteResult.ErrorDocument) {
|
|
173
|
+
const errorDoc = websiteResult.ErrorDocument;
|
|
174
|
+
websiteConfig.errorDocument = errorDoc.Key;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// Website config may not exist
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
name: bucketName,
|
|
183
|
+
location: bucketData.Location,
|
|
184
|
+
creationDate: bucketData.CreationDate,
|
|
185
|
+
storageClass: bucketData.StorageClass,
|
|
186
|
+
extranetEndpoint: bucketData.ExtranetEndpoint,
|
|
187
|
+
intranetEndpoint: bucketData.IntranetEndpoint,
|
|
188
|
+
acl: bucketData.ACL,
|
|
189
|
+
websiteConfig,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (error &&
|
|
194
|
+
typeof error === 'object' &&
|
|
195
|
+
'code' in error &&
|
|
196
|
+
(error.code === 'NoSuchBucket' || error.code === 'ResourceNotFound')) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
updateBucketAcl: async (bucketName, acl) => {
|
|
203
|
+
if (!client) {
|
|
204
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
205
|
+
}
|
|
206
|
+
await client.fetchOpenAPI({
|
|
207
|
+
Action: 'PutBucketAcl',
|
|
208
|
+
Version: '2018-08-01',
|
|
209
|
+
method: 'PUT',
|
|
210
|
+
headers: {
|
|
211
|
+
'content-type': 'application/xml',
|
|
212
|
+
},
|
|
213
|
+
query: {
|
|
214
|
+
Bucket: bucketName,
|
|
215
|
+
ACL: acl,
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
logger_1.logger.info(lang_1.lang.__('TOS_BUCKET_ACL_UPDATED', { bucketName, acl }));
|
|
219
|
+
},
|
|
220
|
+
updateBucketWebsite: async (bucketName, websiteConfig) => {
|
|
221
|
+
if (!client) {
|
|
222
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
223
|
+
}
|
|
224
|
+
const data = {
|
|
225
|
+
IndexDocument: {
|
|
226
|
+
Suffix: websiteConfig.indexDocument,
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
if (websiteConfig.errorDocument) {
|
|
230
|
+
data.ErrorDocument = {
|
|
231
|
+
Key: websiteConfig.errorDocument,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
await client.fetchOpenAPI({
|
|
235
|
+
Action: 'PutBucketWebsite',
|
|
236
|
+
Version: '2018-08-01',
|
|
237
|
+
method: 'PUT',
|
|
238
|
+
headers: {
|
|
239
|
+
'content-type': 'application/xml',
|
|
240
|
+
},
|
|
241
|
+
query: {
|
|
242
|
+
Bucket: bucketName,
|
|
243
|
+
},
|
|
244
|
+
data,
|
|
245
|
+
});
|
|
246
|
+
logger_1.logger.info(lang_1.lang.__('TOS_BUCKET_WEBSITE_UPDATED', { bucketName }));
|
|
247
|
+
},
|
|
248
|
+
deleteBucket: async (bucketName) => {
|
|
249
|
+
if (!client) {
|
|
250
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
let continuationToken;
|
|
254
|
+
do {
|
|
255
|
+
const listResponse = await client.fetchOpenAPI({
|
|
256
|
+
Action: 'ListObjectsType2',
|
|
257
|
+
Version: '2018-08-01',
|
|
258
|
+
method: 'GET',
|
|
259
|
+
query: {
|
|
260
|
+
Bucket: bucketName,
|
|
261
|
+
'list-type': '2',
|
|
262
|
+
...(continuationToken && { 'continuation-token': continuationToken }),
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
const listResult = (listResponse.Result || {});
|
|
266
|
+
const contents = (listResult.Contents || []);
|
|
267
|
+
if (contents.length > 0) {
|
|
268
|
+
const objects = contents.map((obj) => ({ Key: obj.Key }));
|
|
269
|
+
await client.fetchOpenAPI({
|
|
270
|
+
Action: 'DeleteMultipleObjects',
|
|
271
|
+
Version: '2018-08-01',
|
|
272
|
+
method: 'POST',
|
|
273
|
+
headers: {
|
|
274
|
+
'content-type': 'application/xml',
|
|
275
|
+
},
|
|
276
|
+
query: {
|
|
277
|
+
Bucket: bucketName,
|
|
278
|
+
},
|
|
279
|
+
data: {
|
|
280
|
+
Delete: {
|
|
281
|
+
Object: objects,
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
continuationToken = listResult.NextContinuationToken;
|
|
287
|
+
} while (continuationToken);
|
|
288
|
+
await client.fetchOpenAPI({
|
|
289
|
+
Action: 'DeleteBucket',
|
|
290
|
+
Version: '2018-08-01',
|
|
291
|
+
method: 'DELETE',
|
|
292
|
+
query: {
|
|
293
|
+
Bucket: bucketName,
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
logger_1.logger.info(lang_1.lang.__('TOS_BUCKET_DELETED', { bucketName }));
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
if (error &&
|
|
300
|
+
typeof error === 'object' &&
|
|
301
|
+
'code' in error &&
|
|
302
|
+
(error.code === 'NoSuchBucket' || error.code === 'ResourceNotFound')) {
|
|
303
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', { resourceType: 'Bucket', name: bucketName }));
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
putObject: async (bucket, key, body) => {
|
|
310
|
+
if (!client) {
|
|
311
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
312
|
+
}
|
|
313
|
+
await client.fetchOpenAPI({
|
|
314
|
+
Action: 'PutObject',
|
|
315
|
+
Version: '2018-08-01',
|
|
316
|
+
method: 'PUT',
|
|
317
|
+
headers: {
|
|
318
|
+
'content-type': getContentType(key),
|
|
319
|
+
},
|
|
320
|
+
query: {
|
|
321
|
+
Bucket: bucket,
|
|
322
|
+
Key: key,
|
|
323
|
+
},
|
|
324
|
+
data: body,
|
|
325
|
+
});
|
|
326
|
+
},
|
|
327
|
+
listObjects: async (bucket, prefix) => {
|
|
328
|
+
if (!client) {
|
|
329
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
330
|
+
}
|
|
331
|
+
const objects = [];
|
|
332
|
+
let continuationToken;
|
|
333
|
+
do {
|
|
334
|
+
const response = await client.fetchOpenAPI({
|
|
335
|
+
Action: 'ListObjectsType2',
|
|
336
|
+
Version: '2018-08-01',
|
|
337
|
+
method: 'GET',
|
|
338
|
+
query: {
|
|
339
|
+
Bucket: bucket,
|
|
340
|
+
'list-type': '2',
|
|
341
|
+
...(prefix && { Prefix: prefix }),
|
|
342
|
+
...(continuationToken && { 'continuation-token': continuationToken }),
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
const result = (response.Result || {});
|
|
346
|
+
const contents = (result.Contents || []);
|
|
347
|
+
for (const obj of contents) {
|
|
348
|
+
objects.push({
|
|
349
|
+
key: obj.Key,
|
|
350
|
+
size: obj.Size,
|
|
351
|
+
lastModified: obj.LastModified,
|
|
352
|
+
etag: obj.ETag,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
continuationToken = result.NextContinuationToken;
|
|
356
|
+
} while (continuationToken);
|
|
357
|
+
return objects;
|
|
358
|
+
},
|
|
359
|
+
deleteObjects: async (bucket, keys) => {
|
|
360
|
+
if (!client) {
|
|
361
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
362
|
+
}
|
|
363
|
+
if (keys.length === 0)
|
|
364
|
+
return;
|
|
365
|
+
const objects = keys.map((key) => ({ Key: key }));
|
|
366
|
+
await client.fetchOpenAPI({
|
|
367
|
+
Action: 'DeleteMultipleObjects',
|
|
368
|
+
Version: '2018-08-01',
|
|
369
|
+
method: 'POST',
|
|
370
|
+
headers: {
|
|
371
|
+
'content-type': 'application/xml',
|
|
372
|
+
},
|
|
373
|
+
query: {
|
|
374
|
+
Bucket: bucket,
|
|
375
|
+
},
|
|
376
|
+
data: {
|
|
377
|
+
Delete: {
|
|
378
|
+
Object: objects,
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
});
|
|
382
|
+
},
|
|
383
|
+
uploadFiles: async (bucketName, sourcePath) => {
|
|
384
|
+
if (!client) {
|
|
385
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
386
|
+
}
|
|
387
|
+
const uploadDirectory = async (dirPath, prefix = '') => {
|
|
388
|
+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
389
|
+
for (const entry of entries) {
|
|
390
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
391
|
+
const objectKey = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
392
|
+
if (entry.isDirectory()) {
|
|
393
|
+
await uploadDirectory(fullPath, objectKey);
|
|
394
|
+
}
|
|
395
|
+
else if (entry.isFile()) {
|
|
396
|
+
const fileContent = fs.readFileSync(fullPath);
|
|
397
|
+
const contentType = getContentType(fullPath);
|
|
398
|
+
await client.fetchOpenAPI({
|
|
399
|
+
Action: 'PutObject',
|
|
400
|
+
Version: '2018-08-01',
|
|
401
|
+
method: 'PUT',
|
|
402
|
+
headers: {
|
|
403
|
+
'content-type': contentType,
|
|
404
|
+
},
|
|
405
|
+
query: {
|
|
406
|
+
Bucket: bucketName,
|
|
407
|
+
Key: objectKey,
|
|
408
|
+
},
|
|
409
|
+
data: fileContent,
|
|
410
|
+
});
|
|
411
|
+
logger_1.logger.debug(lang_1.lang.__('TOS_OBJECT_UPLOADED', { bucket: bucketName, key: objectKey }));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
const stats = fs.statSync(sourcePath);
|
|
416
|
+
if (stats.isDirectory()) {
|
|
417
|
+
await uploadDirectory(sourcePath);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
const fileName = path.basename(sourcePath);
|
|
421
|
+
const fileContent = fs.readFileSync(sourcePath);
|
|
422
|
+
await client.fetchOpenAPI({
|
|
423
|
+
Action: 'PutObject',
|
|
424
|
+
Version: '2018-08-01',
|
|
425
|
+
method: 'PUT',
|
|
426
|
+
headers: {
|
|
427
|
+
'content-type': getContentType(sourcePath),
|
|
428
|
+
},
|
|
429
|
+
query: {
|
|
430
|
+
Bucket: bucketName,
|
|
431
|
+
Key: fileName,
|
|
432
|
+
},
|
|
433
|
+
data: fileContent,
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
logger_1.logger.info(lang_1.lang.__('TOS_FILES_UPLOADED', { bucket: bucketName, path: sourcePath }));
|
|
437
|
+
},
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
exports.createTosOperations = createTosOperations;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildVolcengineEndpoint = exports.VOLCENGINE_REGIONS = void 0;
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Volcengine Regions
|
|
6
|
+
// ============================================================================
|
|
7
|
+
/**
|
|
8
|
+
* Supported Volcengine regions
|
|
9
|
+
* @see https://www.volcengine.com/docs/6662/107381
|
|
10
|
+
*/
|
|
11
|
+
exports.VOLCENGINE_REGIONS = {
|
|
12
|
+
CN_BEIJING: 'cn-beijing',
|
|
13
|
+
CN_SHANGHAI: 'cn-shanghai',
|
|
14
|
+
CN_GUANGZHOU: 'cn-guangzhou',
|
|
15
|
+
AP_SOUTHEAST_1: 'ap-southeast-1',
|
|
16
|
+
};
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Volcengine Endpoints
|
|
19
|
+
// ============================================================================
|
|
20
|
+
/**
|
|
21
|
+
* Build service endpoint for Volcengine services
|
|
22
|
+
*/
|
|
23
|
+
const buildVolcengineEndpoint = (service, region) => {
|
|
24
|
+
return `${service}.${region}.volces.com`;
|
|
25
|
+
};
|
|
26
|
+
exports.buildVolcengineEndpoint = buildVolcengineEndpoint;
|