hack: check cached file (#8317)

This commit is contained in:
Santy-Wang
2021-03-02 19:16:48 +08:00
committed by GitHub
parent 2a5778b55d
commit 2f3975f39b
@@ -1,5 +1,5 @@
const cacheManager = require('../cache-manager');
const { fs, downloadFile, readText, readArrayBuffer, readJson, loadSubpackage, getUserDataPath } = window.fsUtils;
const { fs, downloadFile, readText, readArrayBuffer, readJson, loadSubpackage, getUserDataPath, exists } = window.fsUtils;
const REGEX = /^https?:\/\/.*/;
@@ -135,7 +135,15 @@ function loadFont (url, options, onComplete) {
onComplete(null, fontFamily || 'Arial');
}
function doNothing (content, options, onComplete) { onComplete(null, content); }
function doNothing (content, options, onComplete) {
exists(content, (existence) => {
if (existence) {
onComplete(null, content);
} else {
onComplete(new Error(`file ${content} does not exist!`));
}
});
}
function downloadAsset (url, options, onComplete) {
download(url, doNothing, options, options.onFileProgress, onComplete);