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,22 +33,18 @@ export default class Auth {
} }
) )
} else { } else {
Window.windowMap Window.windowMap.get("main")!.webContents.send(`error`, {
.get("main")! id: "ERROR_GET_AUTHURL",
.webContents.send(`error`, { message: "Failed to get auth URL to login."
id: "ERROR_GET_AUTHURL", })
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")! id: "ERROR_CONNECTION",
.webContents.send(`error`, { message: "Connection error",
id: "ERROR_CONNECTION", meta: err
message: "Connection error", })
meta: err
})
) )
}) })
ipcMain.on( ipcMain.on(
@ -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")! id: "ERROR_GET_TOKEN",
.webContents.send(`error`, { message: "Failed to get access token."
id: "ERROR_GET_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