toggle encryption in options

This commit is contained in:
SpikeHD
2022-07-02 14:16:20 -07:00
parent 98a948d377
commit 17ea745e23
5 changed files with 86 additions and 13 deletions

36
src/utils/server.ts Normal file
View File

@@ -0,0 +1,36 @@
import { fs } from '@tauri-apps/api'
export async function toggleEncryption(path: string) {
let serverConf
try {
serverConf = JSON.parse(await fs.readTextFile(path))
} catch(e) {
console.log(`Server config at ${path} not found or invalid`)
return
}
const enabled = serverConf.server.http.encryption.useEncryption
serverConf.server.http.encryption.useEncryption = !enabled
serverConf.server.http.encryption.useInRouting = !enabled
// Write file
await fs.writeFile({
path,
contents: JSON.stringify(serverConf)
})
}
export async function encryptionEnabled(path: string) {
let serverConf
try {
serverConf = JSON.parse(await fs.readTextFile(path))
} catch(e) {
console.log(`Server config at ${path} not found or invalid`)
return false
}
return serverConf.server.http.encryption.useEncryption
}