From af40fc6132fc368798d8ee09acaf1d9088d57c2a Mon Sep 17 00:00:00 2001 From: 3846masa <3846masahiro+git@gmail.com> Date: Sun, 19 Jan 2020 02:57:51 +0900 Subject: [PATCH] Fix cursor type * cursor maybe undefined or null --- src/GPhotos.ts | 20 ++++++-------------- src/GPhotosAlbum.ts | 5 +++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/GPhotos.ts b/src/GPhotos.ts index de90a436..b0b4167f 100644 --- a/src/GPhotos.ts +++ b/src/GPhotos.ts @@ -1,6 +1,7 @@ import util from 'util'; import { CookieJar } from 'tough-cookie'; import { Nullable, isNotNull, isNull } from 'option-t/cjs/Nullable'; +import { Maybe, isNotNullAndUndefined } from 'option-t/cjs/Maybe'; import { signinViaPuppeteer } from './signin_via_puppeteer'; import { Requestor } from './Requestor'; @@ -40,7 +41,7 @@ class GPhotos { const { Z5xsfc: [albumInfoList, nextCursor], } = await this.requestor.sendBatchExecute<{ - Z5xsfc: [Nullable, Nullable]; + Z5xsfc: [Nullable, Maybe]; }>({ queries: { Z5xsfc: [cursor, null, null, null, 1], @@ -60,7 +61,7 @@ class GPhotos { }); }); - return { results: albumList, nextCursor }; + return { results: albumList, nextCursor: isNotNullAndUndefined(nextCursor) ? nextCursor : null }; } async searchAlbum({ title }: { title: string }): Promise> { @@ -81,17 +82,13 @@ class GPhotos { } async createAlbum({ title }: { title: string }): Promise { - const { - results: [latestPhoto], - } = await this.fetchPhotoList({ cursor: null }); - const { OXvT9d: [[albumId]], } = await this.requestor.sendBatchExecute<{ OXvT9d: [[string]]; }>({ queries: { - OXvT9d: [title, null, 1, [[[latestPhoto.id]]]], + OXvT9d: [title, null, 2, []], }, }); @@ -107,11 +104,6 @@ class GPhotos { { requestor: this.requestor }, ); - const { - results: [insertedPhoto], - } = await album.fetchPhotoList({ cursor: null }); - await album.remove(insertedPhoto); - return album; } @@ -129,7 +121,7 @@ class GPhotos { const { lcxiM: [photoInfoList, nextCursor], } = await this.requestor.sendBatchExecute<{ - lcxiM: [any[], Nullable]; + lcxiM: [any[], Maybe]; }>({ queries: { lcxiM: [cursor, null, null, null, 1], @@ -140,7 +132,7 @@ class GPhotos { return new GPhotosPhoto(GPhotosPhoto.parseInfo(info), { requestor: this.requestor }); }); - return { results: photoList, nextCursor }; + return { results: photoList, nextCursor: isNotNullAndUndefined(nextCursor) ? nextCursor : null }; } async upload({ diff --git a/src/GPhotosAlbum.ts b/src/GPhotosAlbum.ts index 82c6dbac..38c1e48f 100644 --- a/src/GPhotosAlbum.ts +++ b/src/GPhotosAlbum.ts @@ -1,5 +1,6 @@ import util from 'util'; import { Nullable } from 'option-t/cjs/Nullable'; +import { Maybe, isNotNullAndUndefined } from 'option-t/cjs/Maybe'; import { Requestor } from './Requestor'; import { GPhotosPhoto } from './GPhotosPhoto'; @@ -73,7 +74,7 @@ class GPhotosAlbum { const { snAcKc: [, photoInfoList, nextCursor], } = await this.requestor.sendBatchExecute<{ - snAcKc: [unknown, any[], Nullable]; + snAcKc: [unknown, any[], Maybe]; }>({ queries: { snAcKc: [this.id, cursor, null, null, 0], @@ -84,7 +85,7 @@ class GPhotosAlbum { return new GPhotosPhoto(GPhotosPhoto.parseInfo(info), { requestor: this.requestor }); }); - return { results: photoList, nextCursor }; + return { results: photoList, nextCursor: isNotNullAndUndefined(nextCursor) ? nextCursor : null }; } async delete(): Promise {