Browse Source

change collection id type to number

Abhinav-grd 4 năm trước cách đây
mục cha
commit
71af57409a

+ 4 - 3
src/services/collectionService.ts

@@ -22,7 +22,7 @@ enum CollectionType {
 }
 }
 
 
 export interface collection {
 export interface collection {
-    id: string;
+    id: number;
     owner: user;
     owner: user;
     key?: string;
     key?: string;
     name?: string;
     name?: string;
@@ -111,7 +111,7 @@ export const fetchUpdatedCollections = async (token: string, key: string) => {
     const favCollection = await localForage.getItem('fav-collection') as collection[] ?? updatedCollections.filter(collection => collection.type === CollectionType.favorites);
     const favCollection = await localForage.getItem('fav-collection') as collection[] ?? updatedCollections.filter(collection => collection.type === CollectionType.favorites);
     const localCollections = await getLocalCollections();
     const localCollections = await getLocalCollections();
     const allCollectionsInstances = [...localCollections, ...updatedCollections];
     const allCollectionsInstances = [...localCollections, ...updatedCollections];
-    var latestCollectionsInstances = new Map<string, collection>();
+    var latestCollectionsInstances = new Map<number, collection>();
     allCollectionsInstances.forEach((collection) => {
     allCollectionsInstances.forEach((collection) => {
         if (!latestCollectionsInstances.has(collection.id) || latestCollectionsInstances.get(collection.id).updationTime < collection.updationTime) {
         if (!latestCollectionsInstances.has(collection.id) || latestCollectionsInstances.get(collection.id).updationTime < collection.updationTime) {
             latestCollectionsInstances.set(collection.id, collection);
             latestCollectionsInstances.set(collection.id, collection);
@@ -119,8 +119,9 @@ export const fetchUpdatedCollections = async (token: string, key: string) => {
     });
     });
     let collections = [];
     let collections = [];
     for (const [_, collection] of latestCollectionsInstances) {
     for (const [_, collection] of latestCollectionsInstances) {
-        if (!collection.isDeleted)
+        if (!collection.isDeleted){
             collections.push(collection);
             collections.push(collection);
+        }
     }
     }
     await localForage.setItem('fav-collection', favCollection);
     await localForage.setItem('fav-collection', favCollection);
     await localForage.setItem('collections', collections);
     await localForage.setItem('collections', collections);

+ 7 - 6
src/services/fileService.ts

@@ -76,16 +76,16 @@ export const fetchFiles = async (
     collections: collection[]
     collections: collection[]
 ) => {
 ) => {
     let files = await localFiles();
     let files = await localFiles();
-    const collectionUpdationTime = new Map<string, string>();
+    const collectionUpdationTime = new Map<number, number>();
     let fetchedFiles = [];
     let fetchedFiles = [];
-    let deletedCollection = new Set<string>();
+    let deletedCollection = new Set<number>();
     for (let collection of collections) {
     for (let collection of collections) {
         if (collection.isDeleted) {
         if (collection.isDeleted) {
             deletedCollection.add(collection.id);
             deletedCollection.add(collection.id);
         }
         }
         const files = await getFiles(collection, null, 100, token);
         const files = await getFiles(collection, null, 100, token);
         fetchedFiles.push(...files);
         fetchedFiles.push(...files);
-        collectionUpdationTime.set(collection.id, files.length > 0 ? files.slice(-1)[0].updationTime.toString() : "0");
+        collectionUpdationTime.set(collection.id, files.length > 0 ? files.slice(-1)[0].updationTime : 0);
     }
     }
     files.push(...fetchedFiles);
     files.push(...fetchedFiles);
     var latestFiles = new Map<string, file>();
     var latestFiles = new Map<string, file>();
@@ -97,9 +97,10 @@ export const fetchFiles = async (
     });
     });
     files = [];
     files = [];
     for (const [_, file] of latestFiles) {
     for (const [_, file] of latestFiles) {
-        if (!(file.isDeleted || deletedCollection.has(file.collectionID.toString()))) {
-            files.push(file);
+        if (file.isDeleted || deletedCollection.has(file.collectionID)) {
+            continue;
         }
         }
+        files.push(file);
     }
     }
     files = files.sort(
     files = files.sort(
         (a, b) => b.metadata.creationTime - a.metadata.creationTime
         (a, b) => b.metadata.creationTime - a.metadata.creationTime
@@ -129,7 +130,7 @@ export const getFiles = async (collection: collection, sinceTime: string, limit:
         let resp;
         let resp;
         do {
         do {
             resp = await HTTPService.get(`${ENDPOINT}/collections/diff`, {
             resp = await HTTPService.get(`${ENDPOINT}/collections/diff`, {
-                collectionID: collection.id,
+                collectionID: collection.id.toString(),
                 sinceTime: time,
                 sinceTime: time,
                 limit: limit.toString(),
                 limit: limit.toString(),
             },
             },