fix: 模板调用
This commit is contained in:
parent
db5e8833c2
commit
935b1e92a3
|
|
@ -17,8 +17,8 @@ import { useTemplates } from '@/hooks/data/use-templates'
|
|||
import { usePublicTemplates } from '@/hooks/data/use-public-templates'
|
||||
import { useFavoriteTemplates } from '@/hooks/data/use-favorite-templates'
|
||||
import type { GetUserFavoritesResponse } from '@repo/sdk'
|
||||
import { useAigcTask } from '@/hooks/actions/use-aigc-task'
|
||||
import { useTemplateInteraction } from '@/hooks/actions/use-template-interaction'
|
||||
import { useTemplateActions } from '@/hooks/actions/use-template-actions'
|
||||
|
||||
const BACKGROUND_VIDEOS = [
|
||||
'https://cdn.roasmax.cn/material/b46f380532e14cf58dd350dbacc7c34a.mp4',
|
||||
|
|
@ -331,7 +331,7 @@ export default function Sync() {
|
|||
const { data: templatesData, loading: templatesLoading, execute: loadTemplates } = useTemplates()
|
||||
const { data: publicTemplatesData, loading: publicTemplatesLoading, execute: loadPublicTemplates } = usePublicTemplates()
|
||||
const { data: favoritesData, loading: favoritesLoading, execute: loadFavorites } = useFavoriteTemplates()
|
||||
const { submitTask, startPolling } = useAigcTask()
|
||||
const { runTemplate } = useTemplateActions()
|
||||
|
||||
const [searchText, setSearchText] = useState('')
|
||||
const [isSearchOpen, setIsSearchOpen] = useState(false)
|
||||
|
|
@ -375,7 +375,7 @@ export default function Sync() {
|
|||
|
||||
useEffect(() => {
|
||||
if (isAuthenticated && user?.id) {
|
||||
loadBalance(user.id)
|
||||
loadBalance()
|
||||
}
|
||||
}, [isAuthenticated, user?.id])
|
||||
|
||||
|
|
@ -574,37 +574,26 @@ export default function Sync() {
|
|||
}
|
||||
onConfirm={async () => {
|
||||
Toast.hideModal()
|
||||
|
||||
const { taskId, error } = await submitTask({
|
||||
model_name: 'default',
|
||||
prompt: `生成与 ${selectedItem.id} 相似的内容`,
|
||||
img_url: selectedItem.url,
|
||||
// 要传 扣费返回的凭证
|
||||
const { generationId, error } = await runTemplate({
|
||||
templateId: selectedItem.id,
|
||||
data: {},
|
||||
originalUrl: selectedItem.url,
|
||||
})
|
||||
|
||||
if (error) {
|
||||
Toast.show({ title: `提交失败: ${error.message}` })
|
||||
if (error || !generationId) {
|
||||
Toast.show({ title: error?.message || '生成失败' })
|
||||
return
|
||||
}
|
||||
|
||||
if (taskId) {
|
||||
Toast.show({ title: '任务提交成功,正在生成中...' })
|
||||
startPolling(
|
||||
taskId,
|
||||
(result) => {
|
||||
Toast.show({ title: '生成成功!' })
|
||||
if (user?.id) loadBalance(user.id)
|
||||
},
|
||||
(error) => {
|
||||
Toast.show({ title: `生成失败: ${error.message}` })
|
||||
},
|
||||
)
|
||||
}
|
||||
Toast.show({ title: '生成成功!' })
|
||||
if (user?.id) loadBalance()
|
||||
}}
|
||||
onCancel={() => Toast.hideModal()}
|
||||
/>,
|
||||
{},
|
||||
)
|
||||
}, [isAuthenticated, balance, selectedItem, submitTask, startPolling, user?.id, loadBalance])
|
||||
}, [isAuthenticated, balance, selectedItem, runTemplate, user?.id, loadBalance])
|
||||
|
||||
const openSearch = useCallback(() => setIsSearchOpen(true), [])
|
||||
const closeSearch = useCallback(() => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue