From 69b28571bdf8fb4c13198223e8a5668cf490840c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 12 Oct 2019 23:09:58 -0400 Subject: audioBuildUrl => audioGetUrl and simplify --- ext/bg/js/api.js | 2 +- ext/bg/js/audio.js | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 94a70c34..9fefadca 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -176,7 +176,7 @@ apiCommandExec.handlers = { }; async function apiAudioGetUrl(definition, source, optionsContext) { - return audioBuildUrl(definition, source, optionsContext); + return audioGetUrl(definition, source, optionsContext); } async function apiInjectScreenshot(definition, fields, screenshot) { diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js index 1a626d42..9508abf0 100644 --- a/ext/bg/js/audio.js +++ b/ext/bg/js/audio.js @@ -93,20 +93,14 @@ const audioUrlBuilders = { } }; -async function audioBuildUrl(definition, mode, optionsContext, cache={}) { - const cacheKey = `${mode}:${definition.expression}`; - if (cache.hasOwnProperty(cacheKey)) { - return Promise.resolve(cache[cacheKey]); - } - +async function audioGetUrl(definition, mode, optionsContext, download) { if (audioUrlBuilders.hasOwnProperty(mode)) { const handler = audioUrlBuilders[mode]; - return handler(definition, optionsContext).then( - (url) => { - cache[cacheKey] = url; - return url; - }, - () => null); + try { + return await handler(definition, optionsContext, download); + } catch (e) { + // NOP + } } return null; } -- cgit v1.2.3