chore: 合并一版代码
This commit is contained in:
parent
d1d7fbbe30
commit
18f7fab613
@ -3,7 +3,7 @@ import UploaderProgress from "@/components/file-upload/upload-progress/uploader-
|
|||||||
import AskNavbar from "@/components/layout/ask";
|
import AskNavbar from "@/components/layout/ask";
|
||||||
import { endUploadSessionInDb, syncUploadSessionState } from "@/features/appState/appStateSlice";
|
import { endUploadSessionInDb, syncUploadSessionState } from "@/features/appState/appStateSlice";
|
||||||
import { triggerManualUpload } from "@/lib/background-uploader/automatic";
|
import { triggerManualUpload } from "@/lib/background-uploader/automatic";
|
||||||
import { getUploadTasksSince, UploadTask } from "@/lib/db";
|
import { exist_pending_tasks, getUploadTasksSince, UploadTask } from "@/lib/db";
|
||||||
import { fetchApi } from "@/lib/server-api-util";
|
import { fetchApi } from "@/lib/server-api-util";
|
||||||
import { useAppDispatch, useAppSelector } from "@/store";
|
import { useAppDispatch, useAppSelector } from "@/store";
|
||||||
import { Chat } from "@/types/ask";
|
import { Chat } from "@/types/ask";
|
||||||
@ -54,8 +54,11 @@ const MemoList = () => {
|
|||||||
let isActive = true;
|
let isActive = true;
|
||||||
let interval: any = null;
|
let interval: any = null;
|
||||||
|
|
||||||
const manageUploadState = async () => {
|
const manageUploadState = async (restore_session: boolean = false) => {
|
||||||
if (!isActive) return;
|
if (!isActive) {
|
||||||
|
console.log('MemoList manageUploadState is not active');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 首先,同步Redux中的会话开始时间
|
// 首先,同步Redux中的会话开始时间
|
||||||
const action = await dispatch(syncUploadSessionState());
|
const action = await dispatch(syncUploadSessionState());
|
||||||
@ -86,25 +89,35 @@ const MemoList = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const triggerAndMonitor = async () => {
|
const initializeUploadProcess = async () => {
|
||||||
console.log('MemoList focused, triggering foreground media upload check.');
|
// First, check if a session is already active.
|
||||||
const now = new Date();
|
const action = await dispatch(syncUploadSessionState());
|
||||||
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
const existingSessionStartTime = action.payload as number | null;
|
||||||
|
const existPendingTasks = await exist_pending_tasks();
|
||||||
|
|
||||||
// This now returns the start time string or null
|
if (existingSessionStartTime && existPendingTasks) {
|
||||||
const sessionStartTimeStr = await triggerManualUpload(oneDayAgo, now);
|
console.log('MemoList focused, existing session found. Monitoring progress.');
|
||||||
|
// If a session exists, just start monitoring.
|
||||||
// Only start monitoring if a session was actually started.
|
manageUploadState(true); // Initial check
|
||||||
if (sessionStartTimeStr) {
|
|
||||||
console.log(`Upload session started with time: ${sessionStartTimeStr}, beginning to monitor...`);
|
|
||||||
// Immediately check the state once, then the interval will take over.
|
|
||||||
// This ensures the progress bar appears instantly.
|
|
||||||
manageUploadState();
|
|
||||||
interval = setInterval(manageUploadState, 2000);
|
interval = setInterval(manageUploadState, 2000);
|
||||||
|
} else {
|
||||||
|
// If no session, then try to trigger a new upload.
|
||||||
|
console.log('MemoList focused, no existing session. Triggering foreground media upload check.');
|
||||||
|
const now = new Date();
|
||||||
|
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
||||||
|
|
||||||
|
const newSessionStartTimeStr = await triggerManualUpload(oneDayAgo, now);
|
||||||
|
|
||||||
|
if (newSessionStartTimeStr) {
|
||||||
|
console.log(`New upload session started with time: ${newSessionStartTimeStr}, beginning to monitor...`);
|
||||||
|
// A new session was started, so start monitoring.
|
||||||
|
manageUploadState(); // Initial check
|
||||||
|
interval = setInterval(manageUploadState, 2000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
triggerAndMonitor();
|
initializeUploadProcess();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
isActive = false;
|
isActive = false;
|
||||||
@ -115,11 +128,25 @@ const MemoList = () => {
|
|||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
const renderHeader = () => (
|
||||||
<View style={[styles.container, { paddingTop: insets.top }]}>
|
<>
|
||||||
|
{process.env.NODE_ENV === 'development' && <TouchableOpacity
|
||||||
|
className='mt-2 bg-red-500 items-center h-10 justify-center'
|
||||||
|
onPress={() => router.push('/debug')}
|
||||||
|
>
|
||||||
|
<Text className="text-white">
|
||||||
|
进入db调试页面
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>}
|
||||||
|
|
||||||
|
{/* 顶部标题和上传按钮 */}
|
||||||
|
<View style={styles.header}>
|
||||||
|
<Text style={styles.title}>Memo List</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
{/* 上传进度展示区域 */}
|
{/* 上传进度展示区域 */}
|
||||||
{process.env.NODE_ENV === 'development' && uploadSessionStartTime && (
|
{uploadSessionStartTime && progressInfo.total > 0 && (
|
||||||
<View className="w-full h-20">
|
<View className="h-10 mt-6 mb-2 mx-4">
|
||||||
<UploaderProgress
|
<UploaderProgress
|
||||||
imageUrl={progressInfo.image}
|
imageUrl={progressInfo.image}
|
||||||
uploadedCount={progressInfo.completed}
|
uploadedCount={progressInfo.completed}
|
||||||
@ -127,27 +154,18 @@ const MemoList = () => {
|
|||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[styles.container, { paddingTop: insets.top }]}>
|
||||||
{/* <View className="w-full h-full">
|
{/* <View className="w-full h-full">
|
||||||
<AutoUploadScreen />
|
<AutoUploadScreen />
|
||||||
</View> */}
|
</View> */}
|
||||||
|
|
||||||
<TouchableOpacity
|
|
||||||
className='mt-2 bg-red-500 items-center h-10 justify-center'
|
|
||||||
onPress={() => router.push('/debug')}
|
|
||||||
>
|
|
||||||
<Text className="text-white">
|
|
||||||
进入db调试页面
|
|
||||||
</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
|
|
||||||
{/* 顶部标题和上传按钮 */}
|
|
||||||
<View style={styles.header}>
|
|
||||||
<Text style={styles.title}>Memo List</Text>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
{/* 历史对话 */}
|
{/* 历史对话 */}
|
||||||
<FlatList
|
<FlatList
|
||||||
|
ListHeaderComponent={renderHeader}
|
||||||
data={historyList}
|
data={historyList}
|
||||||
keyExtractor={(item) => item.session_id}
|
keyExtractor={(item) => item.session_id}
|
||||||
ItemSeparatorComponent={() => (
|
ItemSeparatorComponent={() => (
|
||||||
|
|||||||
@ -111,6 +111,13 @@ export async function getUploadTasksSince(timestamp: number): Promise<UploadTask
|
|||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function exist_pending_tasks(): Promise<boolean> {
|
||||||
|
const rows = await db.getAllAsync<UploadTask>(
|
||||||
|
'SELECT * FROM upload_tasks WHERE status = "pending" OR status = "uploading"'
|
||||||
|
);
|
||||||
|
return rows.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
// 检查一组文件URI,返回那些在数据库中不存在或是未成功上传的文件的URI
|
// 检查一组文件URI,返回那些在数据库中不存在或是未成功上传的文件的URI
|
||||||
export async function filterExistingFiles(fileUris: string[]): Promise<string[]> {
|
export async function filterExistingFiles(fileUris: string[]): Promise<string[]> {
|
||||||
if (fileUris.length === 0) {
|
if (fileUris.length === 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user