2023-02-12 10:58:26 +00:00
|
|
|
export default {
|
|
|
|
props: [ 'name', 'href', 'token' ],
|
|
|
|
data() { return {showCopied: false} },
|
2023-02-12 14:18:42 +00:00
|
|
|
template: `<span class="notif"><div v-if="showCopied">copied!</div><a :href="href" @click="fetchAndSave()">{{name}}</a> <a href="#" class="copy" @click="fetchAndCopy()">🗐</a></span>`,
|
2023-02-12 10:58:26 +00:00
|
|
|
methods: {
|
2023-02-12 14:18:42 +00:00
|
|
|
fetch() {
|
2023-02-12 10:58:26 +00:00
|
|
|
event.preventDefault()
|
2023-02-12 14:18:42 +00:00
|
|
|
return fetch(this.href, {
|
2023-02-12 10:58:26 +00:00
|
|
|
method: 'GET',
|
|
|
|
headers: { 'Authorization': 'Bearer ' + this.token },
|
2023-02-12 14:18:42 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
handleFetchError(e) {
|
|
|
|
console.log("failed to get value:", e)
|
|
|
|
alert('failed to get value')
|
|
|
|
},
|
|
|
|
fetchAndSave() {
|
|
|
|
this.fetch().then(resp => resp.blob()).then((value) => {
|
|
|
|
window.open(URL.createObjectURL(value), "_blank")
|
|
|
|
}).catch(this.handleFetchError)
|
|
|
|
},
|
|
|
|
fetchAndCopy() {
|
|
|
|
this.fetch()
|
|
|
|
.then((resp) => resp.headers.get("content-type") == "application/json" ? resp.json() : resp.text())
|
|
|
|
.then((value) => {
|
2023-02-12 10:58:26 +00:00
|
|
|
window.navigator.clipboard.writeText(value)
|
|
|
|
this.showCopied = true
|
|
|
|
setTimeout(() => { this.showCopied = false }, 1000)
|
2023-02-12 14:18:42 +00:00
|
|
|
}).catch(this.handleFetchError)
|
2023-02-12 10:58:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|