Files

36 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2026-01-22 17:55:23 +01:00
const GetCopy = {
props: [ 'name', 'href', 'token' ],
data() { return {showCopied: false} },
2026-06-17 22:40:44 +02:00
template: `<span><a :href="href" @click="fetchAndSave()">{{name}}</a>&nbsp;<a href="#" class="copy" @click="fetchAndCopy()">&#x1F5D0;</a></span>`,
2026-01-22 17:55:23 +01:00
methods: {
fetch() {
event.preventDefault()
return fetch(this.href, {
method: 'GET',
headers: { 'Authorization': 'Bearer ' + this.token },
})
},
handleFetchError(e) {
console.log("failed to get value:", e)
2026-06-17 22:40:44 +02:00
this.$root.toast('failed to get value', 'error')
2026-01-22 17:55:23 +01:00
},
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) => {
2026-06-17 22:40:44 +02:00
try {
window.navigator.clipboard.writeText(value)
this.$root.toast('copied!', 'info')
} catch (e) {
this.$root.toast('copy failed', 'error')
}
2026-01-22 17:55:23 +01:00
}).catch(this.handleFetchError)
},
},
}