From c622243f703776cff23d76cb2240abf995e0a8d7 Mon Sep 17 00:00:00 2001 From: "CATERPILLAR\\Braxen" Date: Wed, 17 Apr 2024 10:33:02 +0200 Subject: [PATCH] restrict config values to keys of fields --- .../components/forms/ChannelUpdateForm.vue | 2 +- .../src/components/forms/SettingsForm.vue | 26 ++-- client-vue/src/components/menu/SideMenu.vue | 2 +- .../src/components/vod/VodItemStatus.vue | 4 +- client-vue/src/store/index.ts | 4 +- common/Config.ts | 6 + common/ServerConfig.ts | 12 +- server/src/Controllers/Channels.ts | 7 +- server/src/Controllers/Settings.ts | 28 +++- server/src/Core/Config.ts | 143 +++++++++++------- server/src/Core/LiveStreamDVR.ts | 23 ++- .../Core/Providers/YouTube/YouTubeChannel.ts | 2 +- server/src/Providers/TikTok.ts | 10 +- server/tests/api.test.ts | 5 +- server/tests/config.test.ts | 6 +- 15 files changed, 177 insertions(+), 103 deletions(-) diff --git a/client-vue/src/components/forms/ChannelUpdateForm.vue b/client-vue/src/components/forms/ChannelUpdateForm.vue index c5d493f1..99918057 100644 --- a/client-vue/src/components/forms/ChannelUpdateForm.vue +++ b/client-vue/src/components/forms/ChannelUpdateForm.vue @@ -376,7 +376,7 @@ function deleteChannel() { } function subscribeChannel() { - if ((!store.cfg("app_url") || store.cfg("app_url") == "debug") && store.cfg("twitchapi.twitchapi.eventsub_type") === "webhook") { + if ((!store.cfg("app_url") || store.cfg("app_url") == "debug") && store.cfg("twitchapi.eventsub_type") === "webhook") { alert("Please set the app url in the settings"); return; } diff --git a/client-vue/src/components/forms/SettingsForm.vue b/client-vue/src/components/forms/SettingsForm.vue index ac4dc99e..1fb6a8b1 100644 --- a/client-vue/src/components/forms/SettingsForm.vue +++ b/client-vue/src/components/forms/SettingsForm.vue @@ -9,8 +9,8 @@ @@ -197,7 +197,7 @@ const { t, te } = useI18n(); const formStatusText = ref("Ready"); const formStatus = ref("IDLE"); const formData = ref<{ config: Record }>({ config: {} }); -const fetchedSettingsFields = ref({}); +const fetchedSettingsFields = ref(); const loading = ref(false); const searchText = ref(""); @@ -205,13 +205,14 @@ const searchText = ref(""); const settingsGroups = computed((): SettingsGroup[] => { if (!fetchedSettingsFields.value) return []; const groups: Record = {}; - for (const key in fetchedSettingsFields.value) { + for (const rawKey in fetchedSettingsFields.value) { + const key = rawKey as keyof typeof fetchedSettingsFields.value; const field = fetchedSettingsFields.value[key]; if (!field.group) continue; if (searchText.value) { if ( !key.toLowerCase().includes(searchText.value.toLowerCase()) && - !field.help?.toLowerCase().includes(searchText.value.toLowerCase()) && + ("help" in field && !field.help?.toLowerCase().includes(searchText.value.toLowerCase())) && !field.text?.toLowerCase().includes(searchText.value.toLowerCase()) ) continue; @@ -232,11 +233,14 @@ const settingsGroups = computed((): SettingsGroup[] => { */ }); -const newAndInterestingSettings = computed((): typeof settingsFields => { - const newSettings: typeof settingsFields = {}; - for (const key in fetchedSettingsFields.value) { +const newAndInterestingSettings = computed((): Record => { + const newSettings: Record = {} as any; + for (const rawKey in fetchedSettingsFields.value) { + const key = rawKey as keyof typeof fetchedSettingsFields.value; const field = fetchedSettingsFields.value[key]; - if (field.new) newSettings[key] = field; + if (field !== undefined && "new" in field && field.new) { + newSettings[key] = field; + } } return newSettings; // return fetchedSettingsFields.value.filter((field) => field.new); @@ -286,8 +290,8 @@ function fetchData(): void { // set defaults for (const key in fetchedSettingsFields.value) { - const field = fetchedSettingsFields.value[key]; - if (field.default !== undefined && formData.value.config[key] === undefined) { + const field = fetchedSettingsFields.value[key as keyof typeof fetchedSettingsFields.value]; + if ("default" in field && field.default !== undefined && formData.value.config[key] === undefined) { formData.value.config[key] = field.default; } } diff --git a/client-vue/src/components/menu/SideMenu.vue b/client-vue/src/components/menu/SideMenu.vue index b93c4667..1095a84c 100644 --- a/client-vue/src/components/menu/SideMenu.vue +++ b/client-vue/src/components/menu/SideMenu.vue @@ -4,7 +4,7 @@
- +

{{ store.app_name }}