feat: 添加文件上传功能到生成页面;修复同步页面的模板重运行接口调用
This commit is contained in:
parent
132ecfba4b
commit
e0cc2527b3
|
|
@ -2,13 +2,14 @@ import { FontAwesome, Fontisto, Ionicons } from '@expo/vector-icons'
|
|||
import { FlashList } from '@shopify/flash-list'
|
||||
import { useRouter } from 'expo-router'
|
||||
import React, { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { ActivityIndicator, RefreshControl } from 'react-native'
|
||||
import { ActivityIndicator, Platform, RefreshControl } from 'react-native'
|
||||
import { useAnimatedStyle } from 'react-native-reanimated'
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
||||
|
||||
import { imgPicker } from '@/@share/apis/imgPicker'
|
||||
import { Block, Img, Input, Text } from '@/@share/components'
|
||||
import BannerSection from '@/components/BannerSection'
|
||||
import { useFileUpload } from '@/hooks/actions'
|
||||
import { useTemplates } from '@/hooks/data/use-templates'
|
||||
import { screenHeight, screenWidth } from '@/utils'
|
||||
|
||||
|
|
@ -29,6 +30,8 @@ export default function Generate() {
|
|||
|
||||
const templates = useTemplates()
|
||||
|
||||
const { uploadFile, loading: uploadLoading } = useFileUpload()
|
||||
|
||||
useEffect(() => {
|
||||
templates.execute({ categoryId: CATEGORY_ID, page: 1, limit: 12, sortBy: 'createdAt', sortOrder: 'desc' })
|
||||
}, [])
|
||||
|
|
@ -68,10 +71,31 @@ export default function Generate() {
|
|||
}, [selectedTemplate])
|
||||
|
||||
const pickImage = useCallback(async (target: 'me' | 'friend') => {
|
||||
const [uri] = (await imgPicker({ maxImages: 1, resultType: 'uri' })) as string[]
|
||||
if (!uri) return
|
||||
const assetList = (await imgPicker({ maxImages: 1, resultType: 'asset' })) as string[]
|
||||
|
||||
const result = assetList[0] as any
|
||||
if (!result) return
|
||||
|
||||
const uri = result?.uri
|
||||
if (target === 'me') setMeImg(uri)
|
||||
else setFriendImg(uri)
|
||||
|
||||
const file = {
|
||||
name: result.fileName || `image_${Date.now()}.jpg`,
|
||||
type: result.mimeType || 'image/jpeg',
|
||||
uri: Platform.OS === 'android' ? result.uri : result.uri.replace('file://', ''),
|
||||
}
|
||||
const formData = new FormData()
|
||||
formData.append('file', file as any)
|
||||
|
||||
const { url, error } = await uploadFile(file as any)
|
||||
// console.log('pickImage---------url:', url, 'error:', error)
|
||||
|
||||
if (error || !url) {
|
||||
return
|
||||
}
|
||||
if (target === 'me') setMeImg(url)
|
||||
else setFriendImg(url)
|
||||
}, [])
|
||||
|
||||
const handleRandom = useCallback(() => {
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ const Sync = () => {
|
|||
Toast.hideModal()
|
||||
|
||||
const { generationId, error } = await reRunTemplate({
|
||||
generationId: selectedItem.id
|
||||
generationId: selectedItem.id,
|
||||
})
|
||||
|
||||
Toast.hideLoading()
|
||||
|
|
|
|||
Loading…
Reference in New Issue