Merge branch 'settingssavefix' into 'master'

fix type error on settingssave

Closes #71

See merge request lukas/openmediacenter!50
This commit is contained in:
Lukas Heiligenbrunner 2021-07-11 12:45:08 +00:00
commit ebb55eb0dc
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, "/") {

View File

@ -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<Props, state> {
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<Props, state> {
<div className={style.infoheader}>
<InfoHeaderItem
backColor='lightblue'
text={this.state.generalSettings.VideoNr}
text={this.state.sizes.VideoNr}
subtext='Videos in Gravity'
icon={faArchive}
/>
<InfoHeaderItem
backColor='yellow'
text={this.state.generalSettings.DBSize + ' MB'}
text={this.state.sizes.DBSize + ' MB'}
subtext='Database size'
icon={faRulerVertical}
/>
<InfoHeaderItem
backColor='green'
text={this.state.generalSettings.DifferentTags}
text={this.state.sizes.DifferentTags}
subtext='different Tags'
icon={faAddressCard}
/>
<InfoHeaderItem
backColor='orange'
text={this.state.generalSettings.TagsAdded}
text={this.state.sizes.TagsAdded}
subtext='tags added'
icon={faBalanceScaleLeft}
/>
@ -210,8 +213,16 @@ class GeneralSettings extends React.Component<Props, state> {
* 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<Props, state> {
}
settings.DarkMode = GlobalInfos.isDarkTheme();
console.log(settings);
callAPI(
APINode.Settings,
{
action: 'saveGeneralSettings',
Settings: settings
...settings
},
(result: GeneralSuccess) => {
if (result.result) {

View File

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