diff --git a/JL.Core/Mining/Anki/Note.cs b/JL.Core/Mining/Anki/Note.cs index 8d51e19b..3478666c 100644 --- a/JL.Core/Mining/Anki/Note.cs +++ b/JL.Core/Mining/Anki/Note.cs @@ -8,16 +8,16 @@ internal sealed class Note( string deckName, string modelName, Dictionary fields, - string[]? tags, - Dictionary? options, - Dictionary? audio, - Dictionary? picture, - Dictionary? video) + string[]? tags = null, + Dictionary? options = null, + Dictionary? audio = null, + Dictionary? picture = null, + Dictionary? video = null) { [JsonPropertyName("deckName")] public string DeckName { get; } = deckName; [JsonPropertyName("modelName")] public string ModelName { get; } = modelName; [JsonPropertyName("fields")] public Dictionary Fields { get; } = fields; - [JsonPropertyName("tags")] public string[]? Tags { get; } = tags; + [JsonPropertyName("tags")] public string[]? Tags { get; set; } = tags; [JsonPropertyName("options")] public Dictionary? Options { get; set; } = options; [JsonPropertyName("audio")] public Dictionary? Audio { get; set; } = audio; [JsonPropertyName("picture")] public Dictionary? Picture { get; set; } = picture; diff --git a/JL.Core/Mining/MiningUtils.cs b/JL.Core/Mining/MiningUtils.cs index bda77208..fa943ea5 100644 --- a/JL.Core/Mining/MiningUtils.cs +++ b/JL.Core/Mining/MiningUtils.cs @@ -773,13 +773,12 @@ public static async Task MineToFile(LookupResult lookupResult, string currentTex ankiConfig = ankiConfigDict.GetValueOrDefault(MineType.Other); } - if (ankiConfig is null) + if (ankiConfig is null || ankiConfig.Fields.Count is 0) { continue; } - OrderedDictionary userFields = ankiConfig.Fields; - (string firstFieldName, JLField firstField) = userFields.GetAt(0); + (string firstFieldName, JLField firstField) = ankiConfig.Fields.GetAt(0); string? firstFieldValue = GetMiningParameter(firstField, lookupResult, currentText, currentCharPosition); if (string.IsNullOrEmpty(firstFieldValue)) { @@ -791,7 +790,7 @@ public static async Task MineToFile(LookupResult lookupResult, string currentTex { firstFieldName, firstFieldValue } }; - Note note = new(ankiConfig.DeckName, ankiConfig.ModelName, fields, null, null, null, null, null); + Note note = new(ankiConfig.DeckName, ankiConfig.ModelName, fields); notes.Add(note); positions.Add(i); } @@ -861,7 +860,7 @@ public static async Task Mine(LookupResult lookupResult, string currentText, str // Audio/Picture/Video shouldn't be set here // Otherwise AnkiConnect will place them under the "collection.media" folder even when it's a duplicate note - Note note = new(ankiConfig.DeckName, ankiConfig.ModelName, fields, ankiConfig.Tags, null, null, null, null); + Note note = new(ankiConfig.DeckName, ankiConfig.ModelName, fields); bool? canAddNote = await AnkiUtils.CanAddNote(note).ConfigureAwait(false); if (canAddNote is null) { @@ -877,6 +876,14 @@ public static async Task Mine(LookupResult lookupResult, string currentText, str return; } + note.Tags = ankiConfig.Tags; + note.Options = new Dictionary(1, StringComparer.Ordinal) + { + { + "allowDuplicate", coreConfigManager.AllowDuplicateCards + } + }; + List audioFields = FindFields(JLField.Audio, userFields); bool needsAudio = audioFields.Count > 0; string reading = lookupResult.Readings?[0] ?? lookupResult.PrimarySpelling; @@ -933,13 +940,6 @@ public static async Task Mine(LookupResult lookupResult, string currentText, str }; } - note.Options = new Dictionary(1, StringComparer.Ordinal) - { - { - "allowDuplicate", coreConfigManager.AllowDuplicateCards - } - }; - Response? response = await AnkiConnect.AddNoteToDeck(note).ConfigureAwait(false); if (response is null) {