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() { togglePreview() {
this.previewEnabled = !this.previewEnabled this.previewEnabled = !this.previewEnabled
if (this.previewEnabled) { if (this.previewEnabled) {
// If you want to add 'preview' support for other response types, if (this.$refs.previewFrame.getAttribute("data-previewing-url") === this.url) return
// just add them here. // Use DOMParser to parse document HTML.
if (this.responseType === "text/html") { const previewDocument = new DOMParser().parseFromString(
// If the preview already has that URL loaded, let's not bother re-loading it all. this.responseBodyText,
if (this.$refs.previewFrame.getAttribute("data-previewing-url") === this.url) return this.responseType
// Use DOMParser to parse document HTML. )
const previewDocument = new DOMParser().parseFromString( // Inject <base href="..."> tag to head, to fix relative CSS/HTML paths.
this.responseBodyText, previewDocument.head.innerHTML =
this.responseType `<base href="${this.url}">` + previewDocument.head.innerHTML
) // Finally, set the iframe source to the resulting HTML.
// Inject <base href="..."> tag to head, to fix relative CSS/HTML paths. this.$refs.previewFrame.srcdoc = previewDocument.documentElement.outerHTML
previewDocument.head.innerHTML = this.$refs.previewFrame.setAttribute("data-previewing-url", this.url)
`<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: { response: {
immediate: true, immediate: true,
handler(newValue) { handler(newValue) {
console.log("wetch")
this.imageSource = "" this.imageSource = ""
const buf = this.response.body const buf = this.response.body
@@ -28,7 +27,6 @@ export default {
const reader = new FileReader() const reader = new FileReader()
reader.onload = (e) => { reader.onload = (e) => {
console.log(e.target.result)
this.imageSource = e.target.result this.imageSource = e.target.result
} }
reader.readAsDataURL(blob) reader.readAsDataURL(blob)
@@ -37,17 +35,14 @@ export default {
}, },
mounted() { mounted() {
console.log("mount")
this.imageSource = "" this.imageSource = ""
console.log(this.response)
const buf = this.response.body const buf = this.response.body
const bytes = new Uint8Array(buf) const bytes = new Uint8Array(buf)
const blob = new Blob([bytes.buffer]) const blob = new Blob([bytes.buffer])
const reader = new FileReader() const reader = new FileReader()
reader.onload = (e) => { reader.onload = (e) => {
console.log(e.target.result)
this.imageSource = e.target.result this.imageSource = e.target.result
} }
reader.readAsDataURL(blob) reader.readAsDataURL(blob)

View File

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