fix local storage video preview

This commit is contained in:
yiling
2026-05-26 19:38:57 +08:00
parent 11ae6d37ac
commit be2e03c1bb
3 changed files with 50 additions and 68 deletions
+8 -24
View File
@@ -1,31 +1,15 @@
import { Hono } from 'hono'
import { s3Service } from '@/services/s3/s3'
import { serveStatic } from 'hono/bun'
const route = new Hono()
.get('/:bucket/:key{.+}', async (c) => {
const bucket = c.req.param('bucket')
const key = c.req.param('key')
try {
const info = await s3Service.headObject(bucket, key)
const { buffer: data, contentType } = await s3Service.getObject(bucket, key)
if (contentType) {
c.header('Content-Type', contentType)
} else if (info.contentType) {
c.header('Content-Type', info.contentType)
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return c.body(data as any)
} catch (e: unknown) {
const error = e as Error
if (error.message?.includes('NoSuchKey')) {
return c.text('Not Found', 404)
}
return c.text(error.message || 'Internal Server Error', 500)
}
})
.get(
'/*',
serveStatic({
root: './data',
rewriteRequestPath: (path) => path.replace(/^\/files\//, ''),
}),
)
.put('/:bucket/:key{.+}', async (c) => {
const bucket = c.req.param('bucket')
const key = c.req.param('key')