Skip to content

Commit

Permalink
Revert "Download verify" (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
weearc authored Jan 13, 2024
1 parent 6fb7f92 commit 92dc701
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions components/DownloadModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,19 @@ export default {
}
const name = url.slice(url.lastIndexOf("/") + 1)
this.verifyPre(url)
const blobUrl = this.xhrDownloadHandler(this.selectedVersionUrl)
// const a = document.createElement("a")
// a.setAttribute("href", blobUrl)
// // a.setAttribute("href", this.selectedVersionUrl)
// a.setAttribute("download", name)
// a.click()
// a.remove()
const blobUrl = this.xhrDownloadHandler(this.selectedVersionUrl).toString()
const a = document.createElement("a")
a.setAttribute("href", blobUrl)
// a.setAttribute("href", this.selectedVersionUrl)
a.setAttribute("download", name)
a.click()
a.remove()
URL.revokeObjectURL(blobUrl)
this.$modal.hide('download-dialog')
},
async verifyPre(key) {
const xhr = new XMLHttpRequest()
const url = Api_mirror.getBaseurl({}) + key
// xhr.open('HEAD','https://mirrors.cqu.edu.cn/test.iso', true)
xhr.open('HEAD', url, true)
xhr.send()
xhr.onreadystatechange = await function () {
Expand All @@ -135,24 +135,14 @@ export default {
},
async xhrDownloadHandler(url) {
const xhr = new XMLHttpRequest()
// xhr.open('GET', 'https://mirrors.cqu.edu.cn/test.iso', true)
xhr.setRequestHeader('Cookie', document.cookie)
xhr.open('GET', url, true)
xhr.withCredentials = true
xhr.responseType = "blob"
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
const blob = xhr.response
const reader = new FileReader()
reader.readAsDataURL(blob)
reader.onload = function (e) {
const a = document.createElement("a")
a.setAttribute("href", e.target.result )
// a.setAttribute("href", this.selectedVersionUrl)
a.setAttribute("download", name)
a.click()
a.remove()
}
const data = xhr.response
const blob = new Blob([data], { type: 'application/octet-stream'})
return URL.createObjectURL(blob)
} else {
console.error('request failed. ', xhr.status)
return ''
Expand All @@ -163,7 +153,7 @@ export default {
},
addCookie(cookieName, cookieValue, path) {
document.cookie = `${cookieName}=${cookieValue}; max-age=300;`
// setTimeout("location.reload()", 5000)
setTimeout("location.reload()", 5000)
},
selectedChanged(newVal) {
if (this.selectedCategory === 0) {
Expand Down

0 comments on commit 92dc701

Please sign in to comment.