aboutsummaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2022-05-22 11:26:49 -0400
committerGitHub <noreply@github.com>2022-05-22 11:26:49 -0400
commit259a3031ce436f86b33c4f361e2a9f919fa9db49 (patch)
treef3816f1e73da202c07f45d4f580a705cc47dc472 /ext/js
parent9800ef5140f0138e252e07d0921834dfa68f576f (diff)
Add apiReflect and apiExists to AnkiConnect (#2150)
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/comm/anki.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/ext/js/comm/anki.js b/ext/js/comm/anki.js
index 83cb8221..7ffb747b 100644
--- a/ext/js/comm/anki.js
+++ b/ext/js/comm/anki.js
@@ -167,6 +167,26 @@ class AnkiConnect {
return await this.findCards(`nid:${noteId}`);
}
+ /**
+ * Gets information about the AnkiConnect APIs available.
+ * @param {string[]} scopes A list of scopes to get information about.
+ * @param {?string[]} actions A list of actions to check for
+ * @returns {object} Information about the APIs.
+ */
+ async apiReflect(scopes, actions=null) {
+ return await this._invoke('apiReflect', {scopes, actions});
+ }
+
+ /**
+ * Checks whether a specific API action exists.
+ * @param {string} action The action to check for.
+ * @returns {boolean} Whether or not the action exists.
+ */
+ async apiExists(action) {
+ const {actions} = await this.apiReflect(['actions'], [action]);
+ return actions.includes(action);
+ }
+
// Private
async _checkVersion() {