gadl/platform.ts

29 lines
744 B
TypeScript
Raw Normal View History

2023-11-19 02:25:32 +09:00
import { Database } from "./database";
import { BrowserContext } from "./browser";
function dmm(db: Database, ctx: BrowserContext) {
return {
async login() {
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),
);
},
};
}
export function createPlatform(db: Database, ctx: BrowserContext) {
const platform = dmm(db, ctx);
return {
async login() {
await platform.login();
},
};
}