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 #460 from 3846masa/revert-459-fix/cursor-undefined
Browse files Browse the repository at this point in the history
Revert "Fix infinity loop when search albums"
  • Loading branch information
3846masa authored Jan 19, 2020
2 parents a5209b5 + 5197d6d commit ef91862
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
20 changes: 14 additions & 6 deletions src/GPhotos.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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';
Expand Down Expand Up @@ -41,7 +40,7 @@ class GPhotos {
const {
Z5xsfc: [albumInfoList, nextCursor],
} = await this.requestor.sendBatchExecute<{
Z5xsfc: [Nullable<any[]>, Maybe<string>];
Z5xsfc: [Nullable<any[]>, Nullable<string>];
}>({
queries: {
Z5xsfc: [cursor, null, null, null, 1],
Expand All @@ -61,7 +60,7 @@ class GPhotos {
});
});

return { results: albumList, nextCursor: isNotNullAndUndefined(nextCursor) ? nextCursor : null };
return { results: albumList, nextCursor };
}

async searchAlbum({ title }: { title: string }): Promise<Nullable<GPhotosAlbum>> {
Expand All @@ -82,13 +81,17 @@ class GPhotos {
}

async createAlbum({ title }: { title: string }): Promise<GPhotosAlbum> {
const {
results: [latestPhoto],
} = await this.fetchPhotoList({ cursor: null });

const {
OXvT9d: [[albumId]],
} = await this.requestor.sendBatchExecute<{
OXvT9d: [[string]];
}>({
queries: {
OXvT9d: [title, null, 2, []],
OXvT9d: [title, null, 1, [[[latestPhoto.id]]]],
},
});

Expand All @@ -104,6 +107,11 @@ class GPhotos {
{ requestor: this.requestor },
);

const {
results: [insertedPhoto],
} = await album.fetchPhotoList({ cursor: null });
await album.remove(insertedPhoto);

return album;
}

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

return { results: photoList, nextCursor: isNotNullAndUndefined(nextCursor) ? nextCursor : null };
return { results: photoList, nextCursor };
}

async upload({
Expand Down
5 changes: 2 additions & 3 deletions src/GPhotosAlbum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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';
Expand Down Expand Up @@ -74,7 +73,7 @@ class GPhotosAlbum {
const {
snAcKc: [, photoInfoList, nextCursor],
} = await this.requestor.sendBatchExecute<{
snAcKc: [unknown, any[], Maybe<string>];
snAcKc: [unknown, any[], Nullable<string>];
}>({
queries: {
snAcKc: [this.id, cursor, null, null, 0],
Expand All @@ -85,7 +84,7 @@ class GPhotosAlbum {
return new GPhotosPhoto(GPhotosPhoto.parseInfo(info), { requestor: this.requestor });
});

return { results: photoList, nextCursor: isNotNullAndUndefined(nextCursor) ? nextCursor : null };
return { results: photoList, nextCursor };
}

async delete(): Promise<void> {
Expand Down

0 comments on commit ef91862

Please sign in to comment.