diff --git a/package-lock.json b/package-lock.json index 58bb3992..e60cb235 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8271,8 +8271,9 @@ } }, "nedb-promises": { - "version": "git://github.com/bajankristof/nedb-promises.git#bbc45f51d1cdcb6a38fb640b11429490816b320e", - "from": "git://github.com/bajankristof/nedb-promises.git#bbc45f5", + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/nedb-promises/-/nedb-promises-3.0.5.tgz", + "integrity": "sha512-ikrcn1lXTZhuiLG+LZnYfMPxAHECsy8kUqqZ0fQVFlXlpuXQROYSRDG8+AmkAX6N0tZY+tY8P/vEsW4+eFScUA==", "dev": true, "requires": { "nedb": "^1.8.0" diff --git a/package.json b/package.json index b3f3091a..ddda2adf 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "eslint": "^5.8.0", "eslint-plugin-vue": "^5.0.0", "megalodon": "^0.6.4", - "nedb-promises": "git://github.com/bajankristof/nedb-promises.git#bbc45f5", + "nedb-promises": "^3.0.5", "postcss-nested": "^4.1.2", "typescript": "^3.4.3", "vue-cli-plugin-electron-builder": "^1.3.1", diff --git a/src/main/Auth.ts b/src/main/Auth.ts index 4909c5be..424487d6 100644 --- a/src/main/Auth.ts +++ b/src/main/Auth.ts @@ -1,12 +1,11 @@ import { ipcMain, Event, shell, app } from "electron" import Mastodon, { Response, Account, OAuth } from "megalodon" import { join } from "path" -import Datastore from "nedb" +import Datastore from "nedb-promises" import Client from "./Client" interface AccountDoc { - _id?: string domain: string acct: string full: string @@ -100,7 +99,7 @@ export default class Auth { let resp: Response = await client.get("/accounts/verify_credentials") let you = resp.data - let db = new Datastore({ + let db = Datastore.create({ filename: join(app.getPath("userData"), "account.db"), autoload: true }) @@ -114,16 +113,15 @@ export default class Auth { accessToken: tokenData.accessToken, } - db.insert(docs, function (err, newDocs) { - if (err) { - event.sender.send(`error`, { - id: "ERROR_YOU_TRY_ANOTHER_ACCOUNT", - message: "You cannot login already logined account." - }) - } else { - Client.setAuthClient('http', newDocs.full, client) - event.sender.send(`login-complete`, newDocs) - } - }) + try { + let newDoc = await db.insert(docs) + Client.setAuthClient('http', newDoc.full, client) + event.sender.send(`login-complete`, newDoc) + } catch (error) { + event.sender.send(`error`, { + id: "ERROR_YOU_TRY_ANOTHER_ACCOUNT", + message: "You cannot login already logined account." + }) + } } } diff --git a/src/main/Client.ts b/src/main/Client.ts index 18cd059b..d640dbfd 100644 --- a/src/main/Client.ts +++ b/src/main/Client.ts @@ -19,7 +19,7 @@ export default class Client { if (!clients.has(username)) { // usernameからドメインをとトークンをデータベースから取得してクライアントを作る - let db = new Datastore({ + let db = Datastore.create({ filename: join(app.getPath("userData"), "account.db"), autoload: true }) diff --git a/src/main/Timeline.ts b/src/main/Timeline.ts index 6f2210df..8c11fa85 100644 --- a/src/main/Timeline.ts +++ b/src/main/Timeline.ts @@ -39,7 +39,7 @@ export default class Timeline { return } - let db = new Datastore({ + let db = Datastore.create({ filename: join(app.getPath("userData"), "timeline.db"), autoload: true })