From 259a3031ce436f86b33c4f361e2a9f919fa9db49 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 22 May 2022 11:26:49 -0400 Subject: Add apiReflect and apiExists to AnkiConnect (#2150) --- ext/js/comm/anki.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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() { -- cgit v1.2.3