Skip to content

Commit 4e726fb

Browse files
authored
feat(config-storage-service): support delete method (#600)
1 parent 99b6bce commit 4e726fb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

localenv/s3/worker.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ export default {
33
if (request.method === 'PUT') {
44
return handlePut(request, env)
55
}
6+
if (request.method === 'DELETE') {
7+
return handleDelete(request, env)
8+
}
69

710
const { pathname } = new URL(request.url)
811
if (request.method === 'GET' && pathname === '/') {
@@ -46,3 +49,11 @@ async function handlePut(request: Request, env: Env) {
4649
})
4750
return Response.json(res)
4851
}
52+
53+
async function handleDelete(request: Request, env: Env) {
54+
const { pathname } = new URL(request.url)
55+
const key = pathname.slice(1)
56+
57+
await env.STORAGE.delete(key)
58+
return Response.json({ message: 'deleted' })
59+
}

shared/config-storage-service/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ export class ConfigStorageService {
6565
throw new Error(`Failed to upload to S3: ${response.status}`)
6666
}
6767
}
68+
69+
async delete(walletAddress: string): Promise<void> {
70+
const key = walletAddressToKey(walletAddress)
71+
const prefix = this.prefix
72+
const url = new URL(`${prefix}/${key}`, this.endpoint)
73+
74+
const res = await this.client.fetch(url, { method: 'DELETE' })
75+
if (!res.ok) {
76+
throw new Error(`Failed to delete from S3: ${res.status}`)
77+
}
78+
}
6879
}
6980

7081
export const isConfigStorageNotFoundError = (

0 commit comments

Comments
 (0)