mirror of
https://gitee.com/ssssssss-team/magic-api.git
synced 2026-06-09 10:23:53 +08:00
修复在结果预览中文件下载未显示文件名的问题
This commit is contained in:
@@ -4,6 +4,7 @@ import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
@@ -363,6 +364,14 @@ public class RequestHandler extends MagicController {
|
||||
*/
|
||||
private Object response(RequestEntity requestEntity, Object value) {
|
||||
if (value instanceof ResponseEntity) {
|
||||
if(requestEntity.isRequestedFromTest()){
|
||||
ResponseEntity<?> entity = (ResponseEntity<?>) value;
|
||||
Set<String> headerKeys = entity.getHeaders().keySet();
|
||||
if(!headerKeys.isEmpty()){
|
||||
// 允许前端读取自定义的header(跨域情况)。
|
||||
requestEntity.getResponse().setHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, String.join(",", headerKeys));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
} else if (value instanceof ResponseModule.NullValue) {
|
||||
return null;
|
||||
|
||||
@@ -685,7 +685,7 @@ export default {
|
||||
// 执行完毕
|
||||
target.running = false
|
||||
bus.$emit('switch-tab', 'result')
|
||||
bus.$emit('update-response-blob', contentType, data);
|
||||
bus.$emit('update-response-blob', contentType, data, res.headers);
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ import MagicJson from '@/components/common/magic-json.vue'
|
||||
import bus from '@/scripts/bus.js'
|
||||
import * as monaco from 'monaco-editor'
|
||||
import store from '@/scripts/store.js'
|
||||
import {isVisible, deepClone} from '@/scripts/utils.js'
|
||||
import {isVisible, deepClone, download as downloadFile} from '@/scripts/utils.js'
|
||||
import {parseJson} from '@/scripts/parsing/parser.js'
|
||||
|
||||
export default {
|
||||
@@ -63,9 +63,21 @@ export default {
|
||||
bus.$on('update-response-body-definition', (responseBodyDefinition) => {
|
||||
this.responseBody = responseBodyDefinition ? [responseBodyDefinition] : []
|
||||
})
|
||||
bus.$on('update-response-blob',(contentType, blob) => {
|
||||
bus.$on('update-response-blob',(contentType, blob, headers) => {
|
||||
this.contentType = contentType
|
||||
let disposition = headers['content-disposition'];
|
||||
if(disposition){
|
||||
try {
|
||||
let filename = disposition.replace(/.*filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/, '$1')
|
||||
downloadFile(blob, decodeURIComponent(filename))
|
||||
return
|
||||
} catch (_e){
|
||||
|
||||
}
|
||||
}
|
||||
this.objectUrl = URL.createObjectURL(blob)
|
||||
//
|
||||
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
@@ -108,7 +120,7 @@ export default {
|
||||
}
|
||||
let ret = parseJson(bodyStr)
|
||||
if(ret){
|
||||
this.responseBody = this.valueCopy(ret, [this.info.responseBodyDefinition]);
|
||||
this.responseBody = this.valueCopy(ret, [this.info.responseBodyDefinition || []]);
|
||||
this.forceUpdate = !this.forceUpdate
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user