mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 10:55:27 +00:00
feat(file): optimize upload and transcoding status polling with batch api (#512)
* feat(file): optimize upload and transcoding status polling with batch api * fix(webui): throttle search invalidation during upload and fix stuck 100% progress ring * fix(webui): deduplicate upload search invalidation and stabilize batch polling
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
import {
|
||||
createCommentRequestSchema,
|
||||
deleteFilesRequestSchema,
|
||||
batchGetFilesRequestSchema,
|
||||
paginationParamsSchema,
|
||||
restoreFilesRequestSchema,
|
||||
updateAssetMetadataRequestSchema,
|
||||
@@ -39,6 +40,40 @@ import { z } from 'zod'
|
||||
type User = Prisma.UserGetPayload<Record<string, never>>
|
||||
|
||||
const route = new Hono<{ Variables: { user: User } }>()
|
||||
.post('/files/batch', zValidator('json', batchGetFilesRequestSchema), async (c) => {
|
||||
const user = c.get('user')
|
||||
const req = c.req.valid('json')
|
||||
|
||||
if (req.ids.length === 0) {
|
||||
return c.json([])
|
||||
}
|
||||
|
||||
const accessibleIds: string[] = []
|
||||
await Promise.all(
|
||||
req.ids.map(async (id) => {
|
||||
try {
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Asset,
|
||||
id,
|
||||
})
|
||||
accessibleIds.push(id)
|
||||
} catch {
|
||||
// Permissive: silently ignore missing or unauthorized IDs
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
if (accessibleIds.length === 0) {
|
||||
return c.json([])
|
||||
}
|
||||
|
||||
const accessibleSet = new Set(accessibleIds)
|
||||
const orderedAccessibleIds = req.ids.filter((id) => accessibleSet.has(id))
|
||||
const assets = await assetService.listAssetsByIds(orderedAccessibleIds)
|
||||
return c.json(assets)
|
||||
})
|
||||
.get('/files/:fileId', async (c) => {
|
||||
const fileId = c.req.param('fileId')
|
||||
const user = c.get('user')
|
||||
|
||||
Reference in New Issue
Block a user