fix type error on settingssave

This commit is contained in:
2021-07-11 14:26:10 +02:00
parent 64897d2abe
commit 24ecfb46e6
7 changed files with 62 additions and 48 deletions

View File

@ -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

View File

@ -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)
})
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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, "/") {