Add: make account.db with NeDB

This commit is contained in:
Cutls 2019-04-25 21:26:25 +09:00
parent 6786985a8a
commit 877001938a

View File

@ -1,6 +1,7 @@
import { ipcMain, Event, shell } from "electron" import { ipcMain, Event, shell, app } from "electron"
import Mastodon, { Status, Response } from "megalodon" import Mastodon, { Status, Response } from "megalodon"
import Datastore from 'nedb' import { join } from "path"
import Datastore from "nedb"
import Window from "./Window" import Window from "./Window"
export default class Auth { export default class Auth {
@ -32,18 +33,14 @@ export default class Auth {
} }
) )
} else { } else {
Window.windowMap Window.windowMap.get("main")!.webContents.send(`error`, {
.get("main")!
.webContents.send(`error`, {
id: "ERROR_GET_AUTHURL", id: "ERROR_GET_AUTHURL",
message: "Failed to get auth URL to login." message: "Failed to get auth URL to login."
}) })
} }
}) })
.catch((err: Error) => .catch((err: Error) =>
Window.windowMap Window.windowMap.get("main")!.webContents.send(`error`, {
.get("main")!
.webContents.send(`error`, {
id: "ERROR_CONNECTION", id: "ERROR_CONNECTION",
message: "Connection error", message: "Connection error",
meta: err meta: err
@ -66,20 +63,20 @@ export default class Auth {
.get<[Status]>("/accounts/verify_credentials") .get<[Status]>("/accounts/verify_credentials")
.then((resp: Response<[Status]>) => { .then((resp: Response<[Status]>) => {
console.log(resp.data) console.log(resp.data)
var db = new Datastore({
filename: join(app.getPath("userData"), "account.db")
})
db.loadDatabase()
}) })
} else { } else {
Window.windowMap Window.windowMap.get("main")!.webContents.send(`error`, {
.get("main")!
.webContents.send(`error`, {
id: "ERROR_GET_TOKEN", id: "ERROR_GET_TOKEN",
message: "Failed to get access token." message: "Failed to get access token."
}) })
} }
}) })
.catch((err: Error) => .catch((err: Error) =>
Window.windowMap Window.windowMap.get("main")!.webContents.send(`error`, {
.get("main")!
.webContents.send(`error`, {
id: "ERROR_CONNECTION", id: "ERROR_CONNECTION",
message: "Connection error", message: "Connection error",
meta: err meta: err