audioBuildUrl => audioGetUrl and simplify

This commit is contained in:
toasted-nutbread 2019-10-12 23:09:58 -04:00
parent 54d4c65854
commit 69b28571bd
2 changed files with 7 additions and 13 deletions

View File

@ -176,7 +176,7 @@ apiCommandExec.handlers = {
}; };
async function apiAudioGetUrl(definition, source, optionsContext) { async function apiAudioGetUrl(definition, source, optionsContext) {
return audioBuildUrl(definition, source, optionsContext); return audioGetUrl(definition, source, optionsContext);
} }
async function apiInjectScreenshot(definition, fields, screenshot) { async function apiInjectScreenshot(definition, fields, screenshot) {

View File

@ -93,20 +93,14 @@ const audioUrlBuilders = {
} }
}; };
async function audioBuildUrl(definition, mode, optionsContext, cache={}) { async function audioGetUrl(definition, mode, optionsContext, download) {
const cacheKey = `${mode}:${definition.expression}`;
if (cache.hasOwnProperty(cacheKey)) {
return Promise.resolve(cache[cacheKey]);
}
if (audioUrlBuilders.hasOwnProperty(mode)) { if (audioUrlBuilders.hasOwnProperty(mode)) {
const handler = audioUrlBuilders[mode]; const handler = audioUrlBuilders[mode];
return handler(definition, optionsContext).then( try {
(url) => { return await handler(definition, optionsContext, download);
cache[cacheKey] = url; } catch (e) {
return url; // NOP
}, }
() => null);
} }
return null; return null;
} }