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 => {
|
const isNetworkImage = (uri: string | number): boolean => {
|
||||||
if (typeof uri === 'number') return false
|
if (typeof uri !== 'string') return false
|
||||||
return uri?.startsWith('http://') || uri?.startsWith('https://')
|
return uri.startsWith('http://') || uri.startsWith('https://')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建图片源
|
// 构建图片源
|
||||||
|
|
|
||||||
|
|
@ -510,6 +510,7 @@ const Sync = () => {
|
||||||
const asset = assetList[0]
|
const asset = assetList[0]
|
||||||
const isVideo = typeof asset === 'object' && asset?.type === 'video'
|
const isVideo = typeof asset === 'object' && asset?.type === 'video'
|
||||||
const uri = typeof asset === 'object' ? asset?.uri : asset
|
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 })
|
Toast.showLoading({ title: '上传中...', duration: 30e3 })
|
||||||
|
|
||||||
|
|
@ -520,7 +521,7 @@ const Sync = () => {
|
||||||
const file = new File([fileBlob], fileName, { type: mimeType })
|
const file = new File([fileBlob], fileName, { type: mimeType })
|
||||||
|
|
||||||
const { url, error } = await uploadFile(file)
|
const { url, error } = await uploadFile(file)
|
||||||
|
console.log({ error })
|
||||||
Toast.hideLoading()
|
Toast.hideLoading()
|
||||||
|
|
||||||
if (error || !url) {
|
if (error || !url) {
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,8 @@ export default function GenerateVideoScreen() {
|
||||||
const parsed = JSON.parse(params.template) as TemplateData
|
const parsed = JSON.parse(params.template) as TemplateData
|
||||||
setTemplateData(parsed)
|
setTemplateData(parsed)
|
||||||
if (parsed.thumbnailUrl) {
|
if (parsed.thumbnailUrl) {
|
||||||
setUploadedImage(parsed.thumbnailUrl)
|
// 修复:将字符串 URL 包装成 ImageSource 对象
|
||||||
|
setUploadedImage(typeof parsed.thumbnailUrl === 'string' ? { uri: parsed.thumbnailUrl } : parsed.thumbnailUrl)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to parse template data:', error)
|
console.error('Failed to parse template data:', error)
|
||||||
|
|
@ -60,9 +61,7 @@ export default function GenerateVideoScreen() {
|
||||||
}, [params.template])
|
}, [params.template])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user?.id) {
|
loadBalance()
|
||||||
loadBalance(user.id)
|
|
||||||
}
|
|
||||||
}, [user?.id])
|
}, [user?.id])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -72,13 +71,16 @@ export default function GenerateVideoScreen() {
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleImageSelect = async (imageUri: any) => {
|
const handleImageSelect = async (imageUri: any) => {
|
||||||
setUploadedImage(imageUri)
|
// 修复:确保传递正确的 ImageSource 格式给 uploadedImage
|
||||||
|
|
||||||
if (typeof imageUri === 'string' && (imageUri.startsWith('http://') || imageUri.startsWith('https://'))) {
|
if (typeof imageUri === 'string' && (imageUri.startsWith('http://') || imageUri.startsWith('https://'))) {
|
||||||
|
setUploadedImage({ uri: imageUri })
|
||||||
setUploadedImageUrl(imageUri)
|
setUploadedImageUrl(imageUri)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 本地文件或 require 资源
|
||||||
|
setUploadedImage(typeof imageUri === 'number' ? imageUri : { uri: imageUri })
|
||||||
|
|
||||||
setGenerationProgress('上传图片中...')
|
setGenerationProgress('上传图片中...')
|
||||||
const { url, error } = await uploadFile(imageUri, 'templates')
|
const { url, error } = await uploadFile(imageUri, 'templates')
|
||||||
|
|
||||||
|
|
@ -89,6 +91,7 @@ export default function GenerateVideoScreen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
|
setUploadedImage({ uri: url })
|
||||||
setUploadedImageUrl(url)
|
setUploadedImageUrl(url)
|
||||||
setGenerationProgress('')
|
setGenerationProgress('')
|
||||||
}
|
}
|
||||||
|
|
@ -217,7 +220,15 @@ export default function GenerateVideoScreen() {
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
<View style={styles.thumbnailContainer}>
|
<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>
|
||||||
</View>
|
</View>
|
||||||
{/* 上传区域 */}
|
{/* 上传区域 */}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue