瀏覽代碼

makew fetch only if return files equal to limit

Abhinav-grd 4 年之前
父節點
當前提交
80d6547dfd
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      src/services/fileService.ts

+ 4 - 4
src/services/fileService.ts

@@ -76,7 +76,7 @@ export const fetchFiles = async (
     collections: collection[]
 ) => {
     let files = await localFiles();
-    const fetchedFiles = await getFiles(collections, null, "100", token);
+    const fetchedFiles = await getFiles(collections, null, 100, token);
 
     files.push(...fetchedFiles);
     var latestFiles = new Map<string, file>();
@@ -98,7 +98,7 @@ export const fetchFiles = async (
     return files;
 };
 
-export const getFiles = async (collections: collection[], sinceTime: string, limit: string, token: string): Promise<file[]> => {
+export const getFiles = async (collections: collection[], sinceTime: string, limit: number, token: string): Promise<file[]> => {
     try {
         const worker = await new CryptoWorker();
         let promises: Promise<file>[] = [];
@@ -115,7 +115,7 @@ export const getFiles = async (collections: collection[], sinceTime: string, lim
                 resp = await HTTPService.get(`${ENDPOINT}/collections/diff`, {
                     collectionID: collection.id,
                     sinceTime: time,
-                    limit,
+                    limit: limit.toString(),
                 },
                     {
                         'X-Auth-Token': token
@@ -138,7 +138,7 @@ export const getFiles = async (collections: collection[], sinceTime: string, lim
                 if (resp.data.diff.length) {
                     time = resp.data.diff.slice(-1)[0].updationTime.toString();
                 }
-            } while (resp.data.diff.length);
+            } while (resp.data.diff.length === limit);
             await localForage.setItem(`${collection.id}-time`, time);
         }
         return Promise.all(promises);