From 5e4f9b1292d536a3aad144a0dae99b23dd65609e Mon Sep 17 00:00:00 2001 From: imeepos Date: Wed, 12 Nov 2025 14:54:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.json | 2 +- app/result.tsx | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app.json b/app.json index 8c0a32a..b499e33 100644 --- a/app.json +++ b/app.json @@ -21,7 +21,7 @@ "edgeToEdgeEnabled": true, "predictiveBackGestureEnabled": false, "package": "com.anonymous.bwexpoappv3", - "versionCode": 3 + "versionCode": 4 }, "web": { "output": "static", diff --git a/app/result.tsx b/app/result.tsx index 2a0f686..2b65d9c 100644 --- a/app/result.tsx +++ b/app/result.tsx @@ -1,7 +1,7 @@ import { ThemedView } from '@/components/themed-view'; import { getTemplateGeneration } from '@/lib/api/template-runs'; import * as Clipboard from 'expo-clipboard'; -import * as FileSystem from 'expo-file-system'; +import { documentDirectory, downloadAsync } from 'expo-file-system/legacy'; import * as MediaLibrary from 'expo-media-library'; import { router, useLocalSearchParams } from 'expo-router'; import { VideoView, useVideoPlayer } from 'expo-video'; @@ -85,6 +85,14 @@ function getMediaType(url: string): 'image' | 'video' | 'unknown' { return 'unknown'; } +/** + * 安全获取媒体类型,过滤掉 unknown + */ +function getSafeMediaType(url: string): 'image' | 'video' { + const type = getMediaType(url); + return type === 'unknown' ? 'image' : type; +} + export default function ResultPage() { const { generationId } = useLocalSearchParams<{ generationId: string }>(); const insets = useSafeAreaInsets(); @@ -194,11 +202,17 @@ export default function ResultPage() { try { // 生成临时文件名 const filename = url.split('/').pop() || `download_${Date.now()}`; - const fileUri = `${FileSystem.documentDirectory}${filename}`; + + if (!documentDirectory) { + console.error('Document directory not available'); + continue; + } + + const fileUri = `${documentDirectory}${filename}`; // 下载文件到本地 console.log('Downloading:', url, 'to', fileUri); - const downloadResult = await FileSystem.downloadAsync(url, fileUri); + const downloadResult = await downloadAsync(url, fileUri); if (downloadResult.status === 200) { // 保存到相册 @@ -402,7 +416,7 @@ export default function ResultPage() { style={styles.expandButton} onPress={() => openFullscreen( - getMediaType(mediaUrls[currentMediaIndex]), + getSafeMediaType(mediaUrls[currentMediaIndex]), mediaUrls[currentMediaIndex] ) }