mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 23:54:25 +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:
@@ -119,11 +119,6 @@ export function FileCard({
|
||||
: 0
|
||||
: 0
|
||||
|
||||
const shouldPoll =
|
||||
(item.type === 'file' || item.type === 'version_stack') &&
|
||||
!!teamId &&
|
||||
(item.status === 'uploading' || item.status === 'uploaded' || item.status === 'processing')
|
||||
|
||||
const { data: polledItem } = useQuery({
|
||||
queryKey: ['file', teamId, item.id],
|
||||
queryFn: async () => {
|
||||
@@ -133,13 +128,7 @@ export function FileCard({
|
||||
if (!res.ok) throw new Error('failed to fetch file')
|
||||
return (await res.json()) as unknown as AssetInfo
|
||||
},
|
||||
enabled: shouldPoll,
|
||||
refetchInterval: (query: unknown) => {
|
||||
const data = (query as { state: { data: { status?: string } } }).state.data
|
||||
return data?.status === 'processed' || data?.status === 'failed' || data?.status === 'error'
|
||||
? false
|
||||
: 1000
|
||||
},
|
||||
enabled: false,
|
||||
})
|
||||
|
||||
const displayItem = useMemo(() => {
|
||||
@@ -277,16 +266,16 @@ export function FileCard({
|
||||
// since the poster/sprite are generated and persisted ahead of the proxy transcodes.
|
||||
const hasPreview = Boolean(displayItem.preview?.thumbnailUrl || displayItem.preview?.spriteUrl)
|
||||
const isFailed = displayItem.status === 'failed'
|
||||
const isProcessing = displayItem.status === 'processing' || displayItem.status === 'uploaded'
|
||||
const isUploadDone = fileUploadState?.status === 'completed' || uploadPercent >= 100
|
||||
const isUploading = displayItem.status === 'uploading' && !isUploadDone
|
||||
const isProcessing =
|
||||
displayItem.status === 'processing' ||
|
||||
displayItem.status === 'uploaded' ||
|
||||
(displayItem.status === 'uploading' && isUploadDone)
|
||||
|
||||
// While uploading/transcoding, the creator row is replaced by a short status label so the real
|
||||
// date/author only appears once the asset is ready or failed.
|
||||
const statusText =
|
||||
displayItem.status === 'uploading'
|
||||
? m.uploading()
|
||||
: displayItem.status === 'uploaded' || displayItem.status === 'processing'
|
||||
? m.preparing()
|
||||
: null
|
||||
const statusText = isUploading ? m.uploading() : isProcessing ? m.preparing() : null
|
||||
|
||||
const failedErrorMessage = displayItem.media?.error || m.processing_failed()
|
||||
|
||||
@@ -393,7 +382,7 @@ export function FileCard({
|
||||
</div>
|
||||
|
||||
<div className="relative aspect-square overflow-hidden bg-muted/30">
|
||||
{displayItem.status === 'uploading' ? (
|
||||
{isUploading ? (
|
||||
<div className="flex h-full w-full items-center justify-center bg-background/50">
|
||||
<ProgressCircle progress={uploadPercent} className="w-16 h-16 z-10" />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user