|
|
@ -1,4 +1,4 @@
|
|
|
|
import { getSize, isTextBody } from './utils'
|
|
|
|
import { arrayBufferToBase64, getSize, isTextBody } from './utils'
|
|
|
|
|
|
|
|
|
|
|
|
export enum MessageType {
|
|
|
|
export enum MessageType {
|
|
|
|
REQUEST = 1,
|
|
|
|
REQUEST = 1,
|
|
|
@ -42,6 +42,11 @@ export interface IFlowPreview {
|
|
|
|
costTime: string
|
|
|
|
costTime: string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IPreviewResponseBody {
|
|
|
|
|
|
|
|
type: 'image'
|
|
|
|
|
|
|
|
data: string
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export class Flow {
|
|
|
|
export class Flow {
|
|
|
|
public no: number
|
|
|
|
public no: number
|
|
|
|
public id: string
|
|
|
|
public id: string
|
|
|
@ -68,6 +73,8 @@ export class Flow {
|
|
|
|
private _requestBody: string | null
|
|
|
|
private _requestBody: string | null
|
|
|
|
private _responseBody: string | null
|
|
|
|
private _responseBody: string | null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private _previewResponseBody: IPreviewResponseBody | null = null
|
|
|
|
|
|
|
|
|
|
|
|
constructor(msg: IMessage) {
|
|
|
|
constructor(msg: IMessage) {
|
|
|
|
this.no = ++Flow.curNo
|
|
|
|
this.no = ++Flow.curNo
|
|
|
|
this.id = msg.id
|
|
|
|
this.id = msg.id
|
|
|
@ -167,6 +174,26 @@ export class Flow {
|
|
|
|
this._responseBody = new TextDecoder().decode(this.response?.body)
|
|
|
|
this._responseBody = new TextDecoder().decode(this.response?.body)
|
|
|
|
return this._responseBody
|
|
|
|
return this._responseBody
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public previewResponseBody(): IPreviewResponseBody | null {
|
|
|
|
|
|
|
|
if (this._previewResponseBody) return this._previewResponseBody
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.status < MessageType.RESPONSE_BODY) return null
|
|
|
|
|
|
|
|
if (!(this.response?.body?.byteLength)) return null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let contentType: string | undefined
|
|
|
|
|
|
|
|
if (this.response.header['Content-Type']) contentType = this.response.header['Content-Type'][0]
|
|
|
|
|
|
|
|
if (!contentType) return null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (contentType.startsWith('image/')) {
|
|
|
|
|
|
|
|
this._previewResponseBody = {
|
|
|
|
|
|
|
|
type: 'image',
|
|
|
|
|
|
|
|
data: arrayBufferToBase64(this.response.body),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this._previewResponseBody
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const allMessageBytes = [
|
|
|
|
const allMessageBytes = [
|
|
|
|