feat: s3 attachment add delete (#625)

This commit is contained in:
Dream Hunter
2025-04-07 20:17:56 +08:00
committed by GitHub
parent 31eb6c23d1
commit 32767176f0
4 changed files with 51 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ api.get('/api/webhook/settings', webhook_settings.getWebhookSettings)
api.post('/api/webhook/settings', webhook_settings.saveWebhookSettings)
api.post('/api/webhook/test', webhook_settings.testWebhookSettings)
api.get('/api/attachment/list', s3_attachment.list)
api.post('/api/attachment/delete', s3_attachment.deleteKey)
api.post('/api/attachment/put_url', s3_attachment.getSignedPutUrl)
api.post('/api/attachment/get_url', s3_attachment.getSignedGetUrl)

View File

@@ -4,7 +4,8 @@ import {
S3Client,
ListObjectsV2Command,
GetObjectCommand,
PutObjectCommand
PutObjectCommand,
DeleteObjectCommand
} from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
@@ -81,4 +82,16 @@ export default {
}
);
},
deleteKey: async (c: Context<HonoCustomType>) => {
const { address } = c.get("jwtPayload")
const { key } = await c.req.json()
const client = getS3Client(c);
await client.send(
new DeleteObjectCommand({
Bucket: c.env.S3_BUCKET,
Key: `${address}/${key}`
})
);
return c.json({ success: true });
}
}