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) {
return audioBuildUrl(definition, source, optionsContext);
return audioGetUrl(definition, source, optionsContext);
}
async function apiInjectScreenshot(definition, fields, screenshot) {

View File

@ -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;
}