summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-22 21:09:43 -0500
committerGitHub <noreply@github.com>2021-01-22 21:09:43 -0500
commita51a591c404e365bc1fca657bb26c04d165f400b (patch)
treedd5176a59ce03c7bd8deb44a327ca7d56bc9d4ab /ext/bg
parent55df9dc7cdae33b782d91ac84f0ea3d8998a3b9b (diff)
Update audio validity checks to be based on the source (#1290)
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/audio-downloader.js23
1 files changed, 15 insertions, 8 deletions
diff --git a/ext/bg/js/audio-downloader.js b/ext/bg/js/audio-downloader.js
index 171f5944..495b6399 100644
--- a/ext/bg/js/audio-downloader.js
+++ b/ext/bg/js/audio-downloader.js
@@ -53,7 +53,7 @@ class AudioDownloader {
switch (info.type) {
case 'url':
try {
- return await this._downloadAudioFromUrl(info.url);
+ return await this._downloadAudioFromUrl(info.url, source);
} catch (e) {
// NOP
}
@@ -192,7 +192,7 @@ class AudioDownloader {
return [{type: 'url', url}];
}
- async _downloadAudioFromUrl(url) {
+ async _downloadAudioFromUrl(url, source) {
const response = await this._requestBuilder.fetchAnonymous(url, {
method: 'GET',
mode: 'cors',
@@ -208,18 +208,25 @@ class AudioDownloader {
const arrayBuffer = await response.arrayBuffer();
- if (!await this._isAudioBinaryValid(arrayBuffer)) {
+ if (!await this._isAudioBinaryValid(arrayBuffer, source)) {
throw new Error('Could not retrieve audio');
}
return this._arrayBufferToBase64(arrayBuffer);
}
- async _isAudioBinaryValid(arrayBuffer) {
- const digest = await this._arrayBufferDigest(arrayBuffer);
- switch (digest) {
- case 'ae6398b5a27bc8c0a771df6c907ade794be15518174773c58c7c7ddd17098906': // jpod101 invalid audio
- return false;
+ async _isAudioBinaryValid(arrayBuffer, source) {
+ switch (source) {
+ case 'jpod101':
+ {
+ const digest = await this._arrayBufferDigest(arrayBuffer);
+ switch (digest) {
+ case 'ae6398b5a27bc8c0a771df6c907ade794be15518174773c58c7c7ddd17098906': // Invalid audio
+ return false;
+ default:
+ return true;
+ }
+ }
default:
return true;
}