Skip to content

Commit 508ac27

Browse files
committed
support to show image
1 parent 0017141 commit 508ac27

File tree

12 files changed

+373
-170
lines changed

12 files changed

+373
-170
lines changed

console/atest-ui/src/views/TestCase.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ const parseResponseBody = (body: any) => {
112112
}
113113
}
114114
115+
const currentContentType = ref('')
116+
const currentImageContent = ref('')
117+
115118
/**
116119
* Handles test result data from API response
117120
*
@@ -124,6 +127,17 @@ const parseResponseBody = (body: any) => {
124127
*/
125128
const handleTestResult = (e: any): void => {
126129
testResult.value = e;
130+
currentContentType.value = e.header.find((h: Pair) => h.key.toLowerCase() === 'content-type')?.value || '';
131+
if (currentContentType.value.startsWith('image/')) {
132+
API.DownloadResponseFile({
133+
body: e.body}, (e) => {
134+
if (e && e.data) {
135+
currentImageContent.value = `data:${currentContentType.value};base64,${e.data}`;
136+
} else {
137+
console.error('No data to display as image.');
138+
}
139+
});
140+
}
127141
128142
if (!isHistoryTestCase.value) {
129143
handleTestResultError(e)
@@ -1372,7 +1386,8 @@ const renameTestCase = (name: string) => {
13721386
</div>
13731387
<div v-else>
13741388
<Codemirror v-if="!isResponseFile" v-model="testResult.bodyText"/>
1375-
<div v-if="isResponseFile" style="padding-top: 10px;">
1389+
<img v-if="currentContentType === 'image/png'" :src="currentImageContent" style="max-width: 100%; max-height: 500px;"/>
1390+
<div v-else-if="isResponseFile" style="padding-top: 10px;">
13761391
<el-row>
13771392
<el-col :span="10">
13781393
<div>Response body is too large, please download to view.</div>

console/atest-ui/src/views/net.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -828,16 +828,10 @@ interface ResponseFile {
828828
function DownloadResponseFile(testcase: ResponseFile,
829829
callback: (d: any) => void, errHandle?: (e: any) => void | null) {
830830
const requestOptions = {
831-
method: 'POST',
832831
headers: {
833832
'X-Store-Name': Cache.GetCurrentStore().name,
834833
'X-Auth': getToken()
835-
},
836-
body: JSON.stringify({
837-
response: {
838-
body: testcase.body,
839-
}
840-
})
834+
}
841835
}
842836
fetch(`/api/v1/downloadFile/${testcase.body}`, requestOptions)
843837
.then(DefaultResponseProcess)

pkg/runner/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (r *simpleTestCaseRunner) RunTestCase(testcase *testing.TestCase, dataConte
257257
err = errors.Join(err, jsonSchemaValidation(testcase.Expect.Schema, responseBodyData))
258258
} else {
259259
switch respType {
260-
case util.OctetStream, util.Image:
260+
case util.OctetStream, util.Image, util.ImagePNG:
261261
var data []byte
262262
if data, err = io.ReadAll(resp.Body); err == nil {
263263
r.simpleResponse.RawBody = data

pkg/runner/monitor/monitor.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/runner/monitor/monitor_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/server/server.pb.go

Lines changed: 85 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)