MCPcopy Create free account
hub / github.com/cfworker/cfworker / bulkDelete

Function bulkDelete

packages/dev/src/cloudflare-api.js:462–486  ·  view source on GitHub ↗

* @param {{ site: StaticSite; name: string; accountId: string; accountEmail: string | undefined; apiKey: string; }} args * @param {{ id: string; }} namespace

(args, namespace)

Source from the content-addressed store, hash-verified

460 * @param {{ id: string; }} namespace
461 */
462async function bulkDelete(args, namespace) {
463 logger.progress('Removing stale site assets...');
464 const keys = await getNamespaceKeys(namespace.id, args);
465 const body = JSON.stringify(
466 keys.filter(key => !args.site.files[key.name]).map(key => key.name)
467 );
468 const response = await fetch(
469 `${apiBase}/accounts/${args.accountId}/storage/kv/namespaces/${namespace.id}/bulk`,
470 {
471 method: 'DELETE',
472 headers: Object.assign(
473 { 'content-type': 'application/json' },
474 buildAuthHeaders(args.apiKey, args.accountEmail)
475 ),
476 body
477 }
478 );
479 if (!response.ok) {
480 throw new Error(
481 `Error deleting stale KV - ${response.status}: ${
482 response.statusText
483 }\n${await response.text()}`
484 );
485 }
486}

Callers 1

getSiteBindingsFunction · 0.85

Calls 4

getNamespaceKeysFunction · 0.85
buildAuthHeadersFunction · 0.85
progressMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected