Add enabled checks
This commit is contained in:
parent
ade1b705d2
commit
c41c7252ae
@ -25,47 +25,74 @@
|
|||||||
|
|
||||||
class AnkiConnect {
|
class AnkiConnect {
|
||||||
constructor(server) {
|
constructor(server) {
|
||||||
|
this._enabled = true;
|
||||||
this._server = server;
|
this._server = server;
|
||||||
this._localVersion = 2;
|
this._localVersion = 2;
|
||||||
this._remoteVersion = 0;
|
this._remoteVersion = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setServer(server) {
|
||||||
|
this._server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
getServer() {
|
||||||
|
return this._server;
|
||||||
|
}
|
||||||
|
|
||||||
|
setEnabled(enabled) {
|
||||||
|
this._enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
isEnabled() {
|
||||||
|
return this._enabled;
|
||||||
|
}
|
||||||
|
|
||||||
async addNote(note) {
|
async addNote(note) {
|
||||||
|
if (!this._enabled) { return null; }
|
||||||
await this._checkVersion();
|
await this._checkVersion();
|
||||||
return await this._ankiInvoke('addNote', {note});
|
return await this._ankiInvoke('addNote', {note});
|
||||||
}
|
}
|
||||||
|
|
||||||
async canAddNotes(notes) {
|
async canAddNotes(notes) {
|
||||||
|
if (!this._enabled) { return []; }
|
||||||
await this._checkVersion();
|
await this._checkVersion();
|
||||||
return await this._ankiInvoke('canAddNotes', {notes});
|
return await this._ankiInvoke('canAddNotes', {notes});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDeckNames() {
|
async getDeckNames() {
|
||||||
|
if (!this._enabled) { return []; }
|
||||||
await this._checkVersion();
|
await this._checkVersion();
|
||||||
return await this._ankiInvoke('deckNames');
|
return await this._ankiInvoke('deckNames');
|
||||||
}
|
}
|
||||||
|
|
||||||
async getModelNames() {
|
async getModelNames() {
|
||||||
|
if (!this._enabled) { return []; }
|
||||||
await this._checkVersion();
|
await this._checkVersion();
|
||||||
return await this._ankiInvoke('modelNames');
|
return await this._ankiInvoke('modelNames');
|
||||||
}
|
}
|
||||||
|
|
||||||
async getModelFieldNames(modelName) {
|
async getModelFieldNames(modelName) {
|
||||||
|
if (!this._enabled) { return []; }
|
||||||
await this._checkVersion();
|
await this._checkVersion();
|
||||||
return await this._ankiInvoke('modelFieldNames', {modelName});
|
return await this._ankiInvoke('modelFieldNames', {modelName});
|
||||||
}
|
}
|
||||||
|
|
||||||
async guiBrowse(query) {
|
async guiBrowse(query) {
|
||||||
|
if (!this._enabled) { return []; }
|
||||||
await this._checkVersion();
|
await this._checkVersion();
|
||||||
return await this._ankiInvoke('guiBrowse', {query});
|
return await this._ankiInvoke('guiBrowse', {query});
|
||||||
}
|
}
|
||||||
|
|
||||||
async storeMediaFile(filename, dataBase64) {
|
async storeMediaFile(filename, dataBase64) {
|
||||||
|
if (!this._enabled) {
|
||||||
|
return {result: null, error: 'AnkiConnect not enabled'};
|
||||||
|
}
|
||||||
await this._checkVersion();
|
await this._checkVersion();
|
||||||
return await this._ankiInvoke('storeMediaFile', {filename, data: dataBase64});
|
return await this._ankiInvoke('storeMediaFile', {filename, data: dataBase64});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findNoteIds(notes) {
|
async findNoteIds(notes) {
|
||||||
|
if (!this._enabled) { return []; }
|
||||||
await this._checkVersion();
|
await this._checkVersion();
|
||||||
const actions = notes.map((note) => ({
|
const actions = notes.map((note) => ({
|
||||||
action: 'findNotes',
|
action: 'findNotes',
|
||||||
|
Loading…
Reference in New Issue
Block a user