mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Added module framework
This commit is contained in:
parent
9f19afc943
commit
a61cf6a68a
22 changed files with 762 additions and 274 deletions
|
@ -8,9 +8,13 @@
|
|||
|
||||
import "babel-polyfill";
|
||||
import Chef from "./Chef.js";
|
||||
import OperationConfig from "value-loader?name=conf!./config/OperationConfig.js";
|
||||
import OpModules from "./config/modules/Default.js";
|
||||
|
||||
|
||||
// Set up Chef instance
|
||||
self.chef = new Chef();
|
||||
self.OpModules = OpModules;
|
||||
|
||||
// Tell the app that the worker has loaded and is ready to operate
|
||||
self.postMessage({
|
||||
|
@ -50,8 +54,13 @@ self.addEventListener("message", function(e) {
|
|||
|
||||
/**
|
||||
* Baking handler
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
async function bake(data) {
|
||||
// Ensure the relevant modules are loaded
|
||||
loadRequiredModules(data.recipeConfig);
|
||||
|
||||
try {
|
||||
const response = await self.chef.bake(
|
||||
data.input, // The user's input
|
||||
|
@ -68,7 +77,7 @@ async function bake(data) {
|
|||
} catch (err) {
|
||||
self.postMessage({
|
||||
action: "bakeError",
|
||||
data: err
|
||||
data: err.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -85,3 +94,20 @@ function silentBake(data) {
|
|||
data: duration
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks that all required modules are loaded and loads them if not.
|
||||
*
|
||||
* @param {Object} recipeConfig
|
||||
*/
|
||||
function loadRequiredModules(recipeConfig) {
|
||||
recipeConfig.forEach(op => {
|
||||
let module = OperationConfig[op.op].module;
|
||||
|
||||
if (!OpModules.hasOwnProperty(module)) {
|
||||
console.log("Loading module " + module);
|
||||
self.importScripts(module + ".js");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue