fix 1
This commit is contained in:
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user