fix(booklet): Close pages when no goodie
This commit is contained in:
parent
fe523c91fe
commit
9bcba4caaa
1 changed files with 12 additions and 9 deletions
|
@ -21,7 +21,7 @@ export async function lucida(album: URL, baseTimeout: number, context: BrowserCo
|
|||
const page: Page = await openAlbum(album, context);
|
||||
|
||||
// Check 'Hide my download from recently downloaded' checkbox
|
||||
await page.locator('input[id="hide-from-recent"]').first().setChecked(true);
|
||||
await page.locator('input[id="hide-from-ticker"]').first().setChecked(true);
|
||||
|
||||
// Parse info
|
||||
const albumName: string = (await page.locator('h1[class="svelte-6pt9ji"]').last().innerText()).trim();
|
||||
|
@ -81,13 +81,16 @@ async function booklet(album: URL, context: BrowserContext): Promise<File | null
|
|||
// Find link with goodies
|
||||
const link: Locator = page.locator('a').filter({hasText: '/goodies/'});
|
||||
const linkCount: number = await link.count();
|
||||
if (linkCount > 0) {
|
||||
console.log(await link.innerHTML());
|
||||
} else {
|
||||
|
||||
if (0 <= linkCount) {
|
||||
console.log('No goodies link found');
|
||||
await page.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log(`Found goodies: ${await link.innerHTML()}`)
|
||||
let result: File | null = null;
|
||||
|
||||
try {
|
||||
// Go to the goodies link
|
||||
await link.dispatchEvent('click');
|
||||
|
@ -97,13 +100,13 @@ async function booklet(album: URL, context: BrowserContext): Promise<File | null
|
|||
const filename: string = download.suggestedFilename();
|
||||
await download.saveAs('/home/tdpeuter/Downloads/lucida/' + filename);
|
||||
|
||||
console.log(`Downloaded booklet ${filename}`);
|
||||
result = new File([await download.path()], filename);
|
||||
|
||||
await page.close();
|
||||
return new File([await download.path()], filename);
|
||||
console.log(`Downloaded booklet ${filename}`);
|
||||
} catch (e) {
|
||||
console.log('Could not download booklet:', e);
|
||||
await page.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
await page.close();
|
||||
return result;
|
||||
}
|
||||
|
|
Reference in a new issue