ag-common 0.0.738 → 0.0.739
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/api/helpers/s3.d.ts +1 -2
- package/dist/api/helpers/s3.js +13 -10
- package/package.json +1 -1
package/dist/api/helpers/s3.d.ts
CHANGED
|
@@ -16,8 +16,7 @@ export type StorageConfig = {
|
|
|
16
16
|
secretAccessKey?: string;
|
|
17
17
|
};
|
|
18
18
|
export declare const createStorageClient: (config: StorageConfig) => S3Client;
|
|
19
|
-
export declare const setS3: (config: StorageConfig) =>
|
|
20
|
-
export declare const s3: S3Client;
|
|
19
|
+
export declare const setS3: (config: StorageConfig) => void;
|
|
21
20
|
export declare const getS3Object: ({ fileurl: { Bucket, Key }, }: {
|
|
22
21
|
fileurl: {
|
|
23
22
|
Bucket: string;
|
package/dist/api/helpers/s3.js
CHANGED
|
@@ -22,7 +22,7 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
22
22
|
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.copyFile = exports.deleteFiles = exports.deleteFile = exports.putS3Object = exports.getS3Object = exports.
|
|
25
|
+
exports.copyFile = exports.deleteFiles = exports.deleteFile = exports.putS3Object = exports.getS3Object = exports.setS3 = exports.createStorageClient = void 0;
|
|
26
26
|
exports.getS3Objects = getS3Objects;
|
|
27
27
|
exports.listFiles = listFiles;
|
|
28
28
|
exports.getPresignedPostURL = getPresignedPostURL;
|
|
@@ -77,15 +77,18 @@ const createStorageClient = (config) => {
|
|
|
77
77
|
return client;
|
|
78
78
|
};
|
|
79
79
|
exports.createStorageClient = createStorageClient;
|
|
80
|
-
|
|
80
|
+
let s3;
|
|
81
|
+
const setS3 = (config) => {
|
|
82
|
+
s3 = (0, exports.createStorageClient)(config);
|
|
83
|
+
};
|
|
81
84
|
exports.setS3 = setS3;
|
|
82
|
-
|
|
85
|
+
(0, exports.setS3)({
|
|
83
86
|
provider: 's3',
|
|
84
87
|
region: 'ap-southeast-2',
|
|
85
88
|
});
|
|
86
89
|
const getS3Object = (_a) => __awaiter(void 0, [_a], void 0, function* ({ fileurl: { Bucket, Key }, }) {
|
|
87
90
|
try {
|
|
88
|
-
const r = yield
|
|
91
|
+
const r = yield s3.send(new client_s3_1.GetObjectCommand({ Bucket, Key }));
|
|
89
92
|
if (!r.Body) {
|
|
90
93
|
throw new Error('no body returned');
|
|
91
94
|
}
|
|
@@ -124,7 +127,7 @@ function getS3Objects(_a) {
|
|
|
124
127
|
}
|
|
125
128
|
const putS3Object = (_a) => __awaiter(void 0, [_a], void 0, function* ({ Body, Bucket, Key, ContentType, CacheControl = 'public, max-age=300', }) {
|
|
126
129
|
try {
|
|
127
|
-
yield
|
|
130
|
+
yield s3.send(new client_s3_1.PutObjectCommand({ Body, Bucket, Key, ContentType, CacheControl }));
|
|
128
131
|
return {};
|
|
129
132
|
}
|
|
130
133
|
catch (e) {
|
|
@@ -134,7 +137,7 @@ const putS3Object = (_a) => __awaiter(void 0, [_a], void 0, function* ({ Body, B
|
|
|
134
137
|
exports.putS3Object = putS3Object;
|
|
135
138
|
const deleteFile = (_a) => __awaiter(void 0, [_a], void 0, function* ({ Bucket, Key, }) {
|
|
136
139
|
try {
|
|
137
|
-
yield
|
|
140
|
+
yield s3.send(new client_s3_1.DeleteObjectCommand({ Bucket, Key }));
|
|
138
141
|
return {};
|
|
139
142
|
}
|
|
140
143
|
catch (e) {
|
|
@@ -150,7 +153,7 @@ const deleteFiles = (_a) => __awaiter(void 0, [_a], void 0, function* ({ Bucket,
|
|
|
150
153
|
while (toDelete.length > 0) {
|
|
151
154
|
const { part, rest } = (0, array_1.take)(toDelete, 900);
|
|
152
155
|
toDelete = rest;
|
|
153
|
-
const res = yield
|
|
156
|
+
const res = yield s3.send(new client_s3_1.DeleteObjectsCommand({
|
|
154
157
|
Bucket,
|
|
155
158
|
Delete: { Objects: part },
|
|
156
159
|
}));
|
|
@@ -170,7 +173,7 @@ exports.deleteFiles = deleteFiles;
|
|
|
170
173
|
const copyFile = (_a) => __awaiter(void 0, [_a], void 0, function* ({ Bucket, fromKey, toKey, deleteSource = false, }) {
|
|
171
174
|
try {
|
|
172
175
|
(0, log_1.debug)(`copying s3 file from ${Bucket}- ${fromKey} to ${toKey}`);
|
|
173
|
-
yield
|
|
176
|
+
yield s3.send(new client_s3_1.CopyObjectCommand({
|
|
174
177
|
//incl bucket
|
|
175
178
|
CopySource: Bucket + '/' + fromKey,
|
|
176
179
|
//dest
|
|
@@ -197,7 +200,7 @@ function listFiles(bucketName, opt) {
|
|
|
197
200
|
const ret = [];
|
|
198
201
|
let response;
|
|
199
202
|
do {
|
|
200
|
-
response = yield
|
|
203
|
+
response = yield s3.send(new client_s3_1.ListObjectsV2Command({
|
|
201
204
|
Bucket: bucketName,
|
|
202
205
|
ContinuationToken: response === null || response === void 0 ? void 0 : response.NextContinuationToken,
|
|
203
206
|
Prefix: opt === null || opt === void 0 ? void 0 : opt.prefix,
|
|
@@ -230,7 +233,7 @@ function listFiles(bucketName, opt) {
|
|
|
230
233
|
function getPresignedPostURL(_a) {
|
|
231
234
|
return __awaiter(this, arguments, void 0, function* ({ bucket, key, maxMb = 5, }) {
|
|
232
235
|
try {
|
|
233
|
-
const ps = yield (0, s3_presigned_post_1.createPresignedPost)(
|
|
236
|
+
const ps = yield (0, s3_presigned_post_1.createPresignedPost)(s3, {
|
|
234
237
|
Bucket: bucket,
|
|
235
238
|
Key: key,
|
|
236
239
|
Expires: 600,
|
package/package.json
CHANGED