This commit is contained in:
Julian Freeman
2026-04-19 08:55:44 -04:00
parent eb1d802f5b
commit e256e596c5
7 changed files with 161 additions and 80 deletions

View File

@@ -12,6 +12,23 @@ const store = useRequestStore();
const settings = useSettingsStore();
const isCopied = ref(false);
const isJsonResponse = computed(() => {
const response = store.activeRequest.response;
if (!response) return false;
const contentType = response.headers['content-type'] || response.headers['Content-Type'] || '';
if (contentType.toLowerCase().includes('json')) {
return true;
}
try {
JSON.parse(response.body);
return true;
} catch {
return false;
}
});
const extensions = computed(() => {
const theme = EditorView.theme({
"&": {
@@ -26,15 +43,20 @@ const extensions = computed(() => {
}
});
return [json(), oneDark, theme, EditorView.editable.of(false)];
return [
oneDark,
theme,
EditorView.editable.of(false),
...(isJsonResponse.value ? [json()] : []),
];
});
const formattedBody = computed(() => {
if (!store.activeRequest.response) return '';
if (!isJsonResponse.value) return store.activeRequest.response.body;
try {
// Auto pretty print
return JSON.stringify(JSON.parse(store.activeRequest.response.body), null, 2);
} catch (e) {
} catch {
return store.activeRequest.response.body;
}
});