mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 12:24:39 +00:00
fix local storage video preview
This commit is contained in:
+8
-24
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user