@certik/skynet 0.14.0 → 0.15.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/.vscode/settings.json +5 -0
- package/CHANGELOG.md +5 -0
- package/bun.lockb +0 -0
- package/examples/api.js +0 -0
- package/examples/consumer.js +0 -0
- package/examples/indexer.js +0 -0
- package/examples/mode-indexer.js +0 -0
- package/examples/producer.js +0 -0
- package/package.json +1 -1
- package/s3.js +26 -10
package/CHANGELOG.md
CHANGED
package/bun.lockb
CHANGED
|
Binary file
|
package/examples/api.js
CHANGED
|
File without changes
|
package/examples/consumer.js
CHANGED
|
File without changes
|
package/examples/indexer.js
CHANGED
|
File without changes
|
package/examples/mode-indexer.js
CHANGED
|
File without changes
|
package/examples/producer.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/s3.js
CHANGED
|
@@ -6,11 +6,17 @@ import {
|
|
|
6
6
|
DeleteObjectCommand,
|
|
7
7
|
ListObjectsV2Command,
|
|
8
8
|
NotFound,
|
|
9
|
+
NoSuchKey,
|
|
9
10
|
} from "@aws-sdk/client-s3";
|
|
10
11
|
import { getAWSSDKConfig } from "./env.js";
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
let _s3Client;
|
|
14
|
+
|
|
15
|
+
function getS3(forceNew = false) {
|
|
16
|
+
if (!_s3Client || forceNew) {
|
|
17
|
+
_s3Client = new S3Client(getAWSSDKConfig());
|
|
18
|
+
}
|
|
19
|
+
return _s3Client;
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
async function readFile(bucketName, key, verbose = false) {
|
|
@@ -21,12 +27,16 @@ async function readFile(bucketName, key, verbose = false) {
|
|
|
21
27
|
try {
|
|
22
28
|
const result = await s3.send(new GetObjectCommand(params));
|
|
23
29
|
return result.Body.transformToString();
|
|
24
|
-
} catch (
|
|
25
|
-
if (
|
|
26
|
-
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof NoSuchKey) {
|
|
32
|
+
if (verbose) {
|
|
33
|
+
console.log("no such bucket or key", bucketName, key);
|
|
34
|
+
}
|
|
35
|
+
// do nothing
|
|
36
|
+
return null;
|
|
27
37
|
}
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
|
|
39
|
+
throw error;
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
42
|
|
|
@@ -93,10 +103,16 @@ async function deleteFile(bucketName, key, verbose = false) {
|
|
|
93
103
|
|
|
94
104
|
try {
|
|
95
105
|
await s3.send(new DeleteObjectCommand(params));
|
|
96
|
-
} catch (
|
|
97
|
-
if (
|
|
98
|
-
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (error instanceof NoSuchKey) {
|
|
108
|
+
if (verbose) {
|
|
109
|
+
console.log("no such bucket or key", bucketName, key);
|
|
110
|
+
}
|
|
111
|
+
// do nothing
|
|
112
|
+
return null;
|
|
99
113
|
}
|
|
114
|
+
|
|
115
|
+
throw error;
|
|
100
116
|
}
|
|
101
117
|
}
|
|
102
118
|
|