chore: rework api endpoints

This commit is contained in:
DaanSelen
2026-04-02 14:36:04 +02:00
parent 9315fe9c0e
commit 7bb3bf45c7
17 changed files with 127 additions and 74 deletions
+2 -2
View File
@@ -10,12 +10,12 @@ if (window.IS_WGDASHBOARD_DESKTOP){
store.IsElectronApp = true;
store.CrossServerConfiguration.Enable = true;
if (store.ActiveServerConfiguration){
fetchGet("/api/locale", {}, (res) => {
fetchGet("/api/dashboard/locale", {}, (res) => {
store.Locale = res.data
})
}
}else{
fetchGet("/api/locale", {}, (res) => {
fetchGet("/api/dashboard/locale", {}, (res) => {
store.Locale = res.data
})
}
@@ -16,22 +16,28 @@ export default {
}
},
mounted() {
fetchGet("/api/locale/available", {}, (res) => {
fetchGet("/api/dashboard/locale/available", {}, (res) => {
this.languages = res.data;
})
},
methods: {
changeLanguage(lang_id){
fetchPost("/api/locale/update", {
lang_id: lang_id
}, (res) => {
fetch("/api/dashboard/locale", {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ lang_id: lang_id }),
})
.then(res => res.json())
.then(res => {
if (res.status){
this.store.Configuration.server.wgdashboard_language = lang_id;
this.store.Locale = res.data
}else{
this.store.newMessage("Server", "WGDashboard language update failed", "danger")
this.store.Locale = res.data;
} else {
this.store.newMessage("Server", "WGDashboard failed to update the language", "danger")
}
})
});
}
},
computed:{
@@ -56,7 +56,7 @@ export default {
}
},
async connect(){
await fetch(`${this.server.host}/api/authenticate`, {
await fetch(`${this.server.host}/api/auth`, {
headers: this.getHeaders,
body: JSON.stringify({
host: window.location.hostname
@@ -11,7 +11,7 @@ export class WireguardConfigurations{
async getConfigurations(){
await fetchGet("/api/getWireguardConfigurations", {}, (res) => {
await fetchGet("/api/dashboard/wireguard/interfaces", {}, (res) => {
if (res.status) this.Configurations = res.data
});
}
+1 -1
View File
@@ -5,7 +5,7 @@ import {DashboardConfigurationStore} from "@/stores/DashboardConfigurationStore.
const checkAuth = async () => {
let result = false
await fetchGet("/api/validateAuthentication", {}, (res) => {
await fetchGet("/api/auth/validate", {}, (res) => {
result = res.status
});
return result;
@@ -60,7 +60,7 @@ export const DashboardConfigurationStore = defineStore('DashboardConfigurationSt
async setActiveCrossServer(key){
this.ActiveServerConfiguration = key;
localStorage.setItem('ActiveCrossServerConfiguration', key)
await fetchGet("/api/locale", {}, (res) => {
await fetchGet("/api/dashboard/locale", {}, (res) => {
this.Locale = res.data
})
},
@@ -101,7 +101,7 @@ export const WireguardConfigurationsStore = defineStore('WireguardConfigurations
},
actions: {
async getConfigurations(){
await fetchGet("/api/getWireguardConfigurations", {}, (res) => {
await fetchGet("/api/dashboard/wireguard/interfaces", {}, (res) => {
if (res.status) {
this.Configurations = res.data
}
+1 -1
View File
@@ -16,7 +16,7 @@ export default {
const theme = ref("");
const peerConfiguration = ref(undefined);
const blob = ref(new Blob())
await fetchGet("/api/getDashboardTheme", {}, (res) => {
await fetchGet("/api/dashboard/theme", {}, (res) => {
theme.value = res.data
});
+4 -4
View File
@@ -18,13 +18,13 @@ export default {
let version = undefined;
if (!store.IsElectronApp){
await Promise.all([
fetchGet("/api/getDashboardTheme", {}, (res) => {
fetchGet("/api/dashboard/theme", {}, (res) => {
theme = res.data
}),
fetchGet("/api/isTotpEnabled", {}, (res) => {
fetchGet("/api/dashboard/totp", {}, (res) => {
totpEnabled = res.data
}),
fetchGet("/api/getDashboardVersion", {}, (res) => {
fetchGet("/api/dashboard/version", {}, (res) => {
version = res.data
})
]);
@@ -60,7 +60,7 @@ export default {
async auth(){
if (this.formValid){
this.loading = true
await fetchPost("/api/authenticate", this.data, (response) => {
await fetchPost("/api/auth", this.data, (response) => {
if (response.status){
this.loginError = false;
this.$refs["signInBtn"].classList.add("signedIn")
+1 -1
View File
@@ -64,7 +64,7 @@ router.beforeEach(async (to, from, next) => {
store.newNotification("Sign in session ended, please sign in again", "warning")
}else{
if (to.meta.auth){
const status = await axiosGet('/api/validateAuthentication')
const status = await axiosGet('/api/auth/validate')
if (status){
next()
}else{