diff --git a/frontend/src/components/PeerViewModal.vue b/frontend/src/components/PeerViewModal.vue index 905df4c..d5ea2a5 100644 --- a/frontend/src/components/PeerViewModal.vue +++ b/frontend/src/components/PeerViewModal.vue @@ -66,6 +66,29 @@ watch(() => props.visible, async (newValue, oldValue) => { } ) +function download() { + // credit: https://www.bitdegree.org/learn/javascript-download + let filename = 'WireGuard-Tunnel.conf' + if (selectedPeer.value.DisplayName) { + filename = selectedPeer.value.DisplayName + .replace(/ /g,"_") + .replace(/[^a-zA-Z0-9-_]/g,"") + .substring(0, 16) + + ".conf" + } + let text = configString.value + + let element = document.createElement('a') + element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)) + element.setAttribute('download', filename) + + element.style.display = 'none' + document.body.appendChild(element) + + element.click() + document.body.removeChild(element) +} +