diff --git a/@share/components/Img.tsx b/@share/components/Img.tsx index 4c47372..40f6da4 100644 --- a/@share/components/Img.tsx +++ b/@share/components/Img.tsx @@ -18,8 +18,8 @@ const Img = forwardRef((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://') } // 构建图片源 diff --git a/app/(tabs)/sync.tsx b/app/(tabs)/sync.tsx index 1ad7187..4ff8165 100644 --- a/app/(tabs)/sync.tsx +++ b/app/(tabs)/sync.tsx @@ -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) { diff --git a/app/generateVideo.tsx b/app/generateVideo.tsx index e11e0cf..0fc9a02 100644 --- a/app/generateVideo.tsx +++ b/app/generateVideo.tsx @@ -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() { )} - + {/* 上传区域 */}