* @param {{ site: StaticSite; name: string; accountId: string; accountEmail: string | undefined; apiKey: string; }} args * @param {{ id: string; }} namespace
(args, namespace)
| 460 | * @param {{ id: string; }} namespace |
| 461 | */ |
| 462 | async 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 | } |
no test coverage detected