aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-25 10:46:59 -0700
committerAlex Yatskov <alex@foosoft.net>2017-03-25 10:46:59 -0700
commit20d062329bfcdc0d7c5fd07f48071ae6524f9566 (patch)
treea9b34e5eafb86c77da97a2b2a6601822f4a67d14 /ext/mixed/js/util.js
parent0e167876923ba6f20c8b84e518436f2b523e06f9 (diff)
more audio handling improvements
Diffstat (limited to 'ext/mixed/js/util.js')
-rw-r--r--ext/mixed/js/util.js31
1 files changed, 30 insertions, 1 deletions
diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js
index 13f124a0..1289455c 100644
--- a/ext/mixed/js/util.js
+++ b/ext/mixed/js/util.js
@@ -21,7 +21,7 @@
* Audio
*/
-function audioBuildUrl(definition, cache) {
+function audioBuildUrl(definition, cache={}) {
return new Promise((resolve, reject) => {
const response = cache[definition.expression];
if (response) {
@@ -78,3 +78,32 @@ function audioBuildFilename(definition) {
return filename += '.mp3';
}
}
+
+function audioInject(definition, fields) {
+ const filename = audioBuildFilename(definition);
+ if (!filename) {
+ return Promise.resolve(true);
+ }
+
+ const audio = {
+ filename,
+ skipHash: '7e2c2f954ef6051373ba916f000168dc',
+ fields: []
+ };
+
+ for (const name in fields) {
+ if (fields[name].includes('{audio}')) {
+ audio.fields.push(name);
+ }
+ }
+
+ if (audio.fields.length === 0) {
+ return Promise.resolve(true);
+ }
+
+ return audioBuildUrl(definition).then(url => {
+ audio.url = url;
+ note.audio = audio;
+ return true;
+ }).catch(() => false);
+}