logmein
Viewing readonly version: 127View latest version
Script
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { extractProjectValInfo } from "https://esm.town/v/maxm/extractProjectValInfo";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite?v=13";
const projectInfo = extractProjectValInfo(import.meta.url);
export type Config = {
login_type: "email" | "password";
id: number;
};
class DB {
#tableNamePrefix: string;
constructor(tableNamePrefix: string) {
this.#tableNamePrefix = tableNamePrefix;
}
async getConfig(): Promise<Config | undefined> {
const res = await sqlite
.execute(`SELECT * FROM ${this.#tableNamePrefix}_logmein_config LIMIT 1`);
if (res.rows.length === 0) {
return undefined;
}
return res.rows[0] as unknown as Config;
}
async writeConfig(loginType: Config["login_type"]): Promise<Config | undefined> {
const res = await sqlite
.execute(
`INSERT OR REPLACE INTO ${this.#tableNamePrefix}_logmein_config(id, login_type) VALUES (?, ?) RETURNING *`,
[1, loginType],
);
if (res.rows.length === 0) {
throw new Error("Failed to write config");
}
return res.rows[0] as unknown as Config;
}
async newSession() {