From 24ecfb46e6792533d926e7103b836535df3ea875 Mon Sep 17 00:00:00 2001 From: lukas Date: Sun, 11 Jul 2021 14:26:10 +0200 Subject: [PATCH] fix type error on settingssave --- apiGo/api/Helpers.go | 3 +- apiGo/api/Settings.go | 44 ++++++++++++---------- apiGo/api/types/Types.go | 4 +- apiGo/database/Database.go | 11 ++---- apiGo/videoparser/VideoParser.go | 8 ++-- src/pages/SettingsPage/GeneralSettings.tsx | 36 ++++++++++++------ src/types/ApiTypes.ts | 4 +- 7 files changed, 62 insertions(+), 48 deletions(-) diff --git a/apiGo/api/Helpers.go b/apiGo/api/Helpers.go index 259f955..aac7b93 100644 --- a/apiGo/api/Helpers.go +++ b/apiGo/api/Helpers.go @@ -3,7 +3,6 @@ package api import ( "database/sql" "encoding/json" - "errors" "fmt" "openmediacenter/apiGo/api/types" "reflect" @@ -109,7 +108,7 @@ func setField(obj interface{}, name string, value interface{}) error { // if type is convertible - convert and set structFieldValue.Set(val.Convert(structFieldType)) } else { - return errors.New("provided value type didn't match obj field type and isn't convertible") + return fmt.Errorf("provided value %s type didn't match obj field type and isn't convertible", name) } } else { // set value if type is the same diff --git a/apiGo/api/Settings.go b/apiGo/api/Settings.go index 63210e4..711d4de 100644 --- a/apiGo/api/Settings.go +++ b/apiGo/api/Settings.go @@ -31,15 +31,23 @@ func getSettingsFromDB() { * @apiSuccess {string} Settings.Password new server password (-1 if no password set) * @apiSuccess {bool} Settings.TMDBGrabbing TMDB grabbing support to grab tag info and thumbnails * @apiSuccess {bool} Settings.DarkMode Darkmode enabled? - * @apiSuccess {uint32} Settings.VideoNr total number of videos - * @apiSuccess {float32} Settings.DBSize total size of database - * @apiSuccess {uint32} Settings.DifferentTags number of different tags available - * @apiSuccess {uint32} Settings.TagsAdded number of different tags added to videos - * @apiSuccess {string} Settings.PathPrefix + * @apiSuccess {Object} Sizes Sizes object + * @apiSuccess {uint32} Sizes.VideoNr total number of videos + * @apiSuccess {float32} Sizes.DBSize total size of database + * @apiSuccess {uint32} Sizes.DifferentTags number of different tags available + * @apiSuccess {uint32} Sizes.TagsAdded number of different tags added to videos */ AddHandler("loadGeneralSettings", SettingsNode, func(info *HandlerInfo) []byte { - result := database.GetSettings() - return jsonify(result) + result, _, sizes := database.GetSettings() + + var ret = struct { + Settings *types.SettingsType + Sizes *types.SettingsSizeType + }{ + Settings: &result, + Sizes: &sizes, + } + return jsonify(ret) }) /** @@ -94,21 +102,17 @@ func saveSettingsToDB() { * @apiName saveGeneralSettings * @apiGroup Settings * - * @apiParam {Object} Settings Settings object - * @apiParam {string} Settings.VideoPath webserver path to the videos - * @apiParam {string} Settings.EpisodePath webserver path to the tvshows - * @apiParam {string} Settings.MediacenterName overall name of the mediacenter - * @apiParam {string} Settings.Password new server password (-1 if no password set) - * @apiParam {bool} Settings.TMDBGrabbing TMDB grabbing support to grab tag info and thumbnails - * @apiParam {bool} Settings.DarkMode Darkmode enabled? + * @apiParam {string} VideoPath webserver path to the videos + * @apiParam {string} EpisodePath webserver path to the tvshows + * @apiParam {string} MediacenterName overall name of the mediacenter + * @apiParam {string} Password new server password (-1 if no password set) + * @apiParam {bool} TMDBGrabbing TMDB grabbing support to grab tag info and thumbnails + * @apiParam {bool} DarkMode Darkmode enabled? * * @apiSuccess {string} result 'success' if successfully or error message if not */ AddHandler("saveGeneralSettings", SettingsNode, func(info *HandlerInfo) []byte { - // todo correct type here! - var args struct { - Settings types.SettingsType - } + var args types.SettingsType if err := FillStruct(&args, info.Data); err != nil { fmt.Println(err.Error()) return nil @@ -124,8 +128,8 @@ func saveSettingsToDB() { DarkMode=? WHERE 1` return database.SuccessQuery(query, - args.Settings.VideoPath, args.Settings.EpisodePath, args.Settings.Password, - args.Settings.MediacenterName, args.Settings.TMDBGrabbing, args.Settings.DarkMode) + args.VideoPath, args.EpisodePath, args.Password, + args.MediacenterName, args.TMDBGrabbing, args.DarkMode) }) } diff --git a/apiGo/api/types/Types.go b/apiGo/api/types/Types.go index e0d9652..bb85f3b 100644 --- a/apiGo/api/types/Types.go +++ b/apiGo/api/types/Types.go @@ -46,13 +46,13 @@ type SettingsType struct { PasswordEnabled bool TMDBGrabbing bool DarkMode bool +} +type SettingsSizeType struct { VideoNr uint32 DBSize float32 DifferentTags uint32 TagsAdded uint32 - - PathPrefix string } type TVShow struct { diff --git a/apiGo/database/Database.go b/apiGo/database/Database.go index 58fc930..5eb7f3f 100644 --- a/apiGo/database/Database.go +++ b/apiGo/database/Database.go @@ -90,9 +90,7 @@ func Close() { db.Close() } -func GetSettings() types.SettingsType { - var result types.SettingsType - +func GetSettings() (result types.SettingsType, PathPrefix string, sizes types.SettingsSizeType) { // query settings and infotile values query := fmt.Sprintf(` SELECT ( @@ -120,7 +118,7 @@ func GetSettings() types.SettingsType { var DarkMode int var TMDBGrabbing int - err := QueryRow(query).Scan(&result.VideoNr, &result.DBSize, &result.DifferentTags, &result.TagsAdded, + err := QueryRow(query).Scan(&sizes.VideoNr, &sizes.DBSize, &sizes.DifferentTags, &sizes.TagsAdded, &result.VideoPath, &result.EpisodePath, &result.Password, &result.MediacenterName, &TMDBGrabbing, &DarkMode) if err != nil { @@ -130,7 +128,6 @@ func GetSettings() types.SettingsType { result.TMDBGrabbing = TMDBGrabbing != 0 result.PasswordEnabled = result.Password != "-1" result.DarkMode = DarkMode != 0 - result.PathPrefix = SettingsVideoPrefix - - return result + PathPrefix = SettingsVideoPrefix + return } diff --git a/apiGo/videoparser/VideoParser.go b/apiGo/videoparser/VideoParser.go index f056b7b..9175962 100644 --- a/apiGo/videoparser/VideoParser.go +++ b/apiGo/videoparser/VideoParser.go @@ -19,9 +19,9 @@ func StartReindex() bool { SendEvent("start") AppendMessage("starting reindex..") - mSettings := database.GetSettings() + mSettings, PathPrefix, _ := database.GetSettings() // add the path prefix to videopath - mSettings.VideoPath = mSettings.PathPrefix + mSettings.VideoPath + mSettings.VideoPath = PathPrefix + mSettings.VideoPath // check if path even exists if _, err := os.Stat(mSettings.VideoPath); os.IsNotExist(err) { @@ -64,9 +64,9 @@ func StartTVShowReindex() { SendEvent("start") AppendMessage("starting tvshow reindex...") - mSettings := database.GetSettings() + mSettings, PathPrefix, _ := database.GetSettings() // add the path prefix to videopath - mSettings.EpisodePath = mSettings.PathPrefix + mSettings.EpisodePath + mSettings.EpisodePath = PathPrefix + mSettings.EpisodePath // add slash suffix if not existing if !strings.HasSuffix(mSettings.EpisodePath, "/") { diff --git a/src/pages/SettingsPage/GeneralSettings.tsx b/src/pages/SettingsPage/GeneralSettings.tsx index 4c604e9..5ba2f7c 100644 --- a/src/pages/SettingsPage/GeneralSettings.tsx +++ b/src/pages/SettingsPage/GeneralSettings.tsx @@ -11,7 +11,8 @@ import {SettingsTypes} from '../../types/ApiTypes'; import {GeneralSuccess} from '../../types/GeneralTypes'; interface state { - generalSettings: SettingsTypes.loadGeneralSettingsType; + generalSettings: SettingsTypes.SettingsType; + sizes: SettingsTypes.SizesType; } interface Props {} @@ -27,16 +28,18 @@ class GeneralSettings extends React.Component { this.state = { generalSettings: { DarkMode: true, - DBSize: 0, - DifferentTags: 0, EpisodePath: '', MediacenterName: '', Password: '', PasswordEnabled: false, - TagsAdded: 0, TMDBGrabbing: false, - VideoNr: 0, VideoPath: '' + }, + sizes: { + DBSize: 0, + DifferentTags: 0, + TagsAdded: 0, + VideoNr: 0 } }; } @@ -52,25 +55,25 @@ class GeneralSettings extends React.Component {
@@ -210,8 +213,16 @@ class GeneralSettings extends React.Component { * inital load of already specified settings from backend */ loadSettings(): void { - callAPI(APINode.Settings, {action: 'loadGeneralSettings'}, (result: SettingsTypes.loadGeneralSettingsType) => { - this.setState({generalSettings: result}); + interface SettingsResponseType { + Settings: SettingsTypes.SettingsType; + Sizes: SettingsTypes.SizesType; + } + + callAPI(APINode.Settings, {action: 'loadGeneralSettings'}, (result: SettingsResponseType) => { + this.setState({ + generalSettings: result.Settings, + sizes: result.Sizes + }); }); } @@ -225,11 +236,12 @@ class GeneralSettings extends React.Component { } settings.DarkMode = GlobalInfos.isDarkTheme(); + console.log(settings); callAPI( APINode.Settings, { action: 'saveGeneralSettings', - Settings: settings + ...settings }, (result: GeneralSuccess) => { if (result.result) { diff --git a/src/types/ApiTypes.ts b/src/types/ApiTypes.ts index 3c80a26..69b804a 100644 --- a/src/types/ApiTypes.ts +++ b/src/types/ApiTypes.ts @@ -39,7 +39,7 @@ export namespace SettingsTypes { TVShowEnabled: boolean; } - export interface loadGeneralSettingsType { + export interface SettingsType { VideoPath: string; EpisodePath: string; MediacenterName: string; @@ -47,7 +47,9 @@ export namespace SettingsTypes { PasswordEnabled: boolean; TMDBGrabbing: boolean; DarkMode: boolean; + } + export interface SizesType { VideoNr: number; DBSize: number; DifferentTags: number;