Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat: add s3 compatible blob storage

tianma-if9d8797c27e2d
diff --git a/.env.local.example b/.env.local.example
index 274d9626..ff777b05 100644
--- a/.env.local.example
+++ b/.env.local.example
@@ -49,6 +49,14 @@ EDGE_EVER_DATA_DIR=.edgeever-data
EDGE_EVER_SQLITE_FILE=.edgeever-data/edgeever.sqlite
EDGE_EVER_RESOURCES_DIR=.edgeever-data/resources
EDGE_EVER_PORT=8787
+# Set to `s3` for AWS S3, MinIO, R2, OSS, or COS through the S3-compatible API.
+EDGE_EVER_STORAGE_BACKEND=local
+EDGE_EVER_S3_ENDPOINT=
+EDGE_EVER_S3_REGION=us-east-1
+EDGE_EVER_S3_BUCKET=
+EDGE_EVER_S3_ACCESS_KEY_ID=
+EDGE_EVER_S3_SECRET_ACCESS_KEY=
+EDGE_EVER_S3_FORCE_PATH_STYLE=false
# Multi-instance deployments
# Select remote instances per command, for example:
diff --git a/apps/api/src/s3-compatible-storage-adapter.ts b/apps/api/src/s3-compatible-storage-adapter.ts
new file mode 100644
index 00000000..2702d4d1
--- /dev/null
+++ b/apps/api/src/s3-compatible-storage-adapter.ts
@@ -0,0 +1,130 @@
+import {
+ DeleteObjectsCommand,
+ GetObjectCommand,
+ PutObjectCommand,
+ S3Client,
+} from "@aws-sdk/client-s3";
+import type { Readable } from "node:stream";
+import type { BlobStoreAdapter, BlobObjectAdapter, StorageAdapter } from "./storage-contract";
+import type { SqliteDatabaseLike } from "./self-hosted-storage-adapter";
+import { createSelfHostedStorageAdapter } from "./self-hosted-storage-adapter";
+
+export type S3CompatibleStorageConfig = {
+ bucket: string;
+ region?: string;
+ endpoint?: string;
+ accessKeyId?: string;
+ secretAccessKey?: string;
+ forcePathStyle?: boolean;
+};
+
+type S3Body = {
+ transformToWebStream?: () => ReadableStream<Uint8Array>;
+ transformToByteArray?: () => Promise<Uint8Array>;
+};
+
+const toWebStream = async (body: unknown): Promise<ReadableStream<Uint8Array>> => {
+ const candidate = body as S3Body | ReadableStream<Uint8Array> | Readable | Blob | Uint8Array;
+
+ if (candidate && typeof (candidate as S3Body).transformToWebStream === "function") {
+ return (candidate as S3Body).transformToWebStream!();
+ }
+
+ if (candidate instanceof ReadableStream) {
+ return candidate;
+ }
+
+ if (candidate instanceof Blob) {
+ return candidate.stream() as ReadableStream<Uint8Array>;
+ }
+
+ if (candidate instanceof Uint8Array) {
+ return new Blob([candidate as never]).stream() as ReadableStream<Uint8Array>;
+ }
+
+ if (candidate && typeof (candidate as S3Body).transformToByteArray === "function") {
+ return new Blob([await (candidate as S3Body).transformToByteArray!() as never]).stream() as ReadableStream<Uint8Array>;
+ }
+
+ return new Response(candidate as BodyInit).body as ReadableStream<Uint8Array>;
+};
+
+const isMissingObjectError = (error: unknown) => {
+ const candidate = error as { name?: string; $metadata?: { httpStatusCode?: number } };
+ return candidate.name === "NoSuchKey"
+ || candidate.name === "NotFound"
+ || candidate.$metadata?.httpStatusCode === 404;
+};
+
+const createS3BlobStore = (
+ config: S3CompatibleStorageConfig,
+ client = new S3Client({
+ region: config.region ?? "us-east-1",
+ endpoint: config.endpoint,
+ forcePathStyle: config.forcePathStyle ?? Boolean(config.endpoint),
+ credentials: config.accessKeyId && config.secretAccessKey
+ ? { accessKeyId: config.accessKeyId, secretAccessKey: config.secretAccessKey }
+ : undefined,
+ }),
+): BlobStoreAdapter => ({
+ async get(objectKey): Promise<BlobObjectAdapter | null> {
+ try {
+ const result = await client.send(new GetObjectCommand({ Bucket: config.bucket, Key: objectKey }));
+ if (!result.Body) {
+ return null;
+ }
+
+ const body = await toWebStream(result.Body);
+ return {
+ body,
+ size: result.ContentLength ?? 0,
+ writeHttpMetadata: (headers) => {
+ if (result.ContentType) headers.set("Content-Type", result.ContentType);
+ if (result.CacheControl) headers.set("Cache-Control", result.CacheControl);
+ if (result.ContentDisposition) headers.set("Content-Disposition", result.ContentDisposition);
+ if (result.ETag) headers.set("ETag", result.ETag);
+ if (result.LastModified) headers.set("Last-Modified", result.LastModified.toUTCString());
+ },
+ };
+ } catch (error) {
+ if (isMissingObjectError(error)) return null;
+ throw error;
+ }
+ },
+
+ async put(objectKey, value, options) {
+ const metadata = options as { httpMetadata?: Record<string, string> } | undefined;
+ const httpMetadata = metadata?.httpMetadata ?? {};
+ await client.send(new PutObjectCommand({
+ Bucket: config.bucket,
+ Key: objectKey,
+ Body: value as never,
+ ContentType: httpMetadata.contentType,
+ CacheControl: httpMetadata.cacheControl,
+ ContentDisposition: httpMetadata.contentDisposition,
+ }));
+ },
+
+ async delete(objectKeys) {
+ const keys = Array.isArray(objectKeys) ? objectKeys : [objectKeys];
+ for (let index = 0; index < keys.length; index += 1000) {
+ await client.send(new DeleteObjectsCommand({
+ Bucket: config.bucket,
+ Delete: { Objects: keys.slice(index, index + 1000).map((Key) => ({ Key })) },
+ }));
+ }
+ },
+});
+
+/**
+ * S3-compatible storage for self-hosted deployments. The SQLite adapter is
+ * reused for metadata while objects are stored in S3/MinIO/OSS/COS/R2.
+ */
+export const createS3CompatibleStorageAdapter = (
+ sqlite: SqliteDatabaseLike,
+ config: S3CompatibleStorageConfig,
+ client?: S3Client,
+): StorageAdapter => ({
+ db: createSelfHostedStorageAdapter(sqlite, ".edgeever-unused-resources").db,
+ resources: createS3BlobStore(config, client),
+});
diff --git a/bun.lock b/bun.lock
index a9b3f4bf..f8d2cf20 100644
--- a/bun.lock
+++ b/bun.lock
@@ -5,6 +5,7 @@
"": {
"name": "edgeever",
"dependencies": {
+ "@aws-sdk/client-s3": "^3.1095.0",
"@edgeever/shared": "workspace:*",
"@hono/zod-validator": "latest",
"@radix-ui/react-checkbox": "^1.3.5",
@@ -227,6 +228,42 @@
"@astrojs/yaml2ts": ["@astrojs/[email protected]", "", { "dependencies": { "yaml": "^2.8.3" } }, "sha512-8oddpOae35pJsXPQXhTkM0ypfKPskVsh2bCxRtbf7e+/Epw2nReakFYpLKjZMEr75CsoF203PMnCocpfz0s69A=="],
+ "@aws-sdk/checksums": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-uc5PMNcLcs+UBSLGsRjbMZKi3mgnPSalXpABw9Xjo0DMrv4gjIa/E4a02yJsuU4FF6Tmvis/JgGdKNIOoN4DQw=="],
+
+ "@aws-sdk/client-s3": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/checksums": "^3.1000.20", "@aws-sdk/core": "^3.977.0", "@aws-sdk/credential-provider-node": "^3.972.72", "@aws-sdk/middleware-sdk-s3": "^3.972.66", "@aws-sdk/signature-v4-multi-region": "^3.996.42", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/fetch-http-handler": "^5.6.10", "@smithy/node-http-handler": "^4.9.10", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-eeobm3TKci47CTTHIxc5s5UDjLL0gTKfjlcyzKU+NMoeIJ3flKPq51Fhi2nUDiMNbzsY5HAynM3bHAQFHxRTUw=="],
+
+ "@aws-sdk/core": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/types": "^3.974.2", "@aws-sdk/xml-builder": "^3.972.37", "@aws/lambda-invoke-store": "^0.3.0", "@smithy/core": "^3.29.8", "@smithy/signature-v4": "^5.6.9", "@smithy/types": "^4.16.1", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-KVtQRtc00ES/y+Sc3vYXeP6pCIcNlBJCZOwvqSy8ZpVGmbM5+IG+AfhuTKQ2oXmIVqZJewaGMMpzPkywC6xg0w=="],
+
+ "@aws-sdk/credential-provider-env": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-qihs2ekMb89Nxd2JenCgVFhjbkb3EIo7HEBCBzyZACKVJdrLUZBLOmAE3xr0Sayml8n/jZSzwO/IufIiIzO7PQ=="],
+
+ "@aws-sdk/credential-provider-http": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/fetch-http-handler": "^5.6.10", "@smithy/node-http-handler": "^4.9.10", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-yfozsS8wkWZEi/n6IsrodcFKBWZ0iNAezhJbTReMNc0z1Px17qdeAeuL1/wziCAmCZyXiW7QzP75ggJkBQv8jQ=="],
+
+ "@aws-sdk/credential-provider-ini": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/credential-provider-env": "^3.972.61", "@aws-sdk/credential-provider-http": "^3.972.63", "@aws-sdk/credential-provider-login": "^3.972.68", "@aws-sdk/credential-provider-process": "^3.972.61", "@aws-sdk/credential-provider-sso": "^3.973.5", "@aws-sdk/credential-provider-web-identity": "^3.972.67", "@aws-sdk/nested-clients": "^3.997.35", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/credential-provider-imds": "^4.4.13", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-jGLTW1bj148GL/6/IMlfY2fMYS9FtHOG+NahkFD4y0qkzYudNUahelxryY68/HGMslYuHClk1XaS/3b3eJzEkg=="],
+
+ "@aws-sdk/credential-provider-login": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/nested-clients": "^3.997.35", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-w6tNci6g7RqFpLhj1f5xseBvaNojb4Pkgp5Jp5apl9hrJtaf2AA+rX9+qlhlWUK6kcyAFYPA7emO+55zj+S98Q=="],
+
+ "@aws-sdk/credential-provider-node": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/credential-provider-env": "^3.972.61", "@aws-sdk/credential-provider-http": "^3.972.63", "@aws-sdk/credential-provider-ini": "^3.973.6", "@aws-sdk/credential-provider-process": "^3.972.61", "@aws-sdk/credential-provider-sso": "^3.973.5", "@aws-sdk/credential-provider-web-identity": "^3.972.67", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/credential-provider-imds": "^4.4.13", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-blQ7F5QGzylnzeh5549zQLoCAiMHkXFLjFovEMaVy4b2X8JhUu+u9NXro1hyK95YHdVFNmBHKs2hIHtZchxKlQ=="],
+
+ "@aws-sdk/credential-provider-process": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-xzRuj+fUVO4nkafKQJVKAF97kGpeQbfjuwmRrtGZNf42/1dkmcz6o7dswBy7alY0htQn5sCL1GWQYEykviWZkA=="],
+
+ "@aws-sdk/credential-provider-sso": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/nested-clients": "^3.997.35", "@aws-sdk/token-providers": "3.1095.0", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-fZRjjWhLFelsDoOYjqShQTrIGYC3Pf9Mx9Czf+1ikfQDgktxjze33dVo1q1/ZQ+T0qbtejVoHNHrfD5aJVpv/w=="],
+
+ "@aws-sdk/credential-provider-web-identity": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/nested-clients": "^3.997.35", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-FTNZ05gkPBA6CKbU3N4zPgybV+stdazwMOya75CmGdcJL7p8Fw/BdHP8WVxJd0mvzyPK2cg/C3gli58Ir4HgCw=="],
+
+ "@aws-sdk/middleware-sdk-s3": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/signature-v4-multi-region": "^3.996.42", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-sTZKP1+SvyzWc/3alO8AM/PUiEzDCmn2P/KOcFFSk2UKzKZkB5ZxXdlHVtACE7DHaMFvx6DY0bognwHa1qTv4g=="],
+
+ "@aws-sdk/nested-clients": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/signature-v4-multi-region": "^3.996.42", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/fetch-http-handler": "^5.6.10", "@smithy/node-http-handler": "^4.9.10", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-2MJfseVG/aXvIyOIBlYA/Oaf6qFDdsu4D8RKsEUdOQpVuLaor0BdxIBBtJLBNQQEe6Ku3YMvLljwb1MwVUpzRw=="],
+
+ "@aws-sdk/signature-v4-multi-region": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/types": "^3.974.2", "@smithy/signature-v4": "^5.6.9", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-DBV4naZP6HYBlAvPpoQzOP12Wvfou/5rN8yJPXjBTBylU5qwCbh/tXr2MddHoIjgoRkEl/eS+IljiUqvmwey1Q=="],
+
+ "@aws-sdk/token-providers": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/core": "^3.977.0", "@aws-sdk/nested-clients": "^3.997.35", "@aws-sdk/types": "^3.974.2", "@smithy/core": "^3.29.8", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-65SudS6y4nzaYHybtqcpm3sHe5jLhdMn68HRKS1nUx690BtQeaAQOoujQ+dpOjBATIVGVgKKjEP8tR+U06QJQA=="],
+
+ "@aws-sdk/types": ["@aws-sdk/[email protected]", "", { "dependencies": { "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-3W6IUtSxFbH6X7Wb7DzGCV5QiFQsd0g8bOfntpmDxQlzBoKWUMBu/JPQR0DwkE+Hpnxd6db1tXbOwdeHddG6cA=="],
+
+ "@aws-sdk/xml-builder": ["@aws-sdk/[email protected]", "", { "dependencies": { "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-zKq4HQum8JwDyEuyfuI4bbiAcU0KxP6qy+9PR/IsR92IyE/DaBAikzAS50tjxip4bqIIANpCcG+Yyj6CVhXupg=="],
+
+ "@aws/lambda-invoke-store": ["@aws/[email protected]", "", {}, "sha512-sl4Bm6yiMNYrZKkqqDFWN0UfnWhlS8ivKxrYl+6t0gCLrqr8y3B2IqZZbFRkfaVVp7C/baApyh71P+LeE1A2sQ=="],
+
"@babel/code-frame": ["@babel/[email protected]", "", { "dependencies": { "@babel/helper-validator-identifier": "^7.29.7", "js-tokens": "^4.0.0", "picocolors": "^1.1.1" } }, "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw=="],
"@babel/compat-data": ["@babel/[email protected]", "", {}, "sha512-locTkQyKvwIEgBzVrn8693ebc97F2U8ZHjbXwDXJ5Fn2TCpNwTlKcaKLkdHop5c/icOFE7qt7Q9JC5hnKNa6Gg=="],
@@ -1013,6 +1050,18 @@
"@sindresorhus/is": ["@sindresorhus/[email protected]", "", {}, "sha512-P1Cz1dWaFfR4IR+U13mqqiGsLFf1KbayybWwdd2vfctdV6hDpUkgCY0nKOLLTMSoRd/jJNjtbqzf13K8DCCXQw=="],
+ "@smithy/core": ["@smithy/[email protected]", "", { "dependencies": { "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-dl2yRglDxfzH9uJ4fSo4zTaAHa0zH7+V7BZMRWy8hEYIKT1BiqMUK/CN6T3ADQ3kbA5N1tmUulroJ2UtONS7Kw=="],
+
+ "@smithy/credential-provider-imds": ["@smithy/[email protected]", "", { "dependencies": { "@smithy/core": "^3.30.0", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-QgbuahIb2qxQeZQvNK0sw3aF3JH5zwH8j2lLp5DUasVXexGGMWULAR+7z0omPXFolCP/m5wN9M5lm9EGdSviTQ=="],
+
+ "@smithy/fetch-http-handler": ["@smithy/[email protected]", "", { "dependencies": { "@smithy/core": "^3.30.0", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-o0Zkj1nKqJAoq+a+BrkhU39tRftMNjLwpc/z06Frfl43wpbHrJMaSAVZE4vTqlxtVkNaGaT0bIDxOp7tkFTuQQ=="],
+
+ "@smithy/node-http-handler": ["@smithy/[email protected]", "", { "dependencies": { "@smithy/core": "^3.30.0", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-slbzbz8taEOzoXv/9y34YNBoE+ZHmddLykCgjDAjvMAsu2nM5s2Gzwa5OGF721tD8s+CKeFUBds5lSj9lcbuDg=="],
+
+ "@smithy/signature-v4": ["@smithy/[email protected]", "", { "dependencies": { "@smithy/core": "^3.30.0", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-EXhWePm3SXJAX38npIy4TXL2Aex/OVgCClTjelN2QHw/U+8CQUH8C7AaxsVzQcYieYPseywn48s89DmvuGjiAg=="],
+
+ "@smithy/types": ["@smithy/[email protected]", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-0JFs3V2y2M9tKW5na/qxe69Zv+uxLMO7QBbhxF/FHu/Gp2NFZAAL9tWl9PU02xxo07pb3G9FTyjNc6D5uZrJIg=="],
+
"@speed-highlight/core": ["@speed-highlight/[email protected]", "", {}, "sha512-Z92FwKpCtfaW1V0jTU/fh3QzYEZN8wDwrzRIBoADCJfn4mJCNcJN/XegifX7BDrQ8/h9Xh/JnbyMchL0FqXrkg=="],
"@swc/helpers": ["@swc/[email protected]", "", { "dependencies": { "tslib": "^2.8.0" } }, "sha512-5lSsMOTXURePglDfvuAQUqkGek9Hg2kksOYay2m0+XR++b2NWYL/4sWyuvVBIs8oKnJaxkdi9whaL/sqN13afw=="],
@@ -1403,6 +1452,8 @@
"boolbase": ["[email protected]", "", {}, "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww=="],
+ "bowser": ["[email protected]", "", {}, "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg=="],
+
"boxen": ["[email protected]", "", { "dependencies": { "ansi-align": "^3.0.1", "camelcase": "^8.0.0", "chalk": "^5.3.0", "cli-boxes": "^3.0.0", "string-width": "^7.2.0", "type-fest": "^4.21.0", "widest-line": "^5.0.0", "wrap-ansi": "^9.0.0" } }, "sha512-F3PH5k5juxom4xktynS7MoFY+NUWH5LC4CnH11YB8NPew+HLpmBLCybSAEyb2F+4pRXhuhWqFesoQd6DAyc2hw=="],
"bplist-creator": ["[email protected]", "", { "dependencies": { "stream-buffers": "2.2.x" } }, "sha512-sXaHZicyEEmY86WyueLTQesbeoH/mquvarJaQNbjuOQO+7gbFcDEWqKmcWA4cOTLzFlfgvkiVxolk1k5bBIpmg=="],
diff --git a/docs/self-hosting-architecture.md b/docs/self-hosting-architecture.md
index 6bd9db5d..f9896d09 100644
--- a/docs/self-hosting-architecture.md
+++ b/docs/self-hosting-architecture.md
@@ -76,3 +76,18 @@ EDGE_EVER_AUTH_PASSWORD='<strong-password>' bun run start:self-hosted
Set `EDGE_EVER_DATA_DIR` to the directory that should be persisted by Docker
or a NAS volume. This runtime is not yet a supported release artifact.
+
+The same runtime can use an S3-compatible object store:
+
+```sh
+EDGE_EVER_STORAGE_BACKEND=s3 \
+EDGE_EVER_S3_ENDPOINT='http://minio:9000' \
+EDGE_EVER_S3_REGION='us-east-1' \
+EDGE_EVER_S3_BUCKET='edgeever' \
+EDGE_EVER_S3_ACCESS_KEY_ID='<access-key>' \
+EDGE_EVER_S3_SECRET_ACCESS_KEY='<secret-key>' \
+bun run start:self-hosted
+```
+
+The implementation uses `@aws-sdk/client-s3` and does not load that SDK in the
+Cloudflare Worker entrypoint.
diff --git a/docs/self-hosting-architecture.zh-CN.md b/docs/self-hosting-architecture.zh-CN.md
index 2f4b5fc3..141a3289 100644
--- a/docs/self-hosting-architecture.zh-CN.md
+++ b/docs/self-hosting-architecture.zh-CN.md
@@ -63,3 +63,17 @@ EDGE_EVER_AUTH_PASSWORD='<强密码>' bun run start:self-hosted
可通过 `EDGE_EVER_DATA_DIR` 指定需要由 Docker 或 NAS 卷持久化的目录。该入口
目前仍不是正式支持的发行物。
+
+同一个入口也可以使用 S3 兼容对象存储:
+
+```sh
+EDGE_EVER_STORAGE_BACKEND=s3 \
+EDGE_EVER_S3_ENDPOINT='http://minio:9000' \
+EDGE_EVER_S3_REGION='us-east-1' \
+EDGE_EVER_S3_BUCKET='edgeever' \
+EDGE_EVER_S3_ACCESS_KEY_ID='<access-key>' \
+EDGE_EVER_S3_SECRET_ACCESS_KEY='<secret-key>' \
+bun run start:self-hosted
+```
+
+实现使用 `@aws-sdk/client-s3`,Cloudflare Worker 入口不会加载该 SDK。
diff --git a/package.json b/package.json
index e5a70a08..6ebd180d 100644
--- a/package.json
+++ b/package.json
@@ -69,6 +69,7 @@
}
},
"dependencies": {
+ "@aws-sdk/client-s3": "^3.1095.0",
"@edgeever/shared": "workspace:*",
"@hono/zod-validator": "latest",
"@radix-ui/react-checkbox": "^1.3.5",
diff --git a/scripts/self-hosted-server.mjs b/scripts/self-hosted-server.mjs
index ff831298..df79728d 100644
--- a/scripts/self-hosted-server.mjs
+++ b/scripts/self-hosted-server.mjs
@@ -4,6 +4,7 @@ import { dirname, extname, join, normalize, relative, resolve } from "node:path"
import { fileURLToPath } from "node:url";
import worker from "../apps/api/src/index.ts";
import { createSelfHostedStorageAdapter } from "../apps/api/src/self-hosted-storage-adapter.ts";
+import { createS3CompatibleStorageAdapter } from "../apps/api/src/s3-compatible-storage-adapter.ts";
const projectRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const dataDirectory = resolve(process.env.EDGE_EVER_DATA_DIR ?? join(projectRoot, ".edgeever-data"));
@@ -45,7 +46,23 @@ for (const name of migrationFiles) {
console.log(`[self-hosted] applied migration ${name}`);
}
-const storage = createSelfHostedStorageAdapter(sqlite, resourcesDirectory);
+const storageBackend = process.env.EDGE_EVER_STORAGE_BACKEND ?? "local";
+const storage = storageBackend === "s3"
+ ? createS3CompatibleStorageAdapter(sqlite, {
+ bucket: process.env.EDGE_EVER_S3_BUCKET ?? "",
+ region: process.env.EDGE_EVER_S3_REGION,
+ endpoint: process.env.EDGE_EVER_S3_ENDPOINT,
+ accessKeyId: process.env.EDGE_EVER_S3_ACCESS_KEY_ID,
+ secretAccessKey: process.env.EDGE_EVER_S3_SECRET_ACCESS_KEY,
+ forcePathStyle: process.env.EDGE_EVER_S3_FORCE_PATH_STYLE
+ ? process.env.EDGE_EVER_S3_FORCE_PATH_STYLE === "true"
+ : undefined,
+ })
+ : createSelfHostedStorageAdapter(sqlite, resourcesDirectory);
+
+if (storageBackend === "s3" && !process.env.EDGE_EVER_S3_BUCKET) {
+ throw new Error("EDGE_EVER_S3_BUCKET is required when EDGE_EVER_STORAGE_BACKEND=s3");
+}
const env = {
DB: storage.db,
RESOURCES: storage.resources,
@@ -110,3 +127,4 @@ const server = Bun.serve({
console.log(`[self-hosted] listening on ${server.url}`);
console.log(`[self-hosted] data directory: ${dataDirectory}`);
+console.log(`[self-hosted] storage backend: ${storageBackend}`);
diff --git a/tests/storage-adapter.test.ts b/tests/storage-adapter.test.ts
index e0a37766..6d152a23 100644
--- a/tests/storage-adapter.test.ts
+++ b/tests/storage-adapter.test.ts
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
import { createCloudflareStorageAdapter } from "../apps/api/src/cloudflare-storage-adapter";
import { createSelfHostedStorageAdapter } from "../apps/api/src/self-hosted-storage-adapter";
import { SELF_HOSTED_DATABASE_DIALECT } from "../apps/api/src/self-hosted-storage-adapter";
+import { createS3CompatibleStorageAdapter } from "../apps/api/src/s3-compatible-storage-adapter";
describe("storage adapter", () => {
test("wraps Cloudflare bindings without changing their identity", () => {
@@ -55,4 +56,37 @@ describe("storage adapter", () => {
await rm(directory, { recursive: true, force: true });
}
});
+
+ test("maps the common object operations to an S3-compatible client", async () => {
+ const commands: string[] = [];
+ const client = {
+ send: async (command: { constructor: { name: string }; input: { Key?: string } }) => {
+ commands.push(`${command.constructor.name}:${command.input.Key ?? ""}`);
+ if (command.constructor.name === "GetObjectCommand") {
+ return { Body: new Blob(["edgeever"]), ContentLength: 8, ContentType: "text/plain" };
+ }
+ return {};
+ },
+ };
+ const sqlite = {
+ query: () => ({ all: () => [], get: () => null, run: () => undefined }),
+ transaction: (callback: () => void) => () => callback(),
+ };
+ const adapter = createS3CompatibleStorageAdapter(
+ sqlite,
+ { bucket: "edgeever", endpoint: "http://minio:9000" },
+ client as never,
+ );
+
+ await adapter.resources.put("memo/image.txt", new Uint8Array([1]), {
+ httpMetadata: { contentType: "text/plain" },
+ });
+ expect(await adapter.resources.get("memo/image.txt")).not.toBeNull();
+ await adapter.resources.delete(["memo/image.txt", "memo/other.txt"]);
+ expect(commands).toEqual([
+ "PutObjectCommand:memo/image.txt",
+ "GetObjectCommand:memo/image.txt",
+ "DeleteObjectsCommand:",
+ ]);
+ });
});