mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Add mime type detection to tab title.
Move addition of close tab button back
This commit is contained in:
parent
6ee76e3bf0
commit
84204c1d12
2 changed files with 42 additions and 16 deletions
|
@ -8,6 +8,7 @@
|
||||||
import Utils from "./Utils";
|
import Utils from "./Utils";
|
||||||
import DishError from "./errors/DishError";
|
import DishError from "./errors/DishError";
|
||||||
import BigNumber from "bignumber.js";
|
import BigNumber from "bignumber.js";
|
||||||
|
import {detectFileType} from "./lib/FileType";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,6 +142,23 @@ class Dish {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects the MIME type of the current dish
|
||||||
|
*
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
async detectDishType() {
|
||||||
|
const data = new Uint8Array(this.value),
|
||||||
|
types = detectFileType(data);
|
||||||
|
|
||||||
|
if (!types.length || !types[0].mime || !types[0].mime === "text/plain") {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return types[0].mime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the title of the data up to the specified length
|
* Returns the title of the data up to the specified length
|
||||||
*
|
*
|
||||||
|
@ -158,6 +176,13 @@ class Dish {
|
||||||
case Dish.LIST_FILE:
|
case Dish.LIST_FILE:
|
||||||
title = `${this.value.length} file(s)`;
|
title = `${this.value.length} file(s)`;
|
||||||
break;
|
break;
|
||||||
|
case Dish.ARRAY_BUFFER:
|
||||||
|
case Dish.BYTE_ARRAY:
|
||||||
|
title = await this.detectDishType();
|
||||||
|
if (title === null) {
|
||||||
|
title = await this.get("string");
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
title = await this.get("string");
|
title = await this.get("string");
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,22 @@ class TabWaiter {
|
||||||
|
|
||||||
newTab.appendChild(newTabContent);
|
newTab.appendChild(newTabContent);
|
||||||
|
|
||||||
|
if (io === "input") {
|
||||||
|
const newTabButton = document.createElement("button"),
|
||||||
|
newTabButtonIcon = document.createElement("i");
|
||||||
|
newTabButton.type = "button";
|
||||||
|
newTabButton.className = "btn btn-primary bmd-btn-icon btn-close-tab";
|
||||||
|
|
||||||
|
newTabButtonIcon.classList.add("material-icons");
|
||||||
|
newTabButtonIcon.innerText = "clear";
|
||||||
|
|
||||||
|
newTabButton.appendChild(newTabButtonIcon);
|
||||||
|
|
||||||
|
newTabButton.addEventListener("click", this.manager.input.removeTabClick.bind(this.manager.input));
|
||||||
|
|
||||||
|
newTab.appendChild(newTabButton);
|
||||||
|
}
|
||||||
|
|
||||||
return newTab;
|
return newTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,22 +186,7 @@ class TabWaiter {
|
||||||
* @returns {Element}
|
* @returns {Element}
|
||||||
*/
|
*/
|
||||||
createInputTabElement(inputNum, active=false) {
|
createInputTabElement(inputNum, active=false) {
|
||||||
const newTab = this.createTabElement(inputNum, active, "input"),
|
return this.createTabElement(inputNum, active, "input");
|
||||||
newTabButton = document.createElement("button"),
|
|
||||||
newTabButtonIcon = document.createElement("i");
|
|
||||||
newTabButton.type = "button";
|
|
||||||
newTabButton.className = "btn btn-primary bmd-btn-icon btn-close-tab";
|
|
||||||
|
|
||||||
newTabButtonIcon.classList.add("material-icons");
|
|
||||||
newTabButtonIcon.innerText = "clear";
|
|
||||||
|
|
||||||
newTabButton.appendChild(newTabButtonIcon);
|
|
||||||
|
|
||||||
newTabButton.addEventListener("click", this.manager.input.removeTabClick.bind(this.manager.input));
|
|
||||||
|
|
||||||
newTab.appendChild(newTabButton);
|
|
||||||
|
|
||||||
return newTab;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue