mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-26 09:46:17 -04:00
Reviewed Input and Output Waiters and improved logging in workers
This commit is contained in:
parent
56d1a016da
commit
91f1be8c70
12 changed files with 204 additions and 111 deletions
|
@ -7,11 +7,17 @@
|
|||
*/
|
||||
|
||||
import Dish from "../../core/Dish.mjs";
|
||||
import loglevelMessagePrefix from "loglevel-message-prefix";
|
||||
|
||||
loglevelMessagePrefix(log, {
|
||||
prefixes: [],
|
||||
staticPrefixes: ["DishWorker"]
|
||||
});
|
||||
|
||||
self.addEventListener("message", function(e) {
|
||||
// Handle message from the main thread
|
||||
const r = e.data;
|
||||
log.debug(`DishWorker receiving command '${r.action}'`);
|
||||
log.debug(`Receiving command '${r.action}'`);
|
||||
|
||||
switch (r.action) {
|
||||
case "getDishAs":
|
||||
|
@ -20,8 +26,11 @@ self.addEventListener("message", function(e) {
|
|||
case "getDishTitle":
|
||||
getDishTitle(r.data);
|
||||
break;
|
||||
case "setLogLevel":
|
||||
log.setLevel(r.data, false);
|
||||
break;
|
||||
default:
|
||||
log.error(`DishWorker sent invalid action: '${r.action}'`);
|
||||
log.error(`Unknown action: '${r.action}'`);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
*/
|
||||
|
||||
import Utils from "../../core/Utils.mjs";
|
||||
import loglevelMessagePrefix from "loglevel-message-prefix";
|
||||
|
||||
loglevelMessagePrefix(log, {
|
||||
prefixes: [],
|
||||
staticPrefixes: ["InputWorker"]
|
||||
});
|
||||
|
||||
// Default max values
|
||||
// These will be correctly calculated automatically
|
||||
|
@ -52,7 +58,7 @@ self.addEventListener("message", function(e) {
|
|||
return;
|
||||
}
|
||||
|
||||
log.debug(`Receiving ${r.action} from InputWaiter.`);
|
||||
log.debug(`Receiving command '${r.action}'`);
|
||||
|
||||
switch (r.action) {
|
||||
case "loadUIFiles":
|
||||
|
|
|
@ -6,32 +6,36 @@
|
|||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import loglevelMessagePrefix from "loglevel-message-prefix";
|
||||
|
||||
loglevelMessagePrefix(log, {
|
||||
prefixes: [],
|
||||
staticPrefixes: ["LoaderWorker"]
|
||||
});
|
||||
|
||||
self.id = null;
|
||||
|
||||
|
||||
self.handleMessage = function(e) {
|
||||
const r = e.data;
|
||||
log.debug(`LoaderWorker receiving command '${r.action}'`);
|
||||
|
||||
switch (r.action) {
|
||||
case "loadInput":
|
||||
self.loadFile(r.data.file, r.data.inputNum);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Respond to message from parent thread.
|
||||
*/
|
||||
self.addEventListener("message", function(e) {
|
||||
// Handle message
|
||||
const r = e.data;
|
||||
if (Object.prototype.hasOwnProperty.call(r, "file") && Object.prototype.hasOwnProperty.call(r, "inputNum")) {
|
||||
self.loadFile(r.file, r.inputNum);
|
||||
} else if (Object.prototype.hasOwnProperty.call(r, "file")) {
|
||||
self.loadFile(r.file, "");
|
||||
} else if (Object.prototype.hasOwnProperty.call(r, "id")) {
|
||||
self.id = r.id;
|
||||
log.debug(`Receiving command '${r.action}'`);
|
||||
|
||||
switch (r.action) {
|
||||
case "setID":
|
||||
self.id = r.data.id;
|
||||
break;
|
||||
case "loadFile":
|
||||
self.loadFile(r.data.file, r.data?.inputNum ?? "");
|
||||
break;
|
||||
case "setLogLevel":
|
||||
log.setLevel(r.data, false);
|
||||
break;
|
||||
default:
|
||||
log.error(`Unknown action '${r.action}'.`);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -10,6 +10,12 @@ import zip from "zlibjs/bin/zip.min.js";
|
|||
import Utils from "../../core/Utils.mjs";
|
||||
import Dish from "../../core/Dish.mjs";
|
||||
import {detectFileType} from "../../core/lib/FileType.mjs";
|
||||
import loglevelMessagePrefix from "loglevel-message-prefix";
|
||||
|
||||
loglevelMessagePrefix(log, {
|
||||
prefixes: [],
|
||||
staticPrefixes: ["ZipWorker"],
|
||||
});
|
||||
|
||||
const Zlib = zip.Zlib;
|
||||
|
||||
|
@ -17,17 +23,20 @@ const Zlib = zip.Zlib;
|
|||
* Respond to message from parent thread.
|
||||
*/
|
||||
self.addEventListener("message", function(e) {
|
||||
// Handle message from the main thread
|
||||
const r = e.data;
|
||||
if (!("outputs" in r)) {
|
||||
log.error("No files were passed to the ZipWorker.");
|
||||
return;
|
||||
}
|
||||
if (!("filename" in r)) {
|
||||
log.error("No filename was passed to the ZipWorker");
|
||||
return;
|
||||
}
|
||||
log.debug(`Receiving command '${r.action}'`);
|
||||
|
||||
self.zipFiles(r.outputs, r.filename, r.fileExtension);
|
||||
switch (r.action) {
|
||||
case "zipFiles":
|
||||
self.zipFiles(r.data.outputs, r.data.filename, r.data.fileExtension);
|
||||
break;
|
||||
case "setLogLevel":
|
||||
log.setLevel(r.data, false);
|
||||
break;
|
||||
default:
|
||||
log.error(`Unknown action: '${r.action}'`);
|
||||
}
|
||||
});
|
||||
|
||||
self.setOption = function(...args) {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue