work on audio
This commit is contained in:
parent
e2373345a4
commit
1ed8997240
@ -32,8 +32,7 @@ class Database {
|
|||||||
if (db.verno !== this.version) {
|
if (db.verno !== this.version) {
|
||||||
await db.delete();
|
await db.delete();
|
||||||
}
|
}
|
||||||
}
|
} catch(e) {
|
||||||
catch(error) {
|
|
||||||
// NOP
|
// NOP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ function clozeBuild(sentence, source) {
|
|||||||
* Audio
|
* Audio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function audioBuildUrl(definition, mode, cache={}) {
|
async function audioBuildUrl(definition, mode, cache={}) {
|
||||||
if (mode === 'jpod101') {
|
if (mode === 'jpod101') {
|
||||||
let kana = definition.reading;
|
let kana = definition.reading;
|
||||||
let kanji = definition.expression;
|
let kanji = definition.expression;
|
||||||
@ -103,7 +103,7 @@ function audioBuildUrl(definition, mode, cache={}) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject('unsupported audio source');
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,16 +121,7 @@ function audioBuildFilename(definition) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function audioInject(definition, fields, mode) {
|
async function audioInject(definition, fields, mode) {
|
||||||
if (mode === 'disabled') {
|
|
||||||
return Promise.resolve(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
const filename = audioBuildFilename(definition);
|
|
||||||
if (!filename) {
|
|
||||||
return Promise.resolve(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
let usesAudio = false;
|
let usesAudio = false;
|
||||||
for (const name in fields) {
|
for (const name in fields) {
|
||||||
if (fields[name].includes('{audio}')) {
|
if (fields[name].includes('{audio}')) {
|
||||||
@ -140,11 +131,19 @@ function audioInject(definition, fields, mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!usesAudio) {
|
if (!usesAudio) {
|
||||||
return Promise.resolve(true);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return audioBuildUrl(definition, mode).then(url => {
|
try {
|
||||||
|
const url = await audioBuildUrl(definition, mode);
|
||||||
|
const filename = audioBuildFilename(definition);
|
||||||
|
|
||||||
|
if (url && filename) {
|
||||||
definition.audio = {url, filename};
|
definition.audio = {url, filename};
|
||||||
return true;
|
}
|
||||||
}).catch(() => false);
|
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user