mirror of
https://github.com/gchq/CyberChef
synced 2025-01-08 10:38:46 +00:00
Display when an input errors on load.
Autobake when all inputs have loaded. Improve load experience.
This commit is contained in:
parent
3c2e5c143a
commit
6d9a14feed
3 changed files with 39 additions and 14 deletions
|
@ -361,7 +361,13 @@ class InputWaiter {
|
||||||
fileName.textContent = inputData.name;
|
fileName.textContent = inputData.name;
|
||||||
fileSize.textContent = inputData.size + " bytes";
|
fileSize.textContent = inputData.size + " bytes";
|
||||||
fileType.textContent = inputData.type;
|
fileType.textContent = inputData.type;
|
||||||
fileLoaded.textContent = inputData.progress + "%";
|
if (inputData.status === "error") {
|
||||||
|
fileLoaded.textContent = "Error";
|
||||||
|
fileLoaded.style.color = "#FF0000";
|
||||||
|
} else {
|
||||||
|
fileLoaded.style.color = "";
|
||||||
|
fileLoaded.textContent = inputData.progress + "%";
|
||||||
|
}
|
||||||
|
|
||||||
this.displayFilePreview(inputData);
|
this.displayFilePreview(inputData);
|
||||||
}
|
}
|
||||||
|
@ -420,7 +426,13 @@ class InputWaiter {
|
||||||
if (inputNum !== activeTab) return;
|
if (inputNum !== activeTab) return;
|
||||||
|
|
||||||
const fileLoaded = document.getElementById("input-file-loaded");
|
const fileLoaded = document.getElementById("input-file-loaded");
|
||||||
fileLoaded.textContent = progress + "%";
|
if (progress === "error") {
|
||||||
|
fileLoaded.textContent = "Error";
|
||||||
|
fileLoaded.style.color = "#FF0000";
|
||||||
|
} else {
|
||||||
|
fileLoaded.textContent = progress + "%";
|
||||||
|
fileLoaded.style.color = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (progress === 100) {
|
if (progress === 100) {
|
||||||
this.inputWorker.postMessage({
|
this.inputWorker.postMessage({
|
||||||
|
@ -789,6 +801,10 @@ class InputWaiter {
|
||||||
});
|
});
|
||||||
}.bind(this), 100);
|
}.bind(this), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (loaded === total) {
|
||||||
|
this.app.autoBake();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// displayTabInfo
|
// displayTabInfo
|
||||||
// simple getInput for each tab
|
// simple getInput for each tab
|
||||||
|
@ -1096,6 +1112,7 @@ class InputWaiter {
|
||||||
if (!this.getTabItem(inputNum) && numTabs < this.maxTabs) {
|
if (!this.getTabItem(inputNum) && numTabs < this.maxTabs) {
|
||||||
const newTab = this.createTabElement(inputNum, false);
|
const newTab = this.createTabElement(inputNum, false);
|
||||||
|
|
||||||
|
|
||||||
tabsWrapper.appendChild(newTab);
|
tabsWrapper.appendChild(newTab);
|
||||||
|
|
||||||
if (numTabs > 0) {
|
if (numTabs > 0) {
|
||||||
|
@ -1111,6 +1128,11 @@ class InputWaiter {
|
||||||
document.getElementById("input-highlighter").style.height = "calc(100% - var(--title-height))";
|
document.getElementById("input-highlighter").style.height = "calc(100% - var(--title-height))";
|
||||||
document.getElementById("input-file").style.height = "calc(100% - var(--title-height))";
|
document.getElementById("input-file").style.height = "calc(100% - var(--title-height))";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.inputWorker.postMessage({
|
||||||
|
action: "updateTabHeader",
|
||||||
|
data: inputNum
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changeTab) {
|
if (changeTab) {
|
||||||
|
|
|
@ -94,6 +94,9 @@ self.addEventListener("message", function(e) {
|
||||||
case "inputSwitch":
|
case "inputSwitch":
|
||||||
self.inputSwitch(r.data);
|
self.inputSwitch(r.data);
|
||||||
break;
|
break;
|
||||||
|
case "updateTabHeader":
|
||||||
|
self.updateTabHeader(r.data);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
log.error(`Unknown action '${r.action}'.`);
|
log.error(`Unknown action '${r.action}'.`);
|
||||||
}
|
}
|
||||||
|
@ -184,6 +187,9 @@ self.getInputValue = function(inputNum) {
|
||||||
self.getInputProgress = function(inputNum) {
|
self.getInputProgress = function(inputNum) {
|
||||||
const inputObj = self.getInputObj(inputNum);
|
const inputObj = self.getInputObj(inputNum);
|
||||||
if (inputObj === undefined || inputObj === null) return;
|
if (inputObj === undefined || inputObj === null) return;
|
||||||
|
if (inputObj.status === "error") {
|
||||||
|
return "error";
|
||||||
|
}
|
||||||
return inputObj.progress;
|
return inputObj.progress;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -326,6 +332,7 @@ self.setInput = function(inputData) {
|
||||||
inputObj.size = inputVal.size;
|
inputObj.size = inputVal.size;
|
||||||
inputObj.type = inputVal.type;
|
inputObj.type = inputVal.type;
|
||||||
inputObj.progress = input.progress;
|
inputObj.progress = input.progress;
|
||||||
|
inputObj.status = input.status;
|
||||||
inputVal = inputVal.fileBuffer;
|
inputVal = inputVal.fileBuffer;
|
||||||
const fileSlice = inputVal.slice(0, 512001);
|
const fileSlice = inputVal.slice(0, 512001);
|
||||||
inputObj.input = fileSlice;
|
inputObj.input = fileSlice;
|
||||||
|
@ -346,7 +353,7 @@ self.setInput = function(inputData) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
self.getInputProgress(inputNum);
|
self.updateTabHeader(inputNum);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.refreshTabs = function(inputNum, direction) {
|
self.refreshTabs = function(inputNum, direction) {
|
||||||
|
@ -362,16 +369,11 @@ self.refreshTabs = function(inputNum, direction) {
|
||||||
for (let i = 0; i < nums.length; i++) {
|
for (let i = 0; i < nums.length; i++) {
|
||||||
self.updateTabHeader(nums[i]);
|
self.updateTabHeader(nums[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// self.setInput(inputNum);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.updateInputStatus = function(inputNum, status) {
|
self.updateInputStatus = function(inputNum, status) {
|
||||||
for (let i = 0; i < self.inputs.length; i++) {
|
if (self.inputs[inputNum] !== undefined) {
|
||||||
if (self.inputs[i].inputNum === inputNum) {
|
self.inputs[inputNum].status = status;
|
||||||
self.inputs[i].status = status;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -448,8 +450,8 @@ self.handleLoaderMessage = function(r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.hasOwnProperty("error")) {
|
if (r.hasOwnProperty("error")) {
|
||||||
self.updateInputStatus(r.inputNum, "error");
|
|
||||||
self.updateInputProgress(r.inputNum, 0);
|
self.updateInputProgress(r.inputNum, 0);
|
||||||
|
self.updateInputStatus(r.inputNum, "error");
|
||||||
|
|
||||||
log.error(r.error);
|
log.error(r.error);
|
||||||
self.loadingInputs--;
|
self.loadingInputs--;
|
||||||
|
@ -457,6 +459,7 @@ self.handleLoaderMessage = function(r) {
|
||||||
self.terminateLoaderWorker(r.id);
|
self.terminateLoaderWorker(r.id);
|
||||||
self.activateLoaderWorker();
|
self.activateLoaderWorker();
|
||||||
|
|
||||||
|
self.setInput({inputNum: inputNum, silent: true});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,7 +471,7 @@ self.handleLoaderMessage = function(r) {
|
||||||
value: r.fileBuffer
|
value: r.fileBuffer
|
||||||
});
|
});
|
||||||
|
|
||||||
self.setInput({inputNum: inputNum, silent: false});
|
// self.setInput({inputNum: inputNum, silent: false});
|
||||||
|
|
||||||
const idx = self.getLoaderWorkerIdx(r.id);
|
const idx = self.getLoaderWorkerIdx(r.id);
|
||||||
self.loadNextFile(idx);
|
self.loadNextFile(idx);
|
||||||
|
@ -564,6 +567,7 @@ self.loadFiles = function(filesData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.getLoadProgress();
|
self.getLoadProgress();
|
||||||
|
self.setInput({inputNum: activeTab, silent: false});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -612,7 +616,6 @@ self.addInput = function(changeTab=false, type, fileData={name: "unknown", size:
|
||||||
changeTab: changeTab,
|
changeTab: changeTab,
|
||||||
inputNum: inputNum
|
inputNum: inputNum
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return inputNum;
|
return inputNum;
|
||||||
|
|
|
@ -70,7 +70,7 @@ self.loadFile = function(file, inputNum) {
|
||||||
};
|
};
|
||||||
|
|
||||||
reader.onerror = function(e) {
|
reader.onerror = function(e) {
|
||||||
self.postMessage({"error": reader.error.message, "inputNum": inputNum});
|
self.postMessage({"error": reader.error.message, "inputNum": inputNum, "id": self.id});
|
||||||
};
|
};
|
||||||
|
|
||||||
seek();
|
seek();
|
||||||
|
|
Loading…
Reference in a new issue