fix: bug
This commit is contained in:
parent
93122d9955
commit
f753bdd3c0
|
|
@ -18,8 +18,8 @@ const Img = forwardRef<ExpoImage, ImgProps>((props, ref) => {
|
|||
|
||||
// 判断是否为网络图片
|
||||
const isNetworkImage = (uri: string | number): boolean => {
|
||||
if (typeof uri === 'number') return false
|
||||
return uri?.startsWith('http://') || uri?.startsWith('https://')
|
||||
if (typeof uri !== 'string') return false
|
||||
return uri.startsWith('http://') || uri.startsWith('https://')
|
||||
}
|
||||
|
||||
// 构建图片源
|
||||
|
|
|
|||
|
|
@ -510,6 +510,7 @@ const Sync = () => {
|
|||
const asset = assetList[0]
|
||||
const isVideo = typeof asset === 'object' && asset?.type === 'video'
|
||||
const uri = typeof asset === 'object' ? asset?.uri : asset
|
||||
const fileName = typeof asset === 'object' && asset?.fileName ? asset.fileName : `upload_${Date.now()}.${isVideo ? 'mp4' : 'jpg'}`
|
||||
|
||||
Toast.showLoading({ title: '上传中...', duration: 30e3 })
|
||||
|
||||
|
|
@ -520,7 +521,7 @@ const Sync = () => {
|
|||
const file = new File([fileBlob], fileName, { type: mimeType })
|
||||
|
||||
const { url, error } = await uploadFile(file)
|
||||
|
||||
console.log({ error })
|
||||
Toast.hideLoading()
|
||||
|
||||
if (error || !url) {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ export default function GenerateVideoScreen() {
|
|||
const parsed = JSON.parse(params.template) as TemplateData
|
||||
setTemplateData(parsed)
|
||||
if (parsed.thumbnailUrl) {
|
||||
setUploadedImage(parsed.thumbnailUrl)
|
||||
// 修复:将字符串 URL 包装成 ImageSource 对象
|
||||
setUploadedImage(typeof parsed.thumbnailUrl === 'string' ? { uri: parsed.thumbnailUrl } : parsed.thumbnailUrl)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to parse template data:', error)
|
||||
|
|
@ -60,9 +61,7 @@ export default function GenerateVideoScreen() {
|
|||
}, [params.template])
|
||||
|
||||
useEffect(() => {
|
||||
if (user?.id) {
|
||||
loadBalance(user.id)
|
||||
}
|
||||
loadBalance()
|
||||
}, [user?.id])
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -72,13 +71,16 @@ export default function GenerateVideoScreen() {
|
|||
}, [])
|
||||
|
||||
const handleImageSelect = async (imageUri: any) => {
|
||||
setUploadedImage(imageUri)
|
||||
|
||||
// 修复:确保传递正确的 ImageSource 格式给 uploadedImage
|
||||
if (typeof imageUri === 'string' && (imageUri.startsWith('http://') || imageUri.startsWith('https://'))) {
|
||||
setUploadedImage({ uri: imageUri })
|
||||
setUploadedImageUrl(imageUri)
|
||||
return
|
||||
}
|
||||
|
||||
// 本地文件或 require 资源
|
||||
setUploadedImage(typeof imageUri === 'number' ? imageUri : { uri: imageUri })
|
||||
|
||||
setGenerationProgress('上传图片中...')
|
||||
const { url, error } = await uploadFile(imageUri, 'templates')
|
||||
|
||||
|
|
@ -89,6 +91,7 @@ export default function GenerateVideoScreen() {
|
|||
}
|
||||
|
||||
if (url) {
|
||||
setUploadedImage({ uri: url })
|
||||
setUploadedImageUrl(url)
|
||||
setGenerationProgress('')
|
||||
}
|
||||
|
|
@ -217,7 +220,15 @@ export default function GenerateVideoScreen() {
|
|||
</View>
|
||||
)}
|
||||
<View style={styles.thumbnailContainer}>
|
||||
<Image source={templateData?.thumbnailUrl} style={styles.thumbnail} contentFit="cover" />
|
||||
<Image
|
||||
source={
|
||||
typeof templateData?.thumbnailUrl === 'string'
|
||||
? { uri: templateData.thumbnailUrl }
|
||||
: templateData?.thumbnailUrl
|
||||
}
|
||||
style={styles.thumbnail}
|
||||
contentFit="cover"
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
{/* 上传区域 */}
|
||||
|
|
|
|||
Loading…
Reference in New Issue