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() {
|
async run() {
|
||||||
const db = await createDatabase(args.values.db!);
|
const db = await createDatabase(args.values.db!);
|
||||||
const browser = await chromium.launch({ headless: false });
|
const browser = await chromium.launch({ headless: false });
|
||||||
const ctx = await browser.newContext();
|
const platform = createPlatform(db, browser);
|
||||||
const platform = createPlatform(db, ctx);
|
|
||||||
await platform.login();
|
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: {
|
add: {
|
||||||
type: "string",
|
type: "string",
|
||||||
async run() {
|
async run() {
|
||||||
|
|
28
platform.ts
28
platform.ts
|
@ -1,28 +1,16 @@
|
||||||
import { Database } from "./database";
|
import type { Database } from "./database";
|
||||||
import { BrowserContext } from "./browser";
|
import type { Browser } from "./browser";
|
||||||
|
import { DmmBooks } from "./platforms/dmm-books";
|
||||||
|
|
||||||
function dmm(db: Database, ctx: BrowserContext) {
|
export function createPlatform(db: Database, browser: Browser) {
|
||||||
return {
|
const platform = DmmBooks(db, browser);
|
||||||
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 {
|
return {
|
||||||
async login() {
|
async login() {
|
||||||
await platform.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