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