mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 08:58:30 +01:00
Add documentation for inputNum.
Fix syntax for transferable objects.
This commit is contained in:
parent
784b3b58ca
commit
dc74a389d8
1 changed files with 26 additions and 40 deletions
|
@ -37,6 +37,10 @@ self.postMessage({
|
||||||
/**
|
/**
|
||||||
* Respond to message from parent thread.
|
* Respond to message from parent thread.
|
||||||
*
|
*
|
||||||
|
* An inputNum only needs to be sent when baking.
|
||||||
|
* (The background ChefWorker doesn't send one, but as
|
||||||
|
* it only deals with one input at a time it isn't needed)
|
||||||
|
*
|
||||||
* Messages should have the following format:
|
* Messages should have the following format:
|
||||||
* {
|
* {
|
||||||
* action: "bake" | "silentBake",
|
* action: "bake" | "silentBake",
|
||||||
|
@ -45,7 +49,8 @@ self.postMessage({
|
||||||
* recipeConfig: {[Object]},
|
* recipeConfig: {[Object]},
|
||||||
* options: {Object},
|
* options: {Object},
|
||||||
* progress: {number},
|
* progress: {number},
|
||||||
* step: {boolean}
|
* step: {boolean},
|
||||||
|
* inputNum: {number} | undefined
|
||||||
* } | undefined
|
* } | undefined
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
@ -94,7 +99,7 @@ async function bake(data) {
|
||||||
// Ensure the relevant modules are loaded
|
// Ensure the relevant modules are loaded
|
||||||
self.loadRequiredModules(data.recipeConfig);
|
self.loadRequiredModules(data.recipeConfig);
|
||||||
try {
|
try {
|
||||||
self.inputNum = parseInt(data.inputNum, 10);
|
self.inputNum = data.inputNum;
|
||||||
const response = await self.chef.bake(
|
const response = await self.chef.bake(
|
||||||
data.input, // The user's input
|
data.input, // The user's input
|
||||||
data.recipeConfig, // The configuration of the recipe
|
data.recipeConfig, // The configuration of the recipe
|
||||||
|
@ -103,25 +108,16 @@ async function bake(data) {
|
||||||
data.step // Whether or not to take one step or execute the whole recipe
|
data.step // Whether or not to take one step or execute the whole recipe
|
||||||
);
|
);
|
||||||
|
|
||||||
if (data.input instanceof ArrayBuffer) {
|
const transferable = (data.input instanceof ArrayBuffer) ? [data.input] : undefined;
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
action: "bakeComplete",
|
action: "bakeComplete",
|
||||||
data: Object.assign(response, {
|
data: Object.assign(response, {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
inputNum: data.inputNum,
|
inputNum: data.inputNum,
|
||||||
bakeId: data.bakeId
|
bakeId: data.bakeId
|
||||||
})
|
})
|
||||||
}, [data.input]);
|
}, transferable);
|
||||||
} else {
|
|
||||||
self.postMessage({
|
|
||||||
action: "bakeComplete",
|
|
||||||
data: Object.assign(response, {
|
|
||||||
id: data.id,
|
|
||||||
inputNum: data.inputNum,
|
|
||||||
bakeId: data.bakeId
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
action: "bakeError",
|
action: "bakeError",
|
||||||
|
@ -154,24 +150,14 @@ function silentBake(data) {
|
||||||
*/
|
*/
|
||||||
async function getDishAs(data) {
|
async function getDishAs(data) {
|
||||||
const value = await self.chef.getDishAs(data.dish, data.type);
|
const value = await self.chef.getDishAs(data.dish, data.type);
|
||||||
|
const transferable = (data.type === "ArrayBuffer") ? [value] : undefined;
|
||||||
if (data.type === "ArrayBuffer") {
|
self.postMessage({
|
||||||
self.postMessage({
|
action: "dishReturned",
|
||||||
action: "dishReturned",
|
data: {
|
||||||
data: {
|
value: value,
|
||||||
value: value,
|
id: data.id
|
||||||
id: data.id
|
}
|
||||||
}
|
}, transferable);
|
||||||
}, [value]);
|
|
||||||
} else {
|
|
||||||
self.postMessage({
|
|
||||||
action: "dishReturned",
|
|
||||||
data: {
|
|
||||||
value: value,
|
|
||||||
id: data.id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,7 +209,7 @@ self.sendStatusMessage = function(msg) {
|
||||||
action: "statusMessage",
|
action: "statusMessage",
|
||||||
data: {
|
data: {
|
||||||
message: msg,
|
message: msg,
|
||||||
inputNum: self.inputNum || -1
|
inputNum: self.inputNum
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue