Skip to content

Commit

Permalink
Download verify (#63)
Browse files Browse the repository at this point in the history
* add verify for iso

* release download button
  • Loading branch information
weearc authored Jan 13, 2024
1 parent 17a5c88 commit 20a5489
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions components/Api/Api_mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ export default {
},
getNotices: params => {
return (prefix + "/static/notice.json")
},
getBaseurl: params => {
return prefix
}
}
27 changes: 23 additions & 4 deletions components/DownloadModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
</template>

<script>
import Api_mirror from "@/components/Api/Api_mirror";
export default {
name: "DownloadModal",
props: {
Expand Down Expand Up @@ -100,22 +102,39 @@ export default {
},
handleBeforeClose() {
this.$emit('before-close')
},
verify() {
},
handleDownload() {
const url = this.selectedVersionUrl
if (url === 'about:blank') {
return
}
const name = url.slice(url.lastIndexOf("/") + 1)
console.log(url,"====> url")
const a = document.createElement("a")
this.verify(url)
this.verifyPre(url)
a.setAttribute("href", this.selectedVersionUrl)
a.setAttribute("download", name)
a.click()
a.remove()
this.$modal.hide('download-dialog')
},
async verifyPre(key) {
console.log(key)
const xhr = new XMLHttpRequest()
const url = Api_mirror.getBaseurl({}) + key
xhr.open('HEAD', url, true)
xhr.send()
xhr.onreadystatechange = await function () {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
// success
const headers = xhr.getResponseHeader('x-remote-addr')
this.addCookie('addr', headers, key)
}
}.bind(this)
},
addCookie(cookieName, cookieValue, path) {
document.cookie = `${cookieName}=${cookieValue}; max-age=300;`
setTimeout("location.reload()", 5000)
},
selectedChanged(newVal) {
if (this.selectedCategory === 0) {
Expand Down

0 comments on commit 20a5489

Please sign in to comment.