Replies: 2 comments 2 replies
-
Got it!(function (Scratch) {
'use strict';
class MimeTypeDetector {
getInfo() {
return {
id: 'mimeTypeDetector',
name: 'MIME Type Detector',
blocks: [
{
opcode: 'detectMimeType',
blockType: Scratch.BlockType.REPORTER,
text: 'detect MIME type of [TEXT]',
arguments: {
TEXT: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Hello, world!'
}
}
}
]
};
}
detectMimeType(args) {
const text = args.TEXT || '';
if (text.startsWith('<svg')) {
return 'image/svg+xml';
} else if (text.startsWith('<?xml')) {
return 'application/xml';
} else if (text.startsWith('{')) {
return 'application/json';
} else if (text.startsWith('[')) {
return 'application/json';
} else if (/^[\s\S]+<html/i.test(text)) {
return 'text/html';
} else if (/^[\s\S]+<body/i.test(text)) {
return 'text/html';
} else {
return 'text/plain;charset=UTF-8';
}
}
}
Scratch.extensions.register(new MimeTypeDetector());
})(Scratch); GG EZ |
Beta Was this translation helpful? Give feedback.
2 replies
-
i guess fileheaders would work |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Someone should make an extension to detect mime types like:
hello
istext/plain;charset=UTF-8
, and<svg />
isimage/svg+xml
, and so on.Beta Was this translation helpful? Give feedback.
All reactions