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

Commit

Permalink
Revert legacy createalbum method for fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
3846masa committed Jan 25, 2020
1 parent 1815e57 commit 1d97c2b
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/GPhotos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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 { isUndefined } from 'option-t/cjs/Undefinable';

import { signinViaPuppeteer } from './signin_via_puppeteer';
import { Requestor } from './Requestor';
Expand Down Expand Up @@ -93,13 +94,51 @@ class GPhotos {
}

async createAlbum({ title }: { title: string }): Promise<GPhotosAlbum> {
try {
const {
OXvT9d: [[albumId]],
} = await this.requestor.sendBatchExecute<{
OXvT9d: [[string]];
}>({
queries: {
OXvT9d: [title, null, 2, []],
},
});

const album = new GPhotosAlbum(
{
title,
id: albumId,
type: 'album',
period: { from: new Date(0), to: new Date(0) },
itemsCount: 0,
isShared: false,
},
{ requestor: this.requestor },
);

return album;
} catch (_err) {
return this.createAlbumLegacyFallback({ title });
}
}

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

if (isUndefined(latestPhoto)) {
throw new Error('No photos exists in your account.');
}

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

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

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

return album;
}

Expand Down

0 comments on commit 1d97c2b

Please sign in to comment.