mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-02 22:21:01 +01:00
Bring back moving the output into the input.
Change wording for download as zip button
This commit is contained in:
parent
cbfde7ddb1
commit
6268f091b8
@ -276,27 +276,14 @@ class InputWaiter {
|
||||
case "setUrl":
|
||||
this.setUrl(r.data);
|
||||
break;
|
||||
case "inputSwitch":
|
||||
this.manager.output.inputSwitch(r.data);
|
||||
break;
|
||||
default:
|
||||
log.error(`Unknown action ${r.action}.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the input for the active tab
|
||||
*/
|
||||
getActive() {
|
||||
const textArea = document.getElementById("input-text");
|
||||
const value = (textArea.value !== undefined) ? textArea.value : "";
|
||||
const inputNum = this.getActiveTab();
|
||||
|
||||
if (this.fileBuffer) {
|
||||
return this.fileBuffer;
|
||||
} else {
|
||||
this.updateInputValue(inputNum, value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the input for all tabs
|
||||
*/
|
||||
@ -452,13 +439,6 @@ class InputWaiter {
|
||||
* @param {string | ArrayBuffer} value
|
||||
*/
|
||||
updateInputValue(inputNum, value) {
|
||||
this.inputWorker.postMessage({
|
||||
action: "updateInputValue",
|
||||
data: {
|
||||
inputNum: inputNum,
|
||||
value: value
|
||||
}
|
||||
});
|
||||
let includeInput = false;
|
||||
const recipeStr = toBase64(value, "A-Za-z0-9+/"); // B64 alphabet with no padding
|
||||
if (recipeStr.length > 0 && recipeStr.length <= 68267) {
|
||||
@ -468,6 +448,50 @@ class InputWaiter {
|
||||
includeInput: includeInput,
|
||||
input: recipeStr
|
||||
});
|
||||
|
||||
if (typeof value === "string") {
|
||||
this.inputWorker.postMessage({
|
||||
action: "updateInputValue",
|
||||
data: {
|
||||
inputNum: inputNum,
|
||||
value: value
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.inputWorker.postMessage({
|
||||
action: "updateInputValue",
|
||||
data: {
|
||||
inputNum: inputNum,
|
||||
value: value
|
||||
}
|
||||
}, [value]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the .data property for the input of the specified inputNum
|
||||
*
|
||||
* @param {number} inputNum
|
||||
* @param {object} inputData
|
||||
*/
|
||||
updateInputObj(inputNum, inputData) {
|
||||
if (typeof inputData === "string") {
|
||||
this.inputWorker.postMessage({
|
||||
action: "updateInputObj",
|
||||
data: {
|
||||
inputNum: inputNum,
|
||||
data: inputData
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.inputWorker.postMessage({
|
||||
action: "updateInputObj",
|
||||
data: {
|
||||
inputNum: inputNum,
|
||||
data: inputData
|
||||
}
|
||||
}, [inputData.fileBuffer]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,6 +47,9 @@ self.addEventListener("message", function(e) {
|
||||
case "updateInputValue":
|
||||
self.updateInputValue(r.data);
|
||||
break;
|
||||
case "updateInputObj":
|
||||
self.updateInputObj(r.data);
|
||||
break;
|
||||
case "getInputProgress":
|
||||
self.getLoadProgress(r.data);
|
||||
break;
|
||||
@ -89,6 +92,9 @@ self.addEventListener("message", function(e) {
|
||||
case "loaderWorkerMessage":
|
||||
self.handleLoaderMessage(r.data);
|
||||
break;
|
||||
case "inputSwitch":
|
||||
self.inputSwitch(r.data);
|
||||
break;
|
||||
default:
|
||||
log.error(`Unknown action '${r.action}'.`);
|
||||
}
|
||||
@ -407,6 +413,15 @@ self.updateInputValue = function(inputData) {
|
||||
}
|
||||
};
|
||||
|
||||
self.updateInputObj = function(inputData) {
|
||||
const inputNum = inputData.inputNum;
|
||||
const data = inputData.data;
|
||||
|
||||
if (self.getInputObj(inputNum) === -1) return;
|
||||
|
||||
self.inputs[inputNum].data = data;
|
||||
};
|
||||
|
||||
self.getLoaderWorkerIdx = function(workerId) {
|
||||
for (let i = 0; i < self.loaderWorkers.length; i++) {
|
||||
if (self.loaderWorkers[i].id === workerId) {
|
||||
@ -712,3 +727,40 @@ self.filterTabs = function(searchData) {
|
||||
data: inputs
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Swaps the input and outputs, and sends the old input back to the main thread.
|
||||
*
|
||||
* @param {object} switchData
|
||||
* @param {number} switchData.inputNum
|
||||
* @param {string | ArrayBuffer} switchData.outputData
|
||||
*/
|
||||
self.inputSwitch = function(switchData) {
|
||||
const currentInput = self.getInputObj(switchData.inputNum);
|
||||
const currentData = currentInput.data;
|
||||
if (currentInput === undefined || currentInput === null) return;
|
||||
|
||||
if (typeof switchData.outputData === "object") {
|
||||
// ArrayBuffer
|
||||
currentInput.data = {
|
||||
fileBuffer: switchData.outputData,
|
||||
name: "output.dat",
|
||||
size: switchData.outputData.byteLength.toLocaleString(),
|
||||
type: "unknown" // Could run detect file type here
|
||||
};
|
||||
} else {
|
||||
// String
|
||||
currentInput.data = switchData.outputData;
|
||||
}
|
||||
|
||||
self.postMessage({
|
||||
action: "inputSwitch",
|
||||
data: {
|
||||
data: currentData,
|
||||
inputNum: switchData.inputNum
|
||||
}
|
||||
});
|
||||
|
||||
self.setInput({inputNum: switchData.inputNum, silent: false});
|
||||
|
||||
};
|
||||
|
@ -183,8 +183,8 @@ class Manager {
|
||||
document.getElementById("save-to-file").addEventListener("click", this.output.saveClick.bind(this.output));
|
||||
document.getElementById("save-all-to-file").addEventListener("click", this.output.saveAllClick.bind(this.output));
|
||||
document.getElementById("copy-output").addEventListener("click", this.output.copyClick.bind(this.output));
|
||||
// document.getElementById("switch").addEventListener("click", this.output.switchClick.bind(this.output));
|
||||
// document.getElementById("undo-switch").addEventListener("click", this.output.undoSwitchClick.bind(this.output));
|
||||
document.getElementById("switch").addEventListener("click", this.output.switchClick.bind(this.output));
|
||||
document.getElementById("undo-switch").addEventListener("click", this.output.undoSwitchClick.bind(this.output));
|
||||
// document.getElementById("maximise-output").addEventListener("click", this.output.maximiseOutputClick.bind(this.output));
|
||||
document.getElementById("magic").addEventListener("click", this.output.magicClick.bind(this.output));
|
||||
document.getElementById("output-text").addEventListener("scroll", this.highlighter.outputScroll.bind(this.highlighter));
|
||||
|
@ -463,11 +463,9 @@ class OutputWaiter {
|
||||
* be zipped for download
|
||||
*/
|
||||
downloadAllFiles() {
|
||||
|
||||
const inputNums = Object.keys(this.outputs);
|
||||
for (let i = 0; i < inputNums.length; i++) {
|
||||
const iNum = inputNums[i];
|
||||
log.error(this.outputs[iNum]);
|
||||
if (this.outputs[iNum].status !== "baked" ||
|
||||
this.outputs[iNum].bakeId !== this.manager.worker.bakeId) {
|
||||
if (window.confirm("Not all outputs have been baked yet. Continue downloading outputs?")) {
|
||||
@ -1125,6 +1123,67 @@ class OutputWaiter {
|
||||
containsCR() {
|
||||
return this.getActive(true).indexOf("\r") >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for switch click events.
|
||||
* Moves the current output into the input textarea.
|
||||
*/
|
||||
switchClick() {
|
||||
const active = this.getActive(true);
|
||||
if (typeof active === "string") {
|
||||
this.manager.input.inputWorker.postMessage({
|
||||
action: "inputSwitch",
|
||||
data: {
|
||||
inputNum: this.manager.input.getActiveTab(),
|
||||
outputData: active
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.manager.input.inputWorker.postMessage({
|
||||
action: "inputSwitch",
|
||||
data: {
|
||||
inputNum: this.manager.input.getActiveTab(),
|
||||
outputData: active
|
||||
}
|
||||
}, [active]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for when the inputWorker has switched the inputs.
|
||||
* Stores the old input
|
||||
*
|
||||
* @param {object} switchData
|
||||
* @param {number} switchData.inputNum
|
||||
* @param {string | object} switchData.data
|
||||
* @param {ArrayBuffer} switchData.data.fileBuffer
|
||||
* @param {number} switchData.data.size
|
||||
* @param {string} switchData.data.type
|
||||
* @param {string} switchData.data.name
|
||||
*/
|
||||
inputSwitch(switchData) {
|
||||
this.switchOrigData = switchData;
|
||||
document.getElementById("undo-switch").disabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for undo switch click events.
|
||||
* Removes the output from the input and replaces the input that was removed.
|
||||
*/
|
||||
undoSwitchClick() {
|
||||
this.manager.input.updateInputObj(this.switchOrigData.inputNum, this.switchOrigData.data);
|
||||
const undoSwitch = document.getElementById("undo-switch");
|
||||
undoSwitch.disabled = true;
|
||||
$(undoSwitch).tooltip("hide");
|
||||
|
||||
this.manager.input.inputWorker.postMessage({
|
||||
action: "setInput",
|
||||
data: {
|
||||
inputNum: this.switchOrigData.inputNum,
|
||||
silent: false
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default OutputWaiter;
|
||||
|
@ -295,7 +295,7 @@
|
||||
<div class="title no-select">
|
||||
<label for="output-text">Output</label>
|
||||
<span class="float-right">
|
||||
<button type="button" class="btn btn-primary bmd-btn-icon" id="save-all-to-file" data-toggle="tooltip" title="Save all outputs to a file" style="display: none">
|
||||
<button type="button" class="btn btn-primary bmd-btn-icon" id="save-all-to-file" data-toggle="tooltip" title="Save all outputs to a zip file" style="display: none">
|
||||
<i class="material-icons">archive</i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary bmd-btn-icon" id="save-to-file" data-toggle="tooltip" title="Save output to file">
|
||||
|
Loading…
Reference in New Issue
Block a user