summaryrefslogtreecommitdiff
path: root/ext/js/comm/anki-connect.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2022-05-30 12:03:24 -0400
committerGitHub <noreply@github.com>2022-05-30 12:03:24 -0400
commit19bba07a8bccb51a9db85c13fd921d825defe753 (patch)
tree4354e2d3396f5957a005256a85f60d239ab30c0d /ext/js/comm/anki-connect.js
parent0b5d54e7c66c17383e23855a1c3d4dbb1ea817fc (diff)
Add support for Anki API key (#2169)
* Update material.css to support password fields * Support password * Add "apiKey" setting * Use apiKey * Update options if API key changes * Update tests
Diffstat (limited to 'ext/js/comm/anki-connect.js')
-rw-r--r--ext/js/comm/anki-connect.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/ext/js/comm/anki-connect.js b/ext/js/comm/anki-connect.js
index f5dc62f2..f0aff8fa 100644
--- a/ext/js/comm/anki-connect.js
+++ b/ext/js/comm/anki-connect.js
@@ -26,6 +26,7 @@ class AnkiConnect {
this._localVersion = 2;
this._remoteVersion = 0;
this._versionCheckPromise = null;
+ this._apiKey = null;
}
get server() {
@@ -44,6 +45,14 @@ class AnkiConnect {
this._enabled = value;
}
+ get apiKey() {
+ return this._apiKey;
+ }
+
+ set apiKey(value) {
+ this._apiKey = value;
+ }
+
async isConnected() {
try {
await this._invoke('version');
@@ -230,6 +239,8 @@ class AnkiConnect {
}
async _invoke(action, params) {
+ const body = {action, params, version: this._localVersion};
+ if (this._apiKey !== null) { body.key = this._apiKey; }
let response;
try {
response = await fetch(this._server, {
@@ -242,7 +253,7 @@ class AnkiConnect {
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
- body: JSON.stringify({action, params, version: this._localVersion})
+ body: JSON.stringify(body)
});
} catch (e) {
const error = new Error('Anki connection failure');