diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-09-09 21:07:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-09 21:07:18 -0400 |
commit | 58e5ddfde00eb28ac3a12cd2c83c1088a63d7d23 (patch) | |
tree | 7ea4b3c26cec99e22a73b6edcbd17e101a2e4b29 /ext/bg/js/anki-note-builder.js | |
parent | 5d2261acb972374c45fca022f121609405873e90 (diff) |
Generalize AnkiNoteBuilder to not use audioSystem directly (#796)
Diffstat (limited to 'ext/bg/js/anki-note-builder.js')
-rw-r--r-- | ext/bg/js/anki-note-builder.js | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/ext/bg/js/anki-note-builder.js b/ext/bg/js/anki-note-builder.js index b46bf3ba..72e3b337 100644 --- a/ext/bg/js/anki-note-builder.js +++ b/ext/bg/js/anki-note-builder.js @@ -20,9 +20,9 @@ */ class AnkiNoteBuilder { - constructor({audioSystem, renderTemplate, getClipboardImage=null, getScreenshot=null}) { - this._audioSystem = audioSystem; + constructor({renderTemplate, getDefinitionAudio=null, getClipboardImage=null, getScreenshot=null}) { this._renderTemplate = renderTemplate; + this._getDefinitionAudio = getDefinitionAudio; this._getClipboardImage = getClipboardImage; this._getScreenshot = getScreenshot; } @@ -130,7 +130,7 @@ class AnkiNoteBuilder { if (fileName === null) { return; } fileName = this._replaceInvalidFileNameCharacters(fileName); - const {audio} = await this._audioSystem.getDefinitionAudio( + const {audio: data} = await this._getDefinitionAudio( audioSourceDefinition, sources, { @@ -141,7 +141,6 @@ class AnkiNoteBuilder { } ); - const data = this._arrayBufferToBase64(audio); await anki.storeMediaFile(fileName, data); definition.audioFileName = fileName; @@ -260,10 +259,6 @@ class AnkiNoteBuilder { return fileName.replace(/[<>:"/\\|?*\x00-\x1F]/g, '-'); } - _arrayBufferToBase64(arrayBuffer) { - return btoa(String.fromCharCode(...new Uint8Array(arrayBuffer))); - } - _stringReplaceAsync(str, regex, replacer) { let match; let index = 0; |