diff --git a/src/core/Dish.mjs b/src/core/Dish.mjs index 7d1ec7b5..a79d20cf 100755 --- a/src/core/Dish.mjs +++ b/src/core/Dish.mjs @@ -8,6 +8,7 @@ import Utils from "./Utils"; import DishError from "./errors/DishError"; import BigNumber from "bignumber.js"; +import {detectFileType} from "./lib/FileType"; 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 * @@ -158,6 +176,13 @@ class Dish { case Dish.LIST_FILE: title = `${this.value.length} file(s)`; break; + case Dish.ARRAY_BUFFER: + case Dish.BYTE_ARRAY: + title = await this.detectDishType(); + if (title === null) { + title = await this.get("string"); + } + break; default: title = await this.get("string"); } diff --git a/src/web/waiters/TabWaiter.mjs b/src/web/waiters/TabWaiter.mjs index 9ae106de..2af6948c 100644 --- a/src/web/waiters/TabWaiter.mjs +++ b/src/web/waiters/TabWaiter.mjs @@ -159,6 +159,22 @@ class TabWaiter { 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; } @@ -170,22 +186,7 @@ class TabWaiter { * @returns {Element} */ createInputTabElement(inputNum, active=false) { - const newTab = 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; + return this.createTabElement(inputNum, active, "input"); } /**