import type { Database } from "../database"; import type { Browser } from "../browser"; export function DmmBooks(db: Database, browser: Browser) { return { async login() { const ctx = await browser.newContext(); const page = await ctx.newPage(); await page.goto("https://accounts.dmm.com/service/login/password"); await page.waitForURL("https://www.dmm.com/", { timeout: 0 }); const secrets = await ctx.storageState(); await ctx.close(); await db.run( `update platforms set secrets = ? where name = 'dmm-books'`, JSON.stringify(secrets), ); }, async logout() { await db.run( `update platforms set secrets = 'null' where name = 'dmm-books'`, ); }, }; }