diff --git a/image/.prettierrc b/image/.prettierrc new file mode 100644 index 0000000..c3481a7 --- /dev/null +++ b/image/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "semi": false +} \ No newline at end of file diff --git a/image/prettier.config.js b/image/prettier.config.js deleted file mode 100644 index 108b838..0000000 --- a/image/prettier.config.js +++ /dev/null @@ -1,7 +0,0 @@ -/** @type {import("prettier").Config} */ -const config = { - singleQuote: true, - semi: false, -} - -module.exports = config diff --git a/image/src/routes/ipfs.ts b/image/src/routes/ipfs.ts index 0bc16b6..0443e49 100644 --- a/image/src/routes/ipfs.ts +++ b/image/src/routes/ipfs.ts @@ -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 diff --git a/image/src/tests/ipfs.test.ts b/image/src/tests/ipfs.test.ts index 499732b..47dcc14 100644 --- a/image/src/tests/ipfs.test.ts +++ b/image/src/tests/ipfs.test.ts @@ -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'