fix: 兼容性问题
This commit is contained in:
parent
67f3c0b70e
commit
5e4f9b1292
2
app.json
2
app.json
|
|
@ -21,7 +21,7 @@
|
||||||
"edgeToEdgeEnabled": true,
|
"edgeToEdgeEnabled": true,
|
||||||
"predictiveBackGestureEnabled": false,
|
"predictiveBackGestureEnabled": false,
|
||||||
"package": "com.anonymous.bwexpoappv3",
|
"package": "com.anonymous.bwexpoappv3",
|
||||||
"versionCode": 3
|
"versionCode": 4
|
||||||
},
|
},
|
||||||
"web": {
|
"web": {
|
||||||
"output": "static",
|
"output": "static",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { ThemedView } from '@/components/themed-view';
|
import { ThemedView } from '@/components/themed-view';
|
||||||
import { getTemplateGeneration } from '@/lib/api/template-runs';
|
import { getTemplateGeneration } from '@/lib/api/template-runs';
|
||||||
import * as Clipboard from 'expo-clipboard';
|
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 * as MediaLibrary from 'expo-media-library';
|
||||||
import { router, useLocalSearchParams } from 'expo-router';
|
import { router, useLocalSearchParams } from 'expo-router';
|
||||||
import { VideoView, useVideoPlayer } from 'expo-video';
|
import { VideoView, useVideoPlayer } from 'expo-video';
|
||||||
|
|
@ -85,6 +85,14 @@ function getMediaType(url: string): 'image' | 'video' | 'unknown' {
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全获取媒体类型,过滤掉 unknown
|
||||||
|
*/
|
||||||
|
function getSafeMediaType(url: string): 'image' | 'video' {
|
||||||
|
const type = getMediaType(url);
|
||||||
|
return type === 'unknown' ? 'image' : type;
|
||||||
|
}
|
||||||
|
|
||||||
export default function ResultPage() {
|
export default function ResultPage() {
|
||||||
const { generationId } = useLocalSearchParams<{ generationId: string }>();
|
const { generationId } = useLocalSearchParams<{ generationId: string }>();
|
||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
|
|
@ -194,11 +202,17 @@ export default function ResultPage() {
|
||||||
try {
|
try {
|
||||||
// 生成临时文件名
|
// 生成临时文件名
|
||||||
const filename = url.split('/').pop() || `download_${Date.now()}`;
|
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);
|
console.log('Downloading:', url, 'to', fileUri);
|
||||||
const downloadResult = await FileSystem.downloadAsync(url, fileUri);
|
const downloadResult = await downloadAsync(url, fileUri);
|
||||||
|
|
||||||
if (downloadResult.status === 200) {
|
if (downloadResult.status === 200) {
|
||||||
// 保存到相册
|
// 保存到相册
|
||||||
|
|
@ -402,7 +416,7 @@ export default function ResultPage() {
|
||||||
style={styles.expandButton}
|
style={styles.expandButton}
|
||||||
onPress={() =>
|
onPress={() =>
|
||||||
openFullscreen(
|
openFullscreen(
|
||||||
getMediaType(mediaUrls[currentMediaIndex]),
|
getSafeMediaType(mediaUrls[currentMediaIndex]),
|
||||||
mediaUrls[currentMediaIndex]
|
mediaUrls[currentMediaIndex]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue