mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-01 06:22:44 -08:00
fix(anki): avoid unintended kiku grouping on lookup
This commit is contained in:
@@ -179,6 +179,7 @@ export class AnkiConnectProxyServer {
|
||||
if (action !== 'addNote' && action !== 'addNotes' && action !== 'multi') {
|
||||
return;
|
||||
}
|
||||
const shouldFallbackToLatestAdded = this.requestIncludesAddAction(action, requestJson);
|
||||
|
||||
const parsedResponse = this.tryParseJsonValue(responseBody);
|
||||
if (parsedResponse === null || parsedResponse === undefined) {
|
||||
@@ -194,7 +195,7 @@ export class AnkiConnectProxyServer {
|
||||
action === 'multi'
|
||||
? this.collectMultiResultIds(requestJson, responseResult)
|
||||
: this.collectNoteIdsForAction(action, responseResult);
|
||||
if (noteIds.length === 0) {
|
||||
if (noteIds.length === 0 && shouldFallbackToLatestAdded) {
|
||||
void this.enqueueMostRecentAddedNote();
|
||||
return;
|
||||
}
|
||||
@@ -202,6 +203,28 @@ export class AnkiConnectProxyServer {
|
||||
this.enqueueNotes(noteIds);
|
||||
}
|
||||
|
||||
private requestIncludesAddAction(action: string, requestJson: Record<string, unknown>): boolean {
|
||||
if (action === 'addNote' || action === 'addNotes') {
|
||||
return true;
|
||||
}
|
||||
if (action !== 'multi') {
|
||||
return false;
|
||||
}
|
||||
const params =
|
||||
requestJson.params && typeof requestJson.params === 'object'
|
||||
? (requestJson.params as Record<string, unknown>)
|
||||
: null;
|
||||
const actions = Array.isArray(params?.actions) ? params.actions : [];
|
||||
if (actions.length === 0) {
|
||||
return false;
|
||||
}
|
||||
return actions.some((entry) => {
|
||||
if (!entry || typeof entry !== 'object') return false;
|
||||
const actionName = (entry as Record<string, unknown>).action;
|
||||
return actionName === 'addNote' || actionName === 'addNotes';
|
||||
});
|
||||
}
|
||||
|
||||
private async enqueueMostRecentAddedNote(): Promise<void> {
|
||||
const findNotes = this.deps.findNotes;
|
||||
if (!findNotes) {
|
||||
|
||||
Reference in New Issue
Block a user