Merge branch 'feat/binary-response' of https://github.com/AndrewBastin/postwoman into feat/binary-response

This commit is contained in:
Liyas Thomas
2020-06-22 14:27:53 +05:30
3 changed files with 13 additions and 23 deletions

View File

@@ -151,23 +151,18 @@ export default {
togglePreview() {
this.previewEnabled = !this.previewEnabled
if (this.previewEnabled) {
// If you want to add 'preview' support for other response types,
// just add them here.
if (this.responseType === "text/html") {
// If the preview already has that URL loaded, let's not bother re-loading it all.
if (this.$refs.previewFrame.getAttribute("data-previewing-url") === this.url) return
// Use DOMParser to parse document HTML.
const previewDocument = new DOMParser().parseFromString(
this.responseBodyText,
this.responseType
)
// Inject <base href="..."> tag to head, to fix relative CSS/HTML paths.
previewDocument.head.innerHTML =
`<base href="${this.url}">` + previewDocument.head.innerHTML
// Finally, set the iframe source to the resulting HTML.
this.$refs.previewFrame.srcdoc = previewDocument.documentElement.outerHTML
this.$refs.previewFrame.setAttribute("data-previewing-url", this.url)
}
if (this.$refs.previewFrame.getAttribute("data-previewing-url") === this.url) return
// Use DOMParser to parse document HTML.
const previewDocument = new DOMParser().parseFromString(
this.responseBodyText,
this.responseType
)
// Inject <base href="..."> tag to head, to fix relative CSS/HTML paths.
previewDocument.head.innerHTML =
`<base href="${this.url}">` + previewDocument.head.innerHTML
// Finally, set the iframe source to the resulting HTML.
this.$refs.previewFrame.srcdoc = previewDocument.documentElement.outerHTML
this.$refs.previewFrame.setAttribute("data-previewing-url", this.url)
}
},
},

View File

@@ -19,7 +19,6 @@ export default {
response: {
immediate: true,
handler(newValue) {
console.log("wetch")
this.imageSource = ""
const buf = this.response.body
@@ -28,7 +27,6 @@ export default {
const reader = new FileReader()
reader.onload = (e) => {
console.log(e.target.result)
this.imageSource = e.target.result
}
reader.readAsDataURL(blob)
@@ -37,17 +35,14 @@ export default {
},
mounted() {
console.log("mount")
this.imageSource = ""
console.log(this.response)
const buf = this.response.body
const bytes = new Uint8Array(buf)
const blob = new Blob([bytes.buffer])
const reader = new FileReader()
reader.onload = (e) => {
console.log(e.target.result)
this.imageSource = e.target.result
}
reader.readAsDataURL(blob)

View File

@@ -952,7 +952,7 @@
/>
</li>
</ul>
<div v-if="response.body">
<div v-if="response.body && response.body !== $t('loading')">
<response-renderer :response="response" />
</div>
<!--