Skip to content

Commit

Permalink
refactor: handle delete on image workers
Browse files Browse the repository at this point in the history
  • Loading branch information
preschian committed Dec 6, 2023
1 parent 69e11b2 commit f570bc6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
4 changes: 4 additions & 0 deletions image/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"semi": false
}
7 changes: 0 additions & 7 deletions image/prettier.config.js

This file was deleted.

14 changes: 14 additions & 0 deletions image/src/routes/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,18 @@ app.get('/*', async (c) => {
}
})

app.delete('/*', async (c) => {
const url = new URL(c.req.url)
const path = url.pathname.replace('/ipfs/', '')
const objectName = `ipfs/${path}`

try {
await c.env.MY_BUCKET.delete(objectName)

return c.json({ status: 'ok' })
} catch (error) {
return c.json({ status: 'error', error }, 500)
}
})

export default app
11 changes: 11 additions & 0 deletions image/src/tests/ipfs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { expect, test } from 'vitest'

test('[head] ipfs - 200 - json', async () => {
const res = await fetch(
'https://image-beta.w.kodadot.xyz/ipfs/bafkreihy6xwb35imb5hfwxzgmw2p64yoefuxysh6bkghyjwaj7tz5sfnuq',
{ method: 'HEAD' }
)

expect(res.ok).toBe(true)
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toBe('application/json')
})

test('ipfs - 200 - json', async () => {
const res = await fetch(
'https://image-beta.w.kodadot.xyz/ipfs/bafkreihy6xwb35imb5hfwxzgmw2p64yoefuxysh6bkghyjwaj7tz5sfnuq'
Expand Down

0 comments on commit f570bc6

Please sign in to comment.