Kaynağa Gözat

companion: update the pagination limit / boundary on the zoom provider (#2511)

* Fix zoom provider date pagination so that it retrieves the correct start of the next month.

* Add comments to why we are checking dates and try to make initialization of date ranges more readable
mokutsu-coursera 4 yıl önce
ebeveyn
işleme
7b9ec97070

+ 2 - 2
packages/@uppy/companion/src/server/provider/zoom/adapter.js

@@ -50,8 +50,8 @@ exports.getDateFolderModified = (end) => {
   return end.format('YYYY-MM-DD')
 }
 
-exports.getDateNextPagePath = (start) => {
-  return `?cursor=${start.subtract(1, 'days').format('YYYY-MM-DD')}`
+exports.getDateNextPagePath = (end) => {
+  return `?cursor=${end.format('YYYY-MM-DD')}`
 }
 
 exports.getNextPagePath = (results) => {

+ 9 - 7
packages/@uppy/companion/src/server/provider/zoom/index.js

@@ -186,19 +186,19 @@ class Zoom extends Provider {
 
   _initializeData (body, initialEnd = null) {
     let end = initialEnd || moment()
-    let start = end.clone().date(1)
-
     const accountCreation = adapter.getAccountCreationDate(body)
-    const defaultLimit = end.clone().subtract(DEFAULT_RANGE_MOS, 'months')
-    const limit = accountCreation > defaultLimit ? accountCreation : defaultLimit
+    const defaultLimit = end.clone().subtract(DEFAULT_RANGE_MOS, 'months').date(1)
+    const allResultsShown = accountCreation > defaultLimit
+    const limit = allResultsShown ? accountCreation : defaultLimit
+    // if the limit is mid-month, keep that exact date
+    let start = (end.isSame(limit, 'month') && limit.date() !== 1) ? limit.clone() : end.clone().date(1)
 
     const data = {
       items: [],
       username: adapter.getUserEmail(body)
     }
 
-    while (start > limit) {
-      start = end.clone().date(1)
+    while (end.isAfter(limit)) {
       data.items.push({
         isFolder: true,
         icon: 'folder',
@@ -211,8 +211,10 @@ class Zoom extends Provider {
         size: null
       })
       end = start.clone().subtract(1, 'days')
+      // if the limit is mid-month, keep that exact date
+      start = (end.isSame(limit, 'month') && limit.date() !== 1) ? limit.clone() : end.clone().date(1)
     }
-    data.nextPagePath = adapter.getDateNextPagePath(start)
+    data.nextPagePath = allResultsShown ? null : adapter.getDateNextPagePath(end.clone())
     return data
   }