generate interface and peer configuration filenames in backend only (#395)

This commit is contained in:
Christoph
2025-04-19 13:12:31 +02:00
parent a60feb7fc9
commit 6681dfa96f
14 changed files with 91 additions and 20 deletions

View File

@@ -89,19 +89,11 @@ 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:application/octet-stream;charset=utf-8,' + encodeURIComponent(text))
element.setAttribute('download', filename)
element.setAttribute('download', selectedPeer.value.Filename)
element.style.display = 'none'
document.body.appendChild(element)

View File

@@ -42,7 +42,8 @@ export function freshInterface() {
PeerDefPostDown: "",
TotalPeers: 0,
EnabledPeers: 0
EnabledPeers: 0,
Filename: ""
}
}
@@ -120,6 +121,8 @@ export function freshPeer() {
Overridable: true,
},
Filename: "",
// Internal values
IgnoreGlobalSettings: false,
IsSelected: false

View File

@@ -49,12 +49,11 @@ async function download() {
await interfaces.LoadInterfaceConfig(interfaces.GetSelected.Identifier)
// credit: https://www.bitdegree.org/learn/javascript-download
let filename = interfaces.GetSelected.Identifier + ".conf"
let text = interfaces.configuration
let element = document.createElement('a')
element.setAttribute('href', 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(text))
element.setAttribute('download', filename)
element.setAttribute('download', interfaces.GetSelected.Filename)
element.style.display = 'none'
document.body.appendChild(element)