mirror of
https://github.com/gchq/CyberChef
synced 2025-12-15 15:53:30 +00:00
Added 'isImage' and 'isType' functions
This commit is contained in:
@@ -9,7 +9,7 @@ import { fromHex } from "../lib/Hex";
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import Utils from "../Utils";
|
||||
import {detectFileType} from "../lib/FileType";
|
||||
import {isImage} from "../lib/FileType";
|
||||
|
||||
/**
|
||||
* Render Image operation
|
||||
@@ -72,8 +72,7 @@ class RenderImage extends Operation {
|
||||
}
|
||||
|
||||
// Determine file type
|
||||
const types = detectFileType(input);
|
||||
if (!(types.length && types[0].mime.indexOf("image") === 0)) {
|
||||
if (!isImage(input)) {
|
||||
throw new OperationError("Invalid file type");
|
||||
}
|
||||
|
||||
@@ -92,9 +91,9 @@ class RenderImage extends Operation {
|
||||
let dataURI = "data:";
|
||||
|
||||
// Determine file type
|
||||
const types = detectFileType(data);
|
||||
if (types.length && types[0].mime.indexOf("image") === 0) {
|
||||
dataURI += types[0].mime + ";";
|
||||
const mime = isImage(data);
|
||||
if (mime) {
|
||||
dataURI += mime + ";";
|
||||
} else {
|
||||
throw new OperationError("Invalid file type");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user