@hot-updater/cloudflare 1.2.0-rc.5 → 1.2.0-rc.50
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/index.cjs +6 -85
- package/dist/index.d.cts +9 -8
- package/dist/index.d.mts +9 -8
- package/dist/index.mjs +7 -86
- package/dist/init/index.cjs +17 -19
- package/dist/init/index.d.cts +2 -2
- package/dist/init/index.d.mts +2 -2
- package/dist/init/index.mjs +18 -20
- package/dist/worker/index.cjs +39 -0
- package/dist/worker/index.d.cts +3 -2
- package/dist/worker/index.d.mts +3 -2
- package/dist/worker/index.mjs +39 -0
- package/package.json +10 -9
- package/sql/bundles.sql +17 -1
- package/src/d1Executor.ts +4 -3
- package/src/d1Rest.ts +4 -4
- package/src/r2S3Storage.ts +18 -141
- package/src/r2Storage.ts +2 -3
- package/src/r2WorkerStorage.ts +56 -3
- package/worker/dist/README.md +1 -1
- package/worker/dist/index.js +1397 -325
- package/worker/dist/index.js.map +4 -4
- package/worker/migrations/0002_hot-updater_1.2.0.sql +17 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/cloudflare",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.50",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -49,18 +49,19 @@
|
|
|
49
49
|
"package.json"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@aws-sdk/client-s3": "3.1066.0",
|
|
53
|
-
"@aws-sdk/lib-storage": "3.1008.0",
|
|
54
|
-
"@aws-sdk/s3-request-presigner": "3.1066.0",
|
|
55
52
|
"cloudflare": "4.2.0",
|
|
56
53
|
"hono": "4.12.34",
|
|
57
54
|
"uuidv7": "^1.0.2",
|
|
58
|
-
"@hot-updater/cli-tools": "1.2.0-rc.
|
|
59
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
60
|
-
"@hot-updater/
|
|
61
|
-
"@hot-updater/
|
|
55
|
+
"@hot-updater/cli-tools": "1.2.0-rc.50",
|
|
56
|
+
"@hot-updater/protocol": "1.2.0-rc.50",
|
|
57
|
+
"@hot-updater/server": "1.2.0-rc.50",
|
|
58
|
+
"@hot-updater/plugin-core": "1.2.0-rc.50",
|
|
59
|
+
"@hot-updater/storage-s3": "1.2.0-rc.50"
|
|
62
60
|
},
|
|
63
61
|
"devDependencies": {
|
|
62
|
+
"@aws-sdk/client-s3": "3.1066.0",
|
|
63
|
+
"@aws-sdk/lib-storage": "3.1066.0",
|
|
64
|
+
"@aws-sdk/s3-request-presigner": "3.1066.0",
|
|
64
65
|
"@cloudflare/vitest-pool-workers": "0.13.0",
|
|
65
66
|
"@cloudflare/workers-types": "^4.20260312.1",
|
|
66
67
|
"@types/node": "^20",
|
|
@@ -74,7 +75,7 @@
|
|
|
74
75
|
"vitest": "4.1.4",
|
|
75
76
|
"wrangler": "^4.69.0",
|
|
76
77
|
"xdg-app-paths": "^8.3.0",
|
|
77
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
78
|
+
"@hot-updater/test-utils": "1.2.0-rc.50"
|
|
78
79
|
},
|
|
79
80
|
"scripts": {
|
|
80
81
|
"build": "tsdown && pnpm build:worker",
|
package/sql/bundles.sql
CHANGED
|
@@ -36,22 +36,38 @@ CREATE UNIQUE INDEX IF NOT EXISTS "channels_name" ON "channels" ("name");
|
|
|
36
36
|
|
|
37
37
|
CREATE TABLE IF NOT EXISTS "bundle_totals" ("platform_key" TEXT NOT NULL, "_shard" INTEGER NOT NULL, "bundles" INTEGER NOT NULL, "_v" INTEGER NOT NULL DEFAULT 0, PRIMARY KEY ("platform_key", "_shard"));
|
|
38
38
|
|
|
39
|
-
CREATE TABLE IF NOT EXISTS "native_builds" ("id" TEXT NOT NULL, "scope_key" TEXT NOT NULL, "platform" TEXT NOT NULL, "channel_id" TEXT NOT NULL, "fingerprint_hash" TEXT, "app_version" TEXT, "min_bundle_id" TEXT NOT NULL, "artifact_kind" TEXT NOT NULL, "artifact_storage_uri" TEXT NOT NULL, "byte_size" INTEGER NOT NULL, "git_commit_hash" TEXT, "created_at_ms" INTEGER NOT NULL, "build_key" TEXT, "build_number" TEXT, "submitted_to" TEXT, "submitted_at_ms" INTEGER, "submitted_version" TEXT, "_v" INTEGER NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
|
|
39
|
+
CREATE TABLE IF NOT EXISTS "native_builds" ("id" TEXT NOT NULL, "scope_key" TEXT NOT NULL, "platform" TEXT NOT NULL, "channel_id" TEXT NOT NULL, "fingerprint_hash" TEXT, "app_version" TEXT, "min_bundle_id" TEXT NOT NULL, "artifact_kind" TEXT NOT NULL, "artifact_storage_uri" TEXT NOT NULL, "byte_size" INTEGER NOT NULL, "git_commit_hash" TEXT, "created_at_ms" INTEGER NOT NULL, "build_key" TEXT, "build_number" TEXT, "submitted_to" TEXT, "submitted_at_ms" INTEGER, "submitted_version" TEXT, "is_store_build" INTEGER NOT NULL, "is_sandbox" INTEGER NOT NULL, "sandbox_url_scheme" TEXT, "export_method" TEXT, "native_app_version" TEXT, "store_build_scope_key" TEXT, "_v" INTEGER NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
|
|
40
40
|
|
|
41
41
|
CREATE INDEX IF NOT EXISTS "native_builds_byScope" ON "native_builds" ("scope_key", "id");
|
|
42
42
|
|
|
43
43
|
CREATE INDEX IF NOT EXISTS "native_builds_byBuildKey" ON "native_builds" ("scope_key", "build_key", "id");
|
|
44
44
|
|
|
45
|
+
CREATE INDEX IF NOT EXISTS "native_builds_byScopeKind" ON "native_builds" ("scope_key", "artifact_kind", "id");
|
|
46
|
+
|
|
47
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "native_builds_byStoreBuild" ON "native_builds" ("store_build_scope_key");
|
|
48
|
+
|
|
45
49
|
CREATE INDEX IF NOT EXISTS "native_builds_byChannel" ON "native_builds" ("channel_id", "id");
|
|
46
50
|
|
|
47
51
|
CREATE UNIQUE INDEX IF NOT EXISTS "native_builds_min_bundle_id" ON "native_builds" ("min_bundle_id");
|
|
48
52
|
|
|
53
|
+
CREATE TABLE IF NOT EXISTS "ios_devices" ("id" TEXT NOT NULL, "udid" TEXT NOT NULL, "name" TEXT NOT NULL, "status" TEXT NOT NULL, "requested_by" TEXT, "created_at_ms" INTEGER NOT NULL, "approved_by" TEXT, "approved_at_ms" INTEGER, "registered_at_ms" INTEGER, "apple_issuer_id" TEXT, "apple_error" TEXT, "build_id" TEXT, "_v" INTEGER NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
|
|
54
|
+
|
|
55
|
+
CREATE INDEX IF NOT EXISTS "ios_devices_byStatus" ON "ios_devices" ("status", "id");
|
|
56
|
+
|
|
57
|
+
CREATE INDEX IF NOT EXISTS "ios_devices_byRegistration" ON "ios_devices" ("registered_at_ms", "id");
|
|
58
|
+
|
|
59
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "ios_devices_udid" ON "ios_devices" ("udid");
|
|
60
|
+
|
|
61
|
+
CREATE TABLE IF NOT EXISTS "ios_device_account" ("id" TEXT NOT NULL, "apple_issuer_id" TEXT NOT NULL, "claimed_at_ms" INTEGER NOT NULL, "_v" INTEGER NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
|
|
62
|
+
|
|
49
63
|
CREATE TABLE IF NOT EXISTS "bundle_events" ("id" TEXT NOT NULL, "type" TEXT NOT NULL, "install_id" TEXT NOT NULL, "user_id" TEXT, "from_release_id" TEXT, "from_bundle_id" TEXT, "to_release_id" TEXT, "to_bundle_id" TEXT NOT NULL, "platform" TEXT NOT NULL, "app_version" TEXT NOT NULL, "channel" TEXT NOT NULL, "metadata" TEXT NOT NULL, "received_at_ms" INTEGER NOT NULL, "day" INTEGER, "movement_install_id" TEXT, "bundle_ref" TEXT, "_v" INTEGER NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
|
|
50
64
|
|
|
51
65
|
CREATE INDEX IF NOT EXISTS "bundle_events_movementsByInstall" ON "bundle_events" ("movement_install_id", "received_at_ms", "id");
|
|
52
66
|
|
|
53
67
|
CREATE TABLE IF NOT EXISTS "bundle_events__byBundle" ("platform" TEXT NOT NULL, "channel" TEXT NOT NULL, "type" TEXT NOT NULL, "bundle_ref" TEXT NOT NULL, "day" INTEGER NOT NULL, "received_at_ms" INTEGER NOT NULL, "id" TEXT NOT NULL, PRIMARY KEY ("platform", "channel", "type", "bundle_ref", "day", "received_at_ms", "id"));
|
|
54
68
|
|
|
69
|
+
CREATE INDEX IF NOT EXISTS "bundle_events__byBundle__key" ON "bundle_events__byBundle" ("id");
|
|
70
|
+
|
|
55
71
|
CREATE INDEX IF NOT EXISTS "bundle_events_byDay" ON "bundle_events" ("day", "received_at_ms", "id");
|
|
56
72
|
|
|
57
73
|
CREATE TABLE IF NOT EXISTS "bundle_event_heads" ("install_id" TEXT NOT NULL, "id" TEXT NOT NULL, "type" TEXT NOT NULL, "user_id" TEXT, "from_release_id" TEXT, "from_bundle_id" TEXT, "to_release_id" TEXT, "to_bundle_id" TEXT NOT NULL, "platform" TEXT NOT NULL, "app_version" TEXT NOT NULL, "channel" TEXT NOT NULL, "metadata" TEXT NOT NULL, "received_at_ms" INTEGER NOT NULL, "_v" INTEGER NOT NULL DEFAULT 0, PRIMARY KEY ("install_id"));
|
package/src/d1Executor.ts
CHANGED
|
@@ -45,9 +45,10 @@ const withSqliteCode = (error: unknown): unknown => {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* The most ops one write sends
|
|
49
|
-
*
|
|
50
|
-
*
|
|
48
|
+
* The most ops one write sends: one `batch` of at most two statements an op
|
|
49
|
+
* besides its three own, so at most 903 statements. A Worker counts a batch
|
|
50
|
+
* as one query against its invocation's queries, whatever statements it
|
|
51
|
+
* holds (D1's limits), so this bounds one batch, not an invocation.
|
|
51
52
|
*/
|
|
52
53
|
export const D1_MAX_OPS = 450;
|
|
53
54
|
|
package/src/d1Rest.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SqlResult, SqlStatement } from "@hot-updater/plugin-core";
|
|
1
|
+
import type { Lazy, SqlResult, SqlStatement } from "@hot-updater/plugin-core";
|
|
2
2
|
import Cloudflare from "cloudflare";
|
|
3
3
|
|
|
4
4
|
import { D1ExecutionError, type D1ResultLike, toSqlResult } from "./d1Executor";
|
|
@@ -8,10 +8,10 @@ export interface D1RestConfig {
|
|
|
8
8
|
readonly accountId: string;
|
|
9
9
|
/**
|
|
10
10
|
* An API token with D1 edit permission, or a function that returns it,
|
|
11
|
-
* such as
|
|
12
|
-
* so a config loads without the token.
|
|
11
|
+
* such as `secret("<name>")` in `hot-updater.config.ts`: called on the
|
|
12
|
+
* first query, so a config loads without the token.
|
|
13
13
|
*/
|
|
14
|
-
readonly cloudflareApiToken:
|
|
14
|
+
readonly cloudflareApiToken: Lazy<string>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/** The REST API binds text: each value goes as JSON and is read back with `json_extract`. */
|
package/src/r2S3Storage.ts
CHANGED
|
@@ -1,154 +1,31 @@
|
|
|
1
|
+
import type { StorageAdapterWith } from "@hot-updater/plugin-core";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
GetObjectCommand,
|
|
4
|
-
HeadObjectCommand,
|
|
5
|
-
S3Client,
|
|
3
|
+
createS3Storage,
|
|
6
4
|
type S3ClientConfig,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
createStorageKeyBuilder,
|
|
12
|
-
createStorageAdapter,
|
|
13
|
-
createStorageUri,
|
|
14
|
-
parseStorageUri,
|
|
15
|
-
type StorageAdapterWith,
|
|
16
|
-
} from "@hot-updater/plugin-core";
|
|
5
|
+
type S3CredentialsOption,
|
|
6
|
+
type S3StorageOperations,
|
|
7
|
+
} from "@hot-updater/storage-s3";
|
|
17
8
|
|
|
18
|
-
export interface R2S3StorageConfig extends S3ClientConfig {
|
|
9
|
+
export interface R2S3StorageConfig extends Omit<S3ClientConfig, "credentials"> {
|
|
19
10
|
accountId: string;
|
|
20
11
|
bucketName: string;
|
|
21
|
-
credentials
|
|
12
|
+
/** The SDK's credentials, or an R2 access key whose fields are lazy. */
|
|
13
|
+
credentials: NonNullable<S3CredentialsOption>;
|
|
22
14
|
/** Base path where bundles will be stored in the bucket. */
|
|
23
15
|
basePath?: string;
|
|
24
16
|
}
|
|
25
17
|
|
|
26
|
-
/** Devices download right after the update check that returns the URL. */
|
|
27
|
-
const PRESIGNED_URL_EXPIRES_IN_SECONDS = 3600;
|
|
28
|
-
|
|
29
|
-
const isObjectNotFoundError = (error: unknown) => {
|
|
30
|
-
if (
|
|
31
|
-
error instanceof Error &&
|
|
32
|
-
(error.name === "NotFound" || error.name === "NoSuchKey")
|
|
33
|
-
) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
return (
|
|
37
|
-
typeof error === "object" &&
|
|
38
|
-
error !== null &&
|
|
39
|
-
"$metadata" in error &&
|
|
40
|
-
(error as { $metadata?: { httpStatusCode?: number } }).$metadata
|
|
41
|
-
?.httpStatusCode === 404
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
18
|
export const createR2S3Storage = (
|
|
46
19
|
config: R2S3StorageConfig,
|
|
47
|
-
): StorageAdapterWith<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
region,
|
|
57
|
-
...s3Config
|
|
58
|
-
} = config;
|
|
59
|
-
const client = new S3Client({
|
|
60
|
-
...s3Config,
|
|
61
|
-
endpoint: endpoint ?? `https://${accountId}.r2.cloudflarestorage.com`,
|
|
62
|
-
forcePathStyle: forcePathStyle ?? true,
|
|
63
|
-
region: region ?? "auto",
|
|
64
|
-
});
|
|
65
|
-
const getStorageKey = createStorageKeyBuilder(basePath);
|
|
66
|
-
|
|
67
|
-
const parseAndValidate = (storageUri: string) => {
|
|
68
|
-
const parsed = parseStorageUri(storageUri, "r2");
|
|
69
|
-
if (parsed.bucket !== bucketName) {
|
|
70
|
-
throw new Error(
|
|
71
|
-
`Bucket name mismatch: expected "${bucketName}", but found "${parsed.bucket}".`,
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
return parsed;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return createStorageAdapter({
|
|
78
|
-
name: "r2Storage",
|
|
79
|
-
protocol: "r2",
|
|
80
|
-
async put({ key, body, contentLength, contentType }) {
|
|
81
|
-
const storageKey = getStorageKey(key);
|
|
82
|
-
await new Upload({
|
|
83
|
-
client,
|
|
84
|
-
params: {
|
|
85
|
-
Body: body,
|
|
86
|
-
Bucket: bucketName,
|
|
87
|
-
CacheControl: "max-age=31536000",
|
|
88
|
-
ContentLength: contentLength,
|
|
89
|
-
ContentType: contentType,
|
|
90
|
-
Key: storageKey,
|
|
91
|
-
},
|
|
92
|
-
}).done();
|
|
93
|
-
return {
|
|
94
|
-
storageUri: createStorageUri({
|
|
95
|
-
protocol: "r2",
|
|
96
|
-
bucket: bucketName,
|
|
97
|
-
key: storageKey,
|
|
98
|
-
}),
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
async get({ storageUri }) {
|
|
102
|
-
const { key } = parseAndValidate(storageUri);
|
|
103
|
-
try {
|
|
104
|
-
const response = await client.send(
|
|
105
|
-
new GetObjectCommand({ Bucket: bucketName, Key: key }),
|
|
106
|
-
);
|
|
107
|
-
if (!response.Body) return { response: null };
|
|
108
|
-
const headers = new Headers();
|
|
109
|
-
if (response.ContentType)
|
|
110
|
-
headers.set("content-type", response.ContentType);
|
|
111
|
-
if (response.ContentLength !== undefined) {
|
|
112
|
-
headers.set("content-length", String(response.ContentLength));
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
response: new Response(response.Body.transformToWebStream(), {
|
|
116
|
-
headers,
|
|
117
|
-
}),
|
|
118
|
-
};
|
|
119
|
-
} catch (error) {
|
|
120
|
-
if (isObjectNotFoundError(error)) return { response: null };
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
async getDownloadUrl({ storageUri }) {
|
|
125
|
-
const { key } = parseAndValidate(storageUri);
|
|
126
|
-
return {
|
|
127
|
-
url: await getSignedUrl(
|
|
128
|
-
client,
|
|
129
|
-
new GetObjectCommand({ Bucket: bucketName, Key: key }),
|
|
130
|
-
{ expiresIn: PRESIGNED_URL_EXPIRES_IN_SECONDS },
|
|
131
|
-
),
|
|
132
|
-
};
|
|
20
|
+
): StorageAdapterWith<S3StorageOperations> => {
|
|
21
|
+
const { accountId, endpoint, forcePathStyle, region, ...s3Config } = config;
|
|
22
|
+
return createS3Storage(
|
|
23
|
+
{ name: "r2Storage", protocol: "r2" },
|
|
24
|
+
{
|
|
25
|
+
...s3Config,
|
|
26
|
+
endpoint: endpoint ?? `https://${accountId}.r2.cloudflarestorage.com`,
|
|
27
|
+
forcePathStyle: forcePathStyle ?? true,
|
|
28
|
+
region: region ?? "auto",
|
|
133
29
|
},
|
|
134
|
-
|
|
135
|
-
const { key } = parseAndValidate(storageUri);
|
|
136
|
-
try {
|
|
137
|
-
await client.send(
|
|
138
|
-
new HeadObjectCommand({ Bucket: bucketName, Key: key }),
|
|
139
|
-
);
|
|
140
|
-
return { exists: true };
|
|
141
|
-
} catch (error) {
|
|
142
|
-
if (isObjectNotFoundError(error)) return { exists: false };
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
async delete({ storageUri }) {
|
|
147
|
-
const { key } = parseAndValidate(storageUri);
|
|
148
|
-
await client.send(
|
|
149
|
-
new DeleteObjectCommand({ Bucket: bucketName, Key: key }),
|
|
150
|
-
);
|
|
151
|
-
return { deleted: true };
|
|
152
|
-
},
|
|
153
|
-
});
|
|
30
|
+
);
|
|
154
31
|
};
|
package/src/r2Storage.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { StorageAdapterWith } from "@hot-updater/plugin-core";
|
|
2
|
+
import type { S3StorageOperations } from "@hot-updater/storage-s3";
|
|
2
3
|
|
|
3
4
|
import { createR2S3Storage, type R2S3StorageConfig } from "./r2S3Storage";
|
|
4
5
|
|
|
@@ -7,9 +8,7 @@ export type { R2S3StorageConfig };
|
|
|
7
8
|
|
|
8
9
|
export const r2Storage = (
|
|
9
10
|
config: R2S3StorageConfig,
|
|
10
|
-
): StorageAdapterWith<
|
|
11
|
-
"put" | "get" | "getDownloadUrl" | "exists" | "delete"
|
|
12
|
-
> => {
|
|
11
|
+
): StorageAdapterWith<S3StorageOperations> => {
|
|
13
12
|
if (!config.credentials) {
|
|
14
13
|
throw new Error(
|
|
15
14
|
"r2Storage requires S3-compatible credentials: pass credentials with an R2 access key ID and secret access key.",
|
package/src/r2WorkerStorage.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
createStorageUri,
|
|
5
5
|
parseStorageUri,
|
|
6
6
|
type StorageAdapterWith,
|
|
7
|
+
type StorageObject,
|
|
7
8
|
} from "@hot-updater/plugin-core";
|
|
8
9
|
|
|
9
10
|
import { presignR2GetUrl, type R2Credentials } from "./presignR2Url";
|
|
@@ -28,6 +29,16 @@ export type CloudflareWorkerStorageConfig = {
|
|
|
28
29
|
|
|
29
30
|
/** Devices download right after the update check that returns the URL. */
|
|
30
31
|
const PRESIGNED_URL_EXPIRES_IN_SECONDS = 3600;
|
|
32
|
+
/** Keys the binding deletes in one call. */
|
|
33
|
+
const DELETE_BATCH_SIZE = 1000;
|
|
34
|
+
|
|
35
|
+
type R2WorkerOperations =
|
|
36
|
+
| "put"
|
|
37
|
+
| "get"
|
|
38
|
+
| "exists"
|
|
39
|
+
| "delete"
|
|
40
|
+
| "listObjects"
|
|
41
|
+
| "deleteObjects";
|
|
31
42
|
|
|
32
43
|
/**
|
|
33
44
|
* Storage on the Worker's R2 binding. With R2's S3-compatible credentials,
|
|
@@ -39,14 +50,15 @@ export function r2WorkerStorage(
|
|
|
39
50
|
config: CloudflareWorkerStorageConfig & {
|
|
40
51
|
readonly credentials: R2Credentials;
|
|
41
52
|
},
|
|
42
|
-
): StorageAdapterWith<
|
|
53
|
+
): StorageAdapterWith<R2WorkerOperations | "getDownloadUrl">;
|
|
43
54
|
export function r2WorkerStorage(
|
|
44
55
|
config: CloudflareWorkerStorageConfig,
|
|
45
|
-
): StorageAdapterWith<
|
|
56
|
+
): StorageAdapterWith<R2WorkerOperations>;
|
|
46
57
|
export function r2WorkerStorage(
|
|
47
58
|
config: CloudflareWorkerStorageConfig,
|
|
48
|
-
): StorageAdapterWith<
|
|
59
|
+
): StorageAdapterWith<R2WorkerOperations> {
|
|
49
60
|
const getStorageKey = createStorageKeyBuilder(config.basePath);
|
|
61
|
+
const basePrefix = getStorageKey() ? `${getStorageKey()}/` : "";
|
|
50
62
|
|
|
51
63
|
const parseAndValidate = (storageUri: string) => {
|
|
52
64
|
const parsed = parseStorageUri(storageUri, "r2");
|
|
@@ -128,5 +140,46 @@ export function r2WorkerStorage(
|
|
|
128
140
|
await config.bucket.delete(key);
|
|
129
141
|
return { deleted: true };
|
|
130
142
|
},
|
|
143
|
+
async listObjects(prefix) {
|
|
144
|
+
const folder = getStorageKey(prefix ?? "");
|
|
145
|
+
const objects: StorageObject[] = [];
|
|
146
|
+
let cursor: string | undefined;
|
|
147
|
+
do {
|
|
148
|
+
const listed = await config.bucket.list({
|
|
149
|
+
prefix: folder ? `${folder}/` : "",
|
|
150
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
151
|
+
});
|
|
152
|
+
for (const object of listed.objects) {
|
|
153
|
+
if (!object.key.startsWith(basePrefix)) continue;
|
|
154
|
+
// A key no `put` writes, such as a folder marker, has no URI.
|
|
155
|
+
let storageUri: string;
|
|
156
|
+
try {
|
|
157
|
+
storageUri = createStorageUri({
|
|
158
|
+
protocol: "r2",
|
|
159
|
+
bucket: config.bucketName,
|
|
160
|
+
key: object.key,
|
|
161
|
+
});
|
|
162
|
+
} catch {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
objects.push({
|
|
166
|
+
key: object.key.slice(basePrefix.length),
|
|
167
|
+
lastModifiedAt: object.uploaded,
|
|
168
|
+
size: object.size,
|
|
169
|
+
storageUri,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
cursor = listed.truncated ? listed.cursor : undefined;
|
|
173
|
+
} while (cursor !== undefined);
|
|
174
|
+
return objects;
|
|
175
|
+
},
|
|
176
|
+
async deleteObjects(relativeKeys) {
|
|
177
|
+
const keys = relativeKeys.map((key) => getStorageKey(key));
|
|
178
|
+
for (let offset = 0; offset < keys.length; offset += DELETE_BATCH_SIZE) {
|
|
179
|
+
await config.bucket.delete(
|
|
180
|
+
keys.slice(offset, offset + DELETE_BATCH_SIZE),
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
},
|
|
131
184
|
});
|
|
132
185
|
}
|
package/worker/dist/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
This folder contains the built output assets for the worker "hot-updater" generated at 2026-
|
|
1
|
+
This folder contains the built output assets for the worker "hot-updater" generated at 2026-11-20T17:49:09.553Z.
|