aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-07-10 16:48:26 -0700
committerAlex Yatskov <alex@foosoft.net>2017-07-10 16:48:26 -0700
commit1ed8997240ba5d8ee4fe57062d2dbe8ba46436e2 (patch)
tree2d404805f47eb5bbaadb3783fdb9e634e08a3dc6 /ext
parente2373345a4a615ec59a45a6c3c75408826fef9c6 (diff)
work on audio
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/database.js3
-rw-r--r--ext/mixed/js/util.js31
2 files changed, 16 insertions, 18 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index 45ba3d08..b38e00db 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -32,8 +32,7 @@ class Database {
if (db.verno !== this.version) {
await db.delete();
}
- }
- catch(error) {
+ } catch(e) {
// NOP
}
}
diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js
index 5cf62000..0a8c914d 100644
--- a/ext/mixed/js/util.js
+++ b/ext/mixed/js/util.js
@@ -40,7 +40,7 @@ function clozeBuild(sentence, source) {
* Audio
*/
-function audioBuildUrl(definition, mode, cache={}) {
+async function audioBuildUrl(definition, mode, cache={}) {
if (mode === 'jpod101') {
let kana = definition.reading;
let kanji = definition.expression;
@@ -103,7 +103,7 @@ function audioBuildUrl(definition, mode, cache={}) {
}
});
} else {
- return Promise.reject('unsupported audio source');
+ return Promise.resolve();
}
}
@@ -121,16 +121,7 @@ function audioBuildFilename(definition) {
}
}
-function audioInject(definition, fields, mode) {
- if (mode === 'disabled') {
- return Promise.resolve(true);
- }
-
- const filename = audioBuildFilename(definition);
- if (!filename) {
- return Promise.resolve(true);
- }
-
+async function audioInject(definition, fields, mode) {
let usesAudio = false;
for (const name in fields) {
if (fields[name].includes('{audio}')) {
@@ -140,11 +131,19 @@ function audioInject(definition, fields, mode) {
}
if (!usesAudio) {
- return Promise.resolve(true);
+ return true;
}
- return audioBuildUrl(definition, mode).then(url => {
- definition.audio = {url, filename};
+ try {
+ const url = await audioBuildUrl(definition, mode);
+ const filename = audioBuildFilename(definition);
+
+ if (url && filename) {
+ definition.audio = {url, filename};
+ }
+
return true;
- }).catch(() => false);
+ } catch (e) {
+ return false;
+ }
}