Don't load response when blocking large responses

This commit is contained in:
Gregory Schier
2025-01-10 06:27:57 -08:00
parent f694456ddc
commit 8b5b66acf0
10 changed files with 197 additions and 122 deletions

View File

@@ -1,3 +1,4 @@
import MimeType from 'whatwg-mimetype';
import type { EditorProps } from '../components/core/Editor/Editor';
export function languageFromContentType(
@@ -40,10 +41,39 @@ export function isJSON(content: string | null | undefined): boolean {
if (typeof content !== 'string') return false;
try {
JSON.parse(content)
JSON.parse(content);
return true;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
return false;
}
}
export function isProbablyTextContentType(contentType: string | null): boolean {
if (contentType == null) return false;
const mimeType = getMimeTypeFromContentType(contentType).essence;
const normalized = mimeType.toLowerCase();
// Check if it starts with "text/"
if (normalized.startsWith('text/')) {
return true;
}
// Common text mimetypes and suffixes
return [
'application/json',
'application/xml',
'application/javascript',
'application/yaml',
'+json',
'+xml',
'+yaml',
'+text',
].some((textType) => normalized === textType || normalized.endsWith(textType));
}
export function getMimeTypeFromContentType(contentType: string) {
const mimeType = new MimeType(contentType);
return mimeType;
}