mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-11 08:19:01 +08:00
feat(video): add hook for handling OpenAI video status updates
This commit is contained in:
parent
6d22a635f2
commit
00221471b8
52
src/renderer/src/hooks/video/useOpenAIVideos.ts
Normal file
52
src/renderer/src/hooks/video/useOpenAIVideos.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import OpenAI from '@cherrystudio/openai'
|
||||||
|
import { useCallback } from 'react'
|
||||||
|
|
||||||
|
import { useVideos } from './useVideos'
|
||||||
|
|
||||||
|
export const useAddOpenAIVideo = (providerId: string) => {
|
||||||
|
const { addVideo } = useVideos(providerId)
|
||||||
|
|
||||||
|
const addOpenAIVideo = useCallback(
|
||||||
|
(video: OpenAI.Videos.Video) => {
|
||||||
|
switch (video.status) {
|
||||||
|
case 'queued':
|
||||||
|
addVideo({
|
||||||
|
id: video.id,
|
||||||
|
status: video.status,
|
||||||
|
type: 'openai',
|
||||||
|
metadata: video
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case 'in_progress':
|
||||||
|
addVideo({
|
||||||
|
id: video.id,
|
||||||
|
status: 'in_progress',
|
||||||
|
type: 'openai',
|
||||||
|
progress: video.progress,
|
||||||
|
metadata: video
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case 'completed':
|
||||||
|
addVideo({
|
||||||
|
id: video.id,
|
||||||
|
status: 'completed',
|
||||||
|
type: 'openai',
|
||||||
|
metadata: video
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case 'failed':
|
||||||
|
addVideo({
|
||||||
|
id: video.id,
|
||||||
|
status: 'failed',
|
||||||
|
type: 'openai',
|
||||||
|
error: video.error,
|
||||||
|
metadata: video
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[addVideo]
|
||||||
|
)
|
||||||
|
|
||||||
|
return addOpenAIVideo
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user