Compare commits

..

2 Commits

Author SHA1 Message Date
Gregory Schier
041298b3f8 Detect JSON language if application/javascript returns JSON 2025-05-21 11:05:20 -07:00
Gregory Schier
b400940f0e Fix import curl 2025-05-21 11:04:57 -07:00
2 changed files with 8 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
import type { HttpRequest} from '@yaakapp-internal/models';
import { createWorkspaceModel, patchModelById } from '@yaakapp-internal/models';
import type { HttpRequest } from '@yaakapp-internal/models';
import { patchModelById } from '@yaakapp-internal/models';
import { createRequestAndNavigate } from '../lib/createRequestAndNavigate';
import { jotaiStore } from '../lib/jotai';
import { invokeCmd } from '../lib/tauri';
import { showToast } from '../lib/toast';
@@ -26,7 +27,7 @@ export function useImportCurl() {
let verb;
if (overwriteRequestId == null) {
verb = 'Created';
await createWorkspaceModel(importedRequest);
await createRequestAndNavigate(importedRequest);
} else {
verb = 'Updated';
await patchModelById(importedRequest.model, overwriteRequestId, (r: HttpRequest) => ({

View File

@@ -11,7 +11,7 @@ export function languageFromContentType(
} else if (justContentType.includes('xml')) {
return 'xml';
} else if (justContentType.includes('html')) {
const detected = detectFromContent(content, 'html');
const detected = detectFromContent(content);
if (detected === 'xml') {
// If it's detected as XML, but is already HTML, don't change it
return 'html';
@@ -19,7 +19,8 @@ export function languageFromContentType(
return detected;
}
} else if (justContentType.includes('javascript')) {
return 'javascript';
// Sometimes `application/javascript` returns JSON, so try detecting that
return detectFromContent(content, 'javascript');
}
return detectFromContent(content, 'text');
@@ -27,7 +28,7 @@ export function languageFromContentType(
function detectFromContent(
content: string | null,
fallback: EditorProps['language'],
fallback?: EditorProps['language'],
): EditorProps['language'] {
if (content == null) return 'text';