Optimized import method

This commit is contained in:
nobody 2021-02-17 07:02:14 +01:00
parent db398fadec
commit 3b62f261f9
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
1 changed files with 16 additions and 9 deletions

View File

@ -107,16 +107,23 @@ storageManager.startImportFilePicker = function () {
input.click();
};
storageManager.handleImportFilePicker = async function () {
try {
let file = document.getElementById('import-file-picker').files[0];
let content = await storageManager._readFileAsync(file);
storageManager._validation(JSON.parse(content));
} catch (err) {
console.error('[ LocalCDN ] ' + err);
}
storageManager.handleImportFilePicker = function () {
return new Promise((resolve) => {
try {
let file = document.getElementById('import-file-picker').files[0];
storageManager._readFile(file)
.then(JSON.parse)
.then(storageManager._validation);
resolve();
} catch (err) {
console.error(`[ LocalCDN ] ${err}`);
alert(err);
}
});
};
/**
* Private Methods
*/
@ -131,7 +138,7 @@ storageManager._handleStorageChanged = function (type) {
}
};
storageManager._readFileAsync = function (file) {
storageManager._readFile = function (file) {
return new Promise((resolve, reject) => {
let reader = new FileReader();
reader.onload = () => {