fix sync
This commit is contained in:
@@ -5,6 +5,7 @@ import { File, UploadType } from 'expo-file-system';
|
||||
import NetInfo, { NetInfoState } from '@react-native-community/netinfo';
|
||||
import { safDirectory, StoredFolder } from '../services/safDirectory';
|
||||
import { fileStore } from '../services/fileStore';
|
||||
import { activeUploadUris } from '../services/uploadQueue';
|
||||
import { apiClient } from '../api/client';
|
||||
import { API_BASE_URL, ENDPOINTS } from '../constants/api';
|
||||
import { ApiError } from '../types';
|
||||
@@ -113,9 +114,12 @@ export function useAutoSync() {
|
||||
setIsSyncing(true);
|
||||
|
||||
for (const entry of pendingFiles) {
|
||||
const uri = entry.localUri;
|
||||
if (!uri || activeUploadUris.has(uri)) continue;
|
||||
activeUploadUris.add(uri);
|
||||
try {
|
||||
const uploaded = await uploadFile({
|
||||
uri: entry.localUri!,
|
||||
uri,
|
||||
type: entry.mimeType,
|
||||
name: entry.name,
|
||||
});
|
||||
@@ -134,6 +138,8 @@ export function useAutoSync() {
|
||||
});
|
||||
resetRetry(entry.id);
|
||||
}
|
||||
} finally {
|
||||
activeUploadUris.delete(uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,16 +27,6 @@ function recordToUnifiedItem(record: ReturnType<typeof fileStore.getById>): Unif
|
||||
};
|
||||
}
|
||||
|
||||
function recordsToUnifiedItems(records: ReturnType<typeof fileStore.getRootFiles>): {
|
||||
data: UnifiedFileItem[];
|
||||
meta: { page: number; total: number };
|
||||
} {
|
||||
return {
|
||||
data: records.files.map((r) => recordToUnifiedItem(r)!).filter(Boolean),
|
||||
meta: { page: 0, total: records.total },
|
||||
};
|
||||
}
|
||||
|
||||
export function useFiles(parentId?: string | null, page: number = 1, limit: number = 100) {
|
||||
const queryKey = parentId
|
||||
? ['resources', parentId, page, limit]
|
||||
@@ -65,7 +55,6 @@ export function useFiles(parentId?: string | null, page: number = 1, limit: numb
|
||||
thumbnailUrl: f.thumbnailUrl,
|
||||
})),
|
||||
);
|
||||
|
||||
const children = fileStore.getChildrenByParent(parentId);
|
||||
return {
|
||||
data: children.map((r) => recordToUnifiedItem(r)!).filter(Boolean),
|
||||
|
||||
@@ -28,19 +28,23 @@ export function useSyncQueue() {
|
||||
return;
|
||||
}
|
||||
|
||||
const registry = fileStore.getPendingSync();
|
||||
const allFolders = safDirectory.getAll();
|
||||
const autoFolderIds = new Set(
|
||||
allFolders.filter((f) => f.syncMode === 'auto').map((f) => f.id)
|
||||
);
|
||||
|
||||
const registry = fileStore.getAllLocal();
|
||||
let count = 0;
|
||||
|
||||
for (const entry of registry) {
|
||||
if (entry.backendId || !entry.localUri) continue;
|
||||
if (entry.syncStatus !== 'local' && entry.syncStatus !== 'error') continue;
|
||||
if (globalMode === 'auto') {
|
||||
count++;
|
||||
} else {
|
||||
// mode manuel : uniquement les fichiers des dossiers en mode auto
|
||||
if (!entry.parentResourceId) continue;
|
||||
const folder = safDirectory.getAll().find((f) => f.id === entry.parentResourceId);
|
||||
if (folder && folder.syncMode === 'auto') {
|
||||
count++;
|
||||
}
|
||||
if (!entry.parentResourceId || !autoFolderIds.has(entry.parentResourceId)) continue;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user