Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #461 from 3846masa/fix/cursor-falsy
Browse files Browse the repository at this point in the history
Fix to check nextCursor is empty
  • Loading branch information
3846masa authored Jan 19, 2020
2 parents ef91862 + f924726 commit a8cc597
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/GPhotos.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import util from 'util';
import { CookieJar } from 'tough-cookie';
import { Nullable, isNotNull, isNull } from 'option-t/cjs/Nullable';
import { Maybe, isNullOrUndefined } from 'option-t/cjs/Maybe';

import { signinViaPuppeteer } from './signin_via_puppeteer';
import { Requestor } from './Requestor';
Expand Down Expand Up @@ -40,7 +41,7 @@ class GPhotos {
const {
Z5xsfc: [albumInfoList, nextCursor],
} = await this.requestor.sendBatchExecute<{
Z5xsfc: [Nullable<any[]>, Nullable<string>];
Z5xsfc: [Nullable<any[]>, Maybe<string>];
}>({
queries: {
Z5xsfc: [cursor, null, null, null, 1],
Expand All @@ -60,6 +61,11 @@ class GPhotos {
});
});

// NOTE: Cursor maybe undefined or null or empty string.
if (isNullOrUndefined(nextCursor) || cursor === '') {
return { results: albumList, nextCursor: null };
}

return { results: albumList, nextCursor };
}

Expand Down Expand Up @@ -129,7 +135,7 @@ class GPhotos {
const {
lcxiM: [photoInfoList, nextCursor],
} = await this.requestor.sendBatchExecute<{
lcxiM: [any[], Nullable<string>];
lcxiM: [any[], Maybe<string>];
}>({
queries: {
lcxiM: [cursor, null, null, null, 1],
Expand All @@ -140,6 +146,11 @@ class GPhotos {
return new GPhotosPhoto(GPhotosPhoto.parseInfo(info), { requestor: this.requestor });
});

// NOTE: Cursor maybe undefined or null or empty string.
if (isNullOrUndefined(nextCursor) || nextCursor === '') {
return { results: photoList, nextCursor: null };
}

return { results: photoList, nextCursor };
}

Expand Down
8 changes: 7 additions & 1 deletion src/GPhotosAlbum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import util from 'util';
import { Nullable } from 'option-t/cjs/Nullable';
import { Maybe, isNullOrUndefined } from 'option-t/cjs/Maybe';

import { Requestor } from './Requestor';
import { GPhotosPhoto } from './GPhotosPhoto';
Expand Down Expand Up @@ -73,7 +74,7 @@ class GPhotosAlbum {
const {
snAcKc: [, photoInfoList, nextCursor],
} = await this.requestor.sendBatchExecute<{
snAcKc: [unknown, any[], Nullable<string>];
snAcKc: [unknown, any[], Maybe<string>];
}>({
queries: {
snAcKc: [this.id, cursor, null, null, 0],
Expand All @@ -84,6 +85,11 @@ class GPhotosAlbum {
return new GPhotosPhoto(GPhotosPhoto.parseInfo(info), { requestor: this.requestor });
});

// NOTE: Cursor maybe undefined or null or empty string.
if (isNullOrUndefined(nextCursor) || nextCursor === '') {
return { results: photoList, nextCursor: null };
}

return { results: photoList, nextCursor };
}

Expand Down

0 comments on commit a8cc597

Please sign in to comment.