@hocuspocus/extension-s3 3.4.5-rc.0 → 3.4.6-rc.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/package.json +2 -2
- package/dist/index.js +0 -97
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/extension-s3",
|
|
3
3
|
"description": "a S3-compatible persistence driver for Hocuspocus",
|
|
4
|
-
"version": "3.4.
|
|
4
|
+
"version": "3.4.6-rc.1",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"hocuspocus",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@aws-sdk/client-s3": "^3.981.0",
|
|
33
|
-
"@hocuspocus/extension-database": "^3.4.
|
|
33
|
+
"@hocuspocus/extension-database": "^3.4.6-rc.1",
|
|
34
34
|
"kleur": "^4.1.4"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
package/dist/index.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { Database } from "@hocuspocus/extension-database";
|
|
2
|
-
import { GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
3
|
-
import kleur from "kleur";
|
|
4
|
-
|
|
5
|
-
//#region packages/extension-s3/src/S3.ts
|
|
6
|
-
var S3 = class extends Database {
|
|
7
|
-
constructor(configuration) {
|
|
8
|
-
super({});
|
|
9
|
-
this.configuration = {
|
|
10
|
-
region: "us-east-1",
|
|
11
|
-
bucket: "",
|
|
12
|
-
prefix: "hocuspocus-documents/",
|
|
13
|
-
forcePathStyle: false,
|
|
14
|
-
fetch: async ({ documentName }) => {
|
|
15
|
-
const key = this.getObjectKey(documentName);
|
|
16
|
-
try {
|
|
17
|
-
const command = new GetObjectCommand({
|
|
18
|
-
Bucket: this.configuration.bucket,
|
|
19
|
-
Key: key
|
|
20
|
-
});
|
|
21
|
-
const response = await this.s3Client.send(command);
|
|
22
|
-
if (response.Body) {
|
|
23
|
-
const chunks = [];
|
|
24
|
-
const reader = response.Body.transformToWebStream().getReader();
|
|
25
|
-
while (true) {
|
|
26
|
-
const { done, value } = await reader.read();
|
|
27
|
-
if (done) break;
|
|
28
|
-
chunks.push(value);
|
|
29
|
-
}
|
|
30
|
-
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
31
|
-
const result = new Uint8Array(totalLength);
|
|
32
|
-
let offset = 0;
|
|
33
|
-
for (const chunk of chunks) {
|
|
34
|
-
result.set(chunk, offset);
|
|
35
|
-
offset += chunk.length;
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
if (error.name === "NoSuchKey" || error.$metadata?.httpStatusCode === 404) return null;
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
store: async ({ documentName, state }) => {
|
|
46
|
-
const key = this.getObjectKey(documentName);
|
|
47
|
-
const command = new PutObjectCommand({
|
|
48
|
-
Bucket: this.configuration.bucket,
|
|
49
|
-
Key: key,
|
|
50
|
-
Body: state,
|
|
51
|
-
ContentType: "application/octet-stream"
|
|
52
|
-
});
|
|
53
|
-
await this.s3Client.send(command);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
this.configuration = {
|
|
57
|
-
...this.configuration,
|
|
58
|
-
...configuration
|
|
59
|
-
};
|
|
60
|
-
if (!this.configuration.bucket) throw new Error("S3 bucket name is required");
|
|
61
|
-
}
|
|
62
|
-
getObjectKey(documentName) {
|
|
63
|
-
return `${this.configuration.prefix || ""}${documentName}.bin`;
|
|
64
|
-
}
|
|
65
|
-
async onConfigure() {
|
|
66
|
-
if (this.configuration.s3Client) this.s3Client = this.configuration.s3Client;
|
|
67
|
-
else {
|
|
68
|
-
const clientConfig = { region: this.configuration.region };
|
|
69
|
-
if (this.configuration.credentials) clientConfig.credentials = this.configuration.credentials;
|
|
70
|
-
if (this.configuration.endpoint) {
|
|
71
|
-
clientConfig.endpoint = this.configuration.endpoint;
|
|
72
|
-
clientConfig.forcePathStyle = this.configuration.forcePathStyle;
|
|
73
|
-
}
|
|
74
|
-
this.s3Client = new S3Client(clientConfig);
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
const command = new HeadObjectCommand({
|
|
78
|
-
Bucket: this.configuration.bucket,
|
|
79
|
-
Key: "test-connection"
|
|
80
|
-
});
|
|
81
|
-
await this.s3Client.send(command);
|
|
82
|
-
} catch (error) {
|
|
83
|
-
if (error.$metadata?.httpStatusCode !== 404) if (error.message?.includes("Could not load credentials")) {
|
|
84
|
-
console.warn(` ${kleur.yellow("S3 warning:")} ${error.message}`);
|
|
85
|
-
console.warn(` ${kleur.yellow("Note:")} Ensure AWS credentials are properly configured for production use`);
|
|
86
|
-
} else console.error(` ${kleur.red("S3 connection failed:")} ${error.message}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async onListen() {
|
|
90
|
-
const endpoint = this.configuration.endpoint || `https://s3.${this.configuration.region}.amazonaws.com`;
|
|
91
|
-
console.log(` ${kleur.green("S3 extension configured:")} bucket=${this.configuration.bucket}, endpoint=${endpoint}`);
|
|
92
|
-
if (this.configuration.prefix) console.log(` ${kleur.blue("S3 key prefix:")} ${this.configuration.prefix}`);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
//#endregion
|
|
97
|
-
export { S3 };
|