@hot-updater/cloudflare 0.21.11 → 0.21.13
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 +131 -128
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +132 -129
- package/package.json +6 -6
- package/worker/dist/README.md +1 -1
package/dist/index.cjs
CHANGED
|
@@ -339,86 +339,88 @@ function transformRowToBundle(row) {
|
|
|
339
339
|
metadata: row?.metadata ? JSON.parse(row?.metadata) : {}
|
|
340
340
|
};
|
|
341
341
|
}
|
|
342
|
-
const d1Database = (
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
342
|
+
const d1Database = (0, __hot_updater_plugin_core.createDatabasePlugin)({
|
|
343
|
+
name: "d1Database",
|
|
344
|
+
factory: (config) => {
|
|
345
|
+
let bundles = [];
|
|
346
|
+
const cf = new cloudflare.default({ apiToken: config.cloudflareApiToken });
|
|
347
|
+
async function getTotalCount(conditions) {
|
|
348
|
+
const { sql: whereClause, params } = buildWhereClause(conditions);
|
|
349
|
+
const countSql = (0, import_lib.default)(`SELECT COUNT(*) as total FROM bundles${whereClause}`);
|
|
350
|
+
return (await resolvePage(await cf.d1.database.query(config.databaseId, {
|
|
351
|
+
account_id: config.accountId,
|
|
352
|
+
sql: countSql,
|
|
353
|
+
params
|
|
354
|
+
})))[0]?.total || 0;
|
|
355
|
+
}
|
|
356
|
+
async function getPaginatedBundles(conditions, limit, offset) {
|
|
357
|
+
const { sql: whereClause, params } = buildWhereClause(conditions);
|
|
358
|
+
const sql = (0, import_lib.default)(`
|
|
356
359
|
SELECT * FROM bundles
|
|
357
360
|
${whereClause}
|
|
358
361
|
ORDER BY id DESC
|
|
359
362
|
LIMIT ?
|
|
360
363
|
OFFSET ?
|
|
361
364
|
`);
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
account_id: config.accountId,
|
|
365
|
-
sql,
|
|
366
|
-
params
|
|
367
|
-
}))).map(transformRowToBundle);
|
|
368
|
-
}
|
|
369
|
-
return (0, __hot_updater_plugin_core.createDatabasePlugin)("d1Database", {
|
|
370
|
-
getContext: () => ({ cf: new cloudflare.default({ apiToken: config.cloudflareApiToken }) }),
|
|
371
|
-
async getBundleById(context, bundleId) {
|
|
372
|
-
const found = bundles.find((b) => b.id === bundleId);
|
|
373
|
-
if (found) return found;
|
|
374
|
-
const sql = (0, import_lib.default)(`
|
|
375
|
-
SELECT * FROM bundles WHERE id = ? LIMIT 1`);
|
|
376
|
-
const rows = await resolvePage(await context.cf.d1.database.query(config.databaseId, {
|
|
365
|
+
params.push(limit, offset);
|
|
366
|
+
return (await resolvePage(await cf.d1.database.query(config.databaseId, {
|
|
377
367
|
account_id: config.accountId,
|
|
378
368
|
sql,
|
|
379
|
-
params
|
|
380
|
-
}));
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
369
|
+
params
|
|
370
|
+
}))).map(transformRowToBundle);
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
async getBundleById(bundleId) {
|
|
374
|
+
const found = bundles.find((b) => b.id === bundleId);
|
|
375
|
+
if (found) return found;
|
|
376
|
+
const sql = (0, import_lib.default)(`
|
|
377
|
+
SELECT * FROM bundles WHERE id = ? LIMIT 1`);
|
|
378
|
+
const rows = await resolvePage(await cf.d1.database.query(config.databaseId, {
|
|
379
|
+
account_id: config.accountId,
|
|
380
|
+
sql,
|
|
381
|
+
params: [bundleId]
|
|
382
|
+
}));
|
|
383
|
+
if (rows.length === 0) return null;
|
|
384
|
+
return transformRowToBundle(rows[0]);
|
|
385
|
+
},
|
|
386
|
+
async getBundles(options) {
|
|
387
|
+
const { where = {}, limit, offset } = options;
|
|
388
|
+
const totalCount = await getTotalCount(where);
|
|
389
|
+
bundles = await getPaginatedBundles(where, limit, offset);
|
|
390
|
+
const pagination = (0, __hot_updater_plugin_core.calculatePagination)(totalCount, {
|
|
391
|
+
limit,
|
|
392
|
+
offset
|
|
393
|
+
});
|
|
394
|
+
return {
|
|
395
|
+
data: bundles,
|
|
396
|
+
pagination
|
|
397
|
+
};
|
|
398
|
+
},
|
|
399
|
+
async getChannels() {
|
|
400
|
+
const sql = (0, import_lib.default)(`
|
|
399
401
|
SELECT channel FROM bundles GROUP BY channel
|
|
400
402
|
`);
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
403
|
+
return (await resolvePage(await cf.d1.database.query(config.databaseId, {
|
|
404
|
+
account_id: config.accountId,
|
|
405
|
+
sql,
|
|
406
|
+
params: []
|
|
407
|
+
}))).map((row) => row.channel);
|
|
408
|
+
},
|
|
409
|
+
async commitBundle({ changedSets }) {
|
|
410
|
+
if (changedSets.length === 0) return;
|
|
411
|
+
for (const op of changedSets) if (op.operation === "delete") {
|
|
412
|
+
const deleteSql = (0, import_lib.default)(`
|
|
411
413
|
DELETE FROM bundles WHERE id = ?
|
|
412
414
|
`);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
415
|
+
await cf.d1.database.query(config.databaseId, {
|
|
416
|
+
account_id: config.accountId,
|
|
417
|
+
sql: deleteSql,
|
|
418
|
+
params: [op.data.id]
|
|
419
|
+
});
|
|
420
|
+
bundles = bundles.filter((b) => b.id !== op.data.id);
|
|
421
|
+
} else if (op.operation === "insert" || op.operation === "update") {
|
|
422
|
+
const bundle = op.data;
|
|
423
|
+
const upsertSql = (0, import_lib.default)(`
|
|
422
424
|
INSERT OR REPLACE INTO bundles (
|
|
423
425
|
id,
|
|
424
426
|
channel,
|
|
@@ -435,30 +437,30 @@ const d1Database = (config, hooks) => {
|
|
|
435
437
|
)
|
|
436
438
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
437
439
|
`);
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
440
|
+
const params = [
|
|
441
|
+
bundle.id,
|
|
442
|
+
bundle.channel,
|
|
443
|
+
bundle.enabled ? 1 : 0,
|
|
444
|
+
bundle.shouldForceUpdate ? 1 : 0,
|
|
445
|
+
bundle.fileHash,
|
|
446
|
+
bundle.gitCommitHash || null,
|
|
447
|
+
bundle.message || null,
|
|
448
|
+
bundle.platform,
|
|
449
|
+
bundle.targetAppVersion,
|
|
450
|
+
bundle.storageUri,
|
|
451
|
+
bundle.fingerprintHash,
|
|
452
|
+
bundle.metadata ? JSON.stringify(bundle.metadata) : JSON.stringify({})
|
|
453
|
+
];
|
|
454
|
+
await cf.d1.database.query(config.databaseId, {
|
|
455
|
+
account_id: config.accountId,
|
|
456
|
+
sql: upsertSql,
|
|
457
|
+
params
|
|
458
|
+
});
|
|
459
|
+
}
|
|
457
460
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
};
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
});
|
|
462
464
|
|
|
463
465
|
//#endregion
|
|
464
466
|
//#region ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
|
|
@@ -6812,44 +6814,45 @@ const createWrangler = ({ stdio, accountId, cloudflareApiToken, cwd }) => {
|
|
|
6812
6814
|
* })
|
|
6813
6815
|
* ```
|
|
6814
6816
|
*/
|
|
6815
|
-
const r2Storage = (
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
cloudflareApiToken,
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6817
|
+
const r2Storage = (0, __hot_updater_plugin_core.createStoragePlugin)({
|
|
6818
|
+
name: "r2Storage",
|
|
6819
|
+
supportedProtocol: "r2",
|
|
6820
|
+
factory: (config) => {
|
|
6821
|
+
const { bucketName, cloudflareApiToken, accountId } = config;
|
|
6822
|
+
const wrangler = createWrangler({
|
|
6823
|
+
accountId,
|
|
6824
|
+
cloudflareApiToken,
|
|
6825
|
+
cwd: process.cwd()
|
|
6826
|
+
});
|
|
6827
|
+
const getStorageKey = (0, __hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
|
|
6828
|
+
return {
|
|
6829
|
+
async delete(storageUri) {
|
|
6830
|
+
const { bucket, key } = (0, __hot_updater_plugin_core.parseStorageUri)(storageUri, "r2");
|
|
6831
|
+
if (bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${bucket}".`);
|
|
6832
|
+
try {
|
|
6833
|
+
await wrangler("r2", "object", "delete", [bucketName, key].join("/"), "--remote");
|
|
6834
|
+
} catch {
|
|
6835
|
+
throw new Error("Can not delete bundle");
|
|
6836
|
+
}
|
|
6837
|
+
},
|
|
6838
|
+
async upload(key, filePath) {
|
|
6839
|
+
const contentType = (0, __hot_updater_plugin_core.getContentType)(filePath);
|
|
6840
|
+
const Key = getStorageKey(key, path.default.basename(filePath));
|
|
6841
|
+
try {
|
|
6842
|
+
const { stderr, exitCode } = await wrangler("r2", "object", "put", [bucketName, Key].join("/"), "--file", filePath, "--content-type", contentType, "--remote");
|
|
6843
|
+
if (exitCode !== 0 && stderr) throw new Error(stderr);
|
|
6844
|
+
} catch (error$1) {
|
|
6845
|
+
if (error$1 instanceof ExecaError) throw new Error(error$1.stderr || error$1.stdout);
|
|
6846
|
+
throw error$1;
|
|
6847
|
+
}
|
|
6848
|
+
return { storageUri: `r2://${bucketName}/${Key}` };
|
|
6849
|
+
},
|
|
6850
|
+
async getDownloadUrl() {
|
|
6851
|
+
throw new Error("`r2Storage` does not support `getDownloadUrl()`. Use `s3Storage` from `@hot-updater/aws` instead (compatible with Cloudflare R2).\n\nExample:\ns3Storage({\n region: 'auto',\n endpoint: 'https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com',\n credentials: {\n accessKeyId: 'YOUR_ACCESS_KEY_ID',\n secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',\n },\n bucketName: 'YOUR_BUCKET_NAME',\n})");
|
|
6844
6852
|
}
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
async getDownloadUrl() {
|
|
6849
|
-
throw new Error("`r2Storage` does not support `getDownloadUrl()`. Use `s3Storage` from `@hot-updater/aws` instead (compatible with Cloudflare R2).\n\nExample:\ns3Storage({\n region: 'auto',\n endpoint: 'https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com',\n credentials: {\n accessKeyId: 'YOUR_ACCESS_KEY_ID',\n secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',\n },\n bucketName: 'YOUR_BUCKET_NAME',\n})");
|
|
6850
|
-
}
|
|
6851
|
-
};
|
|
6852
|
-
};
|
|
6853
|
+
};
|
|
6854
|
+
}
|
|
6855
|
+
});
|
|
6853
6856
|
|
|
6854
6857
|
//#endregion
|
|
6855
6858
|
exports.d1Database = d1Database;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { DatabasePluginHooks, StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
|
|
1
|
+
import * as _hot_updater_plugin_core1 from "@hot-updater/plugin-core";
|
|
3
2
|
|
|
4
3
|
//#region src/d1Database.d.ts
|
|
5
4
|
interface D1DatabaseConfig {
|
|
@@ -7,7 +6,7 @@ interface D1DatabaseConfig {
|
|
|
7
6
|
accountId: string;
|
|
8
7
|
cloudflareApiToken: string;
|
|
9
8
|
}
|
|
10
|
-
declare const d1Database: (config: D1DatabaseConfig, hooks?: DatabasePluginHooks) => () =>
|
|
9
|
+
declare const d1Database: (config: D1DatabaseConfig, hooks?: _hot_updater_plugin_core1.DatabasePluginHooks) => (() => _hot_updater_plugin_core1.DatabasePlugin);
|
|
11
10
|
//#endregion
|
|
12
11
|
//#region src/r2Storage.d.ts
|
|
13
12
|
interface R2StorageConfig {
|
|
@@ -42,6 +41,6 @@ interface R2StorageConfig {
|
|
|
42
41
|
* })
|
|
43
42
|
* ```
|
|
44
43
|
*/
|
|
45
|
-
declare const r2Storage: (config: R2StorageConfig, hooks?: StoragePluginHooks) => () => StoragePlugin;
|
|
44
|
+
declare const r2Storage: (config: R2StorageConfig, hooks?: _hot_updater_plugin_core1.StoragePluginHooks) => () => _hot_updater_plugin_core1.StoragePlugin;
|
|
46
45
|
//#endregion
|
|
47
46
|
export { D1DatabaseConfig, R2StorageConfig, d1Database, r2Storage };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { DatabasePluginHooks, StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
|
|
1
|
+
import * as _hot_updater_plugin_core1 from "@hot-updater/plugin-core";
|
|
3
2
|
|
|
4
3
|
//#region src/d1Database.d.ts
|
|
5
4
|
interface D1DatabaseConfig {
|
|
@@ -7,7 +6,7 @@ interface D1DatabaseConfig {
|
|
|
7
6
|
accountId: string;
|
|
8
7
|
cloudflareApiToken: string;
|
|
9
8
|
}
|
|
10
|
-
declare const d1Database: (config: D1DatabaseConfig, hooks?: DatabasePluginHooks) => () =>
|
|
9
|
+
declare const d1Database: (config: D1DatabaseConfig, hooks?: _hot_updater_plugin_core1.DatabasePluginHooks) => (() => _hot_updater_plugin_core1.DatabasePlugin);
|
|
11
10
|
//#endregion
|
|
12
11
|
//#region src/r2Storage.d.ts
|
|
13
12
|
interface R2StorageConfig {
|
|
@@ -42,6 +41,6 @@ interface R2StorageConfig {
|
|
|
42
41
|
* })
|
|
43
42
|
* ```
|
|
44
43
|
*/
|
|
45
|
-
declare const r2Storage: (config: R2StorageConfig, hooks?: StoragePluginHooks) => () => StoragePlugin;
|
|
44
|
+
declare const r2Storage: (config: R2StorageConfig, hooks?: _hot_updater_plugin_core1.StoragePluginHooks) => () => _hot_updater_plugin_core1.StoragePlugin;
|
|
46
45
|
//#endregion
|
|
47
46
|
export { D1DatabaseConfig, R2StorageConfig, d1Database, r2Storage };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { calculatePagination, createDatabasePlugin, createStorageKeyBuilder, getContentType, parseStorageUri } from "@hot-updater/plugin-core";
|
|
2
|
+
import { calculatePagination, createDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, getContentType, parseStorageUri } from "@hot-updater/plugin-core";
|
|
3
3
|
import Cloudflare from "cloudflare";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
|
|
@@ -323,86 +323,88 @@ function transformRowToBundle(row) {
|
|
|
323
323
|
metadata: row?.metadata ? JSON.parse(row?.metadata) : {}
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
|
-
const d1Database = (
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
326
|
+
const d1Database = createDatabasePlugin({
|
|
327
|
+
name: "d1Database",
|
|
328
|
+
factory: (config) => {
|
|
329
|
+
let bundles = [];
|
|
330
|
+
const cf = new Cloudflare({ apiToken: config.cloudflareApiToken });
|
|
331
|
+
async function getTotalCount(conditions) {
|
|
332
|
+
const { sql: whereClause, params } = buildWhereClause(conditions);
|
|
333
|
+
const countSql = (0, import_lib.default)(`SELECT COUNT(*) as total FROM bundles${whereClause}`);
|
|
334
|
+
return (await resolvePage(await cf.d1.database.query(config.databaseId, {
|
|
335
|
+
account_id: config.accountId,
|
|
336
|
+
sql: countSql,
|
|
337
|
+
params
|
|
338
|
+
})))[0]?.total || 0;
|
|
339
|
+
}
|
|
340
|
+
async function getPaginatedBundles(conditions, limit, offset) {
|
|
341
|
+
const { sql: whereClause, params } = buildWhereClause(conditions);
|
|
342
|
+
const sql = (0, import_lib.default)(`
|
|
340
343
|
SELECT * FROM bundles
|
|
341
344
|
${whereClause}
|
|
342
345
|
ORDER BY id DESC
|
|
343
346
|
LIMIT ?
|
|
344
347
|
OFFSET ?
|
|
345
348
|
`);
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
account_id: config.accountId,
|
|
349
|
-
sql,
|
|
350
|
-
params
|
|
351
|
-
}))).map(transformRowToBundle);
|
|
352
|
-
}
|
|
353
|
-
return createDatabasePlugin("d1Database", {
|
|
354
|
-
getContext: () => ({ cf: new Cloudflare({ apiToken: config.cloudflareApiToken }) }),
|
|
355
|
-
async getBundleById(context, bundleId) {
|
|
356
|
-
const found = bundles.find((b) => b.id === bundleId);
|
|
357
|
-
if (found) return found;
|
|
358
|
-
const sql = (0, import_lib.default)(`
|
|
359
|
-
SELECT * FROM bundles WHERE id = ? LIMIT 1`);
|
|
360
|
-
const rows = await resolvePage(await context.cf.d1.database.query(config.databaseId, {
|
|
349
|
+
params.push(limit, offset);
|
|
350
|
+
return (await resolvePage(await cf.d1.database.query(config.databaseId, {
|
|
361
351
|
account_id: config.accountId,
|
|
362
352
|
sql,
|
|
363
|
-
params
|
|
364
|
-
}));
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
353
|
+
params
|
|
354
|
+
}))).map(transformRowToBundle);
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
async getBundleById(bundleId) {
|
|
358
|
+
const found = bundles.find((b) => b.id === bundleId);
|
|
359
|
+
if (found) return found;
|
|
360
|
+
const sql = (0, import_lib.default)(`
|
|
361
|
+
SELECT * FROM bundles WHERE id = ? LIMIT 1`);
|
|
362
|
+
const rows = await resolvePage(await cf.d1.database.query(config.databaseId, {
|
|
363
|
+
account_id: config.accountId,
|
|
364
|
+
sql,
|
|
365
|
+
params: [bundleId]
|
|
366
|
+
}));
|
|
367
|
+
if (rows.length === 0) return null;
|
|
368
|
+
return transformRowToBundle(rows[0]);
|
|
369
|
+
},
|
|
370
|
+
async getBundles(options) {
|
|
371
|
+
const { where = {}, limit, offset } = options;
|
|
372
|
+
const totalCount = await getTotalCount(where);
|
|
373
|
+
bundles = await getPaginatedBundles(where, limit, offset);
|
|
374
|
+
const pagination = calculatePagination(totalCount, {
|
|
375
|
+
limit,
|
|
376
|
+
offset
|
|
377
|
+
});
|
|
378
|
+
return {
|
|
379
|
+
data: bundles,
|
|
380
|
+
pagination
|
|
381
|
+
};
|
|
382
|
+
},
|
|
383
|
+
async getChannels() {
|
|
384
|
+
const sql = (0, import_lib.default)(`
|
|
383
385
|
SELECT channel FROM bundles GROUP BY channel
|
|
384
386
|
`);
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
387
|
+
return (await resolvePage(await cf.d1.database.query(config.databaseId, {
|
|
388
|
+
account_id: config.accountId,
|
|
389
|
+
sql,
|
|
390
|
+
params: []
|
|
391
|
+
}))).map((row) => row.channel);
|
|
392
|
+
},
|
|
393
|
+
async commitBundle({ changedSets }) {
|
|
394
|
+
if (changedSets.length === 0) return;
|
|
395
|
+
for (const op of changedSets) if (op.operation === "delete") {
|
|
396
|
+
const deleteSql = (0, import_lib.default)(`
|
|
395
397
|
DELETE FROM bundles WHERE id = ?
|
|
396
398
|
`);
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
399
|
+
await cf.d1.database.query(config.databaseId, {
|
|
400
|
+
account_id: config.accountId,
|
|
401
|
+
sql: deleteSql,
|
|
402
|
+
params: [op.data.id]
|
|
403
|
+
});
|
|
404
|
+
bundles = bundles.filter((b) => b.id !== op.data.id);
|
|
405
|
+
} else if (op.operation === "insert" || op.operation === "update") {
|
|
406
|
+
const bundle = op.data;
|
|
407
|
+
const upsertSql = (0, import_lib.default)(`
|
|
406
408
|
INSERT OR REPLACE INTO bundles (
|
|
407
409
|
id,
|
|
408
410
|
channel,
|
|
@@ -419,30 +421,30 @@ const d1Database = (config, hooks) => {
|
|
|
419
421
|
)
|
|
420
422
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
421
423
|
`);
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
424
|
+
const params = [
|
|
425
|
+
bundle.id,
|
|
426
|
+
bundle.channel,
|
|
427
|
+
bundle.enabled ? 1 : 0,
|
|
428
|
+
bundle.shouldForceUpdate ? 1 : 0,
|
|
429
|
+
bundle.fileHash,
|
|
430
|
+
bundle.gitCommitHash || null,
|
|
431
|
+
bundle.message || null,
|
|
432
|
+
bundle.platform,
|
|
433
|
+
bundle.targetAppVersion,
|
|
434
|
+
bundle.storageUri,
|
|
435
|
+
bundle.fingerprintHash,
|
|
436
|
+
bundle.metadata ? JSON.stringify(bundle.metadata) : JSON.stringify({})
|
|
437
|
+
];
|
|
438
|
+
await cf.d1.database.query(config.databaseId, {
|
|
439
|
+
account_id: config.accountId,
|
|
440
|
+
sql: upsertSql,
|
|
441
|
+
params
|
|
442
|
+
});
|
|
443
|
+
}
|
|
441
444
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
};
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
});
|
|
446
448
|
|
|
447
449
|
//#endregion
|
|
448
450
|
//#region ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
|
|
@@ -6796,44 +6798,45 @@ const createWrangler = ({ stdio, accountId, cloudflareApiToken, cwd }) => {
|
|
|
6796
6798
|
* })
|
|
6797
6799
|
* ```
|
|
6798
6800
|
*/
|
|
6799
|
-
const r2Storage = (
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
cloudflareApiToken,
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6801
|
+
const r2Storage = createStoragePlugin({
|
|
6802
|
+
name: "r2Storage",
|
|
6803
|
+
supportedProtocol: "r2",
|
|
6804
|
+
factory: (config) => {
|
|
6805
|
+
const { bucketName, cloudflareApiToken, accountId } = config;
|
|
6806
|
+
const wrangler = createWrangler({
|
|
6807
|
+
accountId,
|
|
6808
|
+
cloudflareApiToken,
|
|
6809
|
+
cwd: process.cwd()
|
|
6810
|
+
});
|
|
6811
|
+
const getStorageKey = createStorageKeyBuilder(config.basePath);
|
|
6812
|
+
return {
|
|
6813
|
+
async delete(storageUri) {
|
|
6814
|
+
const { bucket, key } = parseStorageUri(storageUri, "r2");
|
|
6815
|
+
if (bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${bucket}".`);
|
|
6816
|
+
try {
|
|
6817
|
+
await wrangler("r2", "object", "delete", [bucketName, key].join("/"), "--remote");
|
|
6818
|
+
} catch {
|
|
6819
|
+
throw new Error("Can not delete bundle");
|
|
6820
|
+
}
|
|
6821
|
+
},
|
|
6822
|
+
async upload(key, filePath) {
|
|
6823
|
+
const contentType = getContentType(filePath);
|
|
6824
|
+
const Key = getStorageKey(key, path$1.basename(filePath));
|
|
6825
|
+
try {
|
|
6826
|
+
const { stderr, exitCode } = await wrangler("r2", "object", "put", [bucketName, Key].join("/"), "--file", filePath, "--content-type", contentType, "--remote");
|
|
6827
|
+
if (exitCode !== 0 && stderr) throw new Error(stderr);
|
|
6828
|
+
} catch (error$1) {
|
|
6829
|
+
if (error$1 instanceof ExecaError) throw new Error(error$1.stderr || error$1.stdout);
|
|
6830
|
+
throw error$1;
|
|
6831
|
+
}
|
|
6832
|
+
return { storageUri: `r2://${bucketName}/${Key}` };
|
|
6833
|
+
},
|
|
6834
|
+
async getDownloadUrl() {
|
|
6835
|
+
throw new Error("`r2Storage` does not support `getDownloadUrl()`. Use `s3Storage` from `@hot-updater/aws` instead (compatible with Cloudflare R2).\n\nExample:\ns3Storage({\n region: 'auto',\n endpoint: 'https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com',\n credentials: {\n accessKeyId: 'YOUR_ACCESS_KEY_ID',\n secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',\n },\n bucketName: 'YOUR_BUCKET_NAME',\n})");
|
|
6828
6836
|
}
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
async getDownloadUrl() {
|
|
6833
|
-
throw new Error("`r2Storage` does not support `getDownloadUrl()`. Use `s3Storage` from `@hot-updater/aws` instead (compatible with Cloudflare R2).\n\nExample:\ns3Storage({\n region: 'auto',\n endpoint: 'https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com',\n credentials: {\n accessKeyId: 'YOUR_ACCESS_KEY_ID',\n secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',\n },\n bucketName: 'YOUR_BUCKET_NAME',\n})");
|
|
6834
|
-
}
|
|
6835
|
-
};
|
|
6836
|
-
};
|
|
6837
|
+
};
|
|
6838
|
+
}
|
|
6839
|
+
});
|
|
6837
6840
|
|
|
6838
6841
|
//#endregion
|
|
6839
6842
|
export { d1Database, r2Storage };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/cloudflare",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.21.
|
|
4
|
+
"version": "0.21.13",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"cloudflare": "4.2.0",
|
|
44
|
-
"@hot-updater/cli-tools": "0.21.
|
|
45
|
-
"@hot-updater/core": "0.21.
|
|
46
|
-
"@hot-updater/js": "0.21.
|
|
47
|
-
"@hot-updater/plugin-core": "0.21.
|
|
44
|
+
"@hot-updater/cli-tools": "0.21.13",
|
|
45
|
+
"@hot-updater/core": "0.21.13",
|
|
46
|
+
"@hot-updater/js": "0.21.13",
|
|
47
|
+
"@hot-updater/plugin-core": "0.21.13"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@cloudflare/vitest-pool-workers": "^0.8.70",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vitest": "2.1.8",
|
|
63
63
|
"wrangler": "^4.5.0",
|
|
64
64
|
"xdg-app-paths": "^8.3.0",
|
|
65
|
-
"@hot-updater/test-utils": "0.21.
|
|
65
|
+
"@hot-updater/test-utils": "0.21.13"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "tsdown && pnpm build:worker",
|
package/worker/dist/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
This folder contains the built output assets for the worker "hot-updater" generated at 2025-11-
|
|
1
|
+
This folder contains the built output assets for the worker "hot-updater" generated at 2025-11-20T01:39:30.527Z.
|