瀏覽代碼

more corrections

Abhinav-grd 4 年之前
父節點
當前提交
e8ae13221e
共有 2 個文件被更改,包括 18 次插入14 次删除
  1. 11 6
      src/services/collectionService.ts
  2. 7 8
      src/services/fileService.ts

+ 11 - 6
src/services/collectionService.ts

@@ -165,7 +165,7 @@ export const getCollectionLatestFile = (
     const collectionMap = new Map<number, collection>();
 
     collections.forEach((collection) =>
-        collectionMap.set(Number(collection.id), collection)
+        collectionMap.set(collection.id, collection)
     );
     files.forEach((file) => {
         if (!latestFile.has(file.collectionID)) {
@@ -188,7 +188,7 @@ export const getFavItemIds = async (files: file[]): Promise<Set<number>> => {
 
     return new Set(
         files
-            .filter((file) => file.collectionID === Number(favCollection.id))
+            .filter((file) => file.collectionID === favCollection.id)
             .map((file): number => file.id)
     );
 };
@@ -275,7 +275,9 @@ export const addToFavorites = async (file: file) => {
 };
 
 export const removeFromFavorites = async (file: file) => {
-    let favCollection: collection = await localForage.getItem<collection>(FAV_COLLECTION);
+    let favCollection: collection = await localForage.getItem<collection>(
+        FAV_COLLECTION
+    );
     await removeFromCollection(favCollection, [file]);
 };
 
@@ -287,7 +289,7 @@ const addtoCollection = async (collection: collection, files: file[]) => {
         params['collectionID'] = collection.id;
         await Promise.all(
             files.map(async (file) => {
-                file.collectionID = Number(collection.id);
+                file.collectionID = collection.id;
                 const newEncryptedKey: keyEncryptionResult = await worker.encryptToB64(
                     file.key,
                     collection.key
@@ -341,10 +343,13 @@ const removeFromCollection = async (collection: collection, files: file[]) => {
 
 const setLocalFavoriteCollection = async (collections: collection[]) => {
     const localFavCollection = await localForage.getItem(FAV_COLLECTION);
-    if (localFavCollection) return;
+    if (localFavCollection) {
+        return;
+    }
     const favCollection = collections.filter(
         (collection) => collection.type == CollectionType.favorites
     );
-    if (favCollection.length > 0)
+    if (favCollection.length > 0) {
         await localForage.setItem(FAV_COLLECTION, favCollection[0]);
+    }
 };

+ 7 - 8
src/services/fileService.ts

@@ -69,7 +69,7 @@ export const localFiles = async () => {
 export const syncFiles = async (token: string, collections: collection[]) => {
     let files = await localFiles();
     let isUpdated = false;
-    await removeDeletedCollectionFiles(collections, files);
+    files = await removeDeletedCollectionFiles(collections, files);
     for (let collection of collections) {
         const lastSyncTime =
             (await localForage.getItem<number>(`${collection.id}-time`)) ?? 0;
@@ -78,8 +78,7 @@ export const syncFiles = async (token: string, collections: collection[]) => {
         }
         isUpdated = true;
         let fetchedFiles =
-            (await getFiles(collection, lastSyncTime.toString(), 100, token)) ??
-            [];
+            (await getFiles(collection, lastSyncTime, 100, token)) ?? [];
         files.push(...fetchedFiles);
         var latestVersionFiles = new Map<number, file>();
         files.forEach((file) => {
@@ -111,7 +110,7 @@ export const syncFiles = async (token: string, collections: collection[]) => {
 
 export const getFiles = async (
     collection: collection,
-    sinceTime: string,
+    sinceTime: number,
     limit: number,
     token: string
 ): Promise<file[]> => {
@@ -120,15 +119,15 @@ export const getFiles = async (
         let promises: Promise<file>[] = [];
         let time =
             sinceTime ||
-            (await localForage.getItem<string>(`${collection.id}-time`)) ||
-            '0';
+            (await localForage.getItem<number>(`${collection.id}-time`)) ||
+            0;
         let resp;
         do {
             resp = await HTTPService.get(
                 `${ENDPOINT}/collections/diff`,
                 {
                     collectionID: collection.id.toString(),
-                    sinceTime: time,
+                    sinceTime: time.toString(),
                     limit: limit.toString(),
                 },
                 {
@@ -220,5 +219,5 @@ const removeDeletedCollectionFiles = async (
         syncedCollectionIds.add(collection.id);
     }
     files = files.filter((file) => syncedCollectionIds.has(file.collectionID));
-    await localForage.setItem('files', files);
+    return files;
 };