logout
This commit is contained in:
parent
e696627acc
commit
7208920cd1
4 changed files with 44 additions and 24 deletions
|
@ -1,3 +1,3 @@
|
|||
import { type BrowserContext, chromium } from "playwright";
|
||||
import { type Browser, chromium } from "playwright";
|
||||
|
||||
export { BrowserContext, chromium };
|
||||
export { Browser, chromium };
|
||||
|
|
12
main.ts
12
main.ts
|
@ -21,11 +21,19 @@ const options = {
|
|||
async run() {
|
||||
const db = await createDatabase(args.values.db!);
|
||||
const browser = await chromium.launch({ headless: false });
|
||||
const ctx = await browser.newContext();
|
||||
const platform = createPlatform(db, ctx);
|
||||
const platform = createPlatform(db, browser);
|
||||
await platform.login();
|
||||
},
|
||||
},
|
||||
logout: {
|
||||
type: "boolean",
|
||||
async run() {
|
||||
const db = await createDatabase(args.values.db!);
|
||||
const browser = await chromium.launch();
|
||||
const platform = createPlatform(db, browser);
|
||||
await platform.logout();
|
||||
},
|
||||
},
|
||||
add: {
|
||||
type: "string",
|
||||
async run() {
|
||||
|
|
28
platform.ts
28
platform.ts
|
@ -1,28 +1,16 @@
|
|||
import { Database } from "./database";
|
||||
import { BrowserContext } from "./browser";
|
||||
import type { Database } from "./database";
|
||||
import type { Browser } from "./browser";
|
||||
import { DmmBooks } from "./platforms/dmm-books";
|
||||
|
||||
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);
|
||||
export function createPlatform(db: Database, browser: Browser) {
|
||||
const platform = DmmBooks(db, browser);
|
||||
|
||||
return {
|
||||
async login() {
|
||||
await platform.login();
|
||||
},
|
||||
async logout() {
|
||||
await platform.logout();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
24
platforms/dmm-books.ts
Normal file
24
platforms/dmm-books.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
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'`,
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue