Add findNoteIds to AnkiConnect
This commit is contained in:
parent
c5d6b9452d
commit
97f5b7139f
@ -72,9 +72,34 @@ class AnkiConnect {
|
||||
}
|
||||
}
|
||||
|
||||
async findNoteIds(notes) {
|
||||
await this.checkVersion();
|
||||
const actions = notes.map(note => ({
|
||||
action: 'findNotes',
|
||||
params: {
|
||||
query: `deck:"${AnkiConnect.escapeQuery(note.deckName)}" ${AnkiConnect.fieldsToQuery(note.fields)}`
|
||||
}
|
||||
}));
|
||||
return await this.ankiInvoke('multi', {actions});
|
||||
}
|
||||
|
||||
ankiInvoke(action, params) {
|
||||
return requestJson(this.server, 'POST', {action, params, version: this.localVersion});
|
||||
}
|
||||
|
||||
static escapeQuery(text) {
|
||||
return text.replace(/"/g, '');
|
||||
}
|
||||
|
||||
static fieldsToQuery(fields) {
|
||||
const fieldNames = Object.keys(fields);
|
||||
if (fieldNames.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const key = fieldNames[0];
|
||||
return `${key.toLowerCase()}:"${AnkiConnect.escapeQuery(fields[key])}"`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -106,4 +131,8 @@ class AnkiNull {
|
||||
async guiBrowse(query) {
|
||||
return [];
|
||||
}
|
||||
|
||||
async findNoteIds(notes) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user