fix type error on settingssave
This commit is contained in:
		| @@ -3,7 +3,6 @@ package api | |||||||
| import ( | import ( | ||||||
| 	"database/sql" | 	"database/sql" | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"errors" |  | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"openmediacenter/apiGo/api/types" | 	"openmediacenter/apiGo/api/types" | ||||||
| 	"reflect" | 	"reflect" | ||||||
| @@ -109,7 +108,7 @@ func setField(obj interface{}, name string, value interface{}) error { | |||||||
| 			// if type is convertible - convert and set | 			// if type is convertible - convert and set | ||||||
| 			structFieldValue.Set(val.Convert(structFieldType)) | 			structFieldValue.Set(val.Convert(structFieldType)) | ||||||
| 		} else { | 		} 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 { | 	} else { | ||||||
| 		// set value if type is the same | 		// set value if type is the same | ||||||
|   | |||||||
| @@ -31,15 +31,23 @@ func getSettingsFromDB() { | |||||||
| 	 * @apiSuccess {string} Settings.Password new server password (-1 if no password set) | 	 * @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.TMDBGrabbing TMDB grabbing support to grab tag info and thumbnails | ||||||
| 	 * @apiSuccess {bool} Settings.DarkMode Darkmode enabled? | 	 * @apiSuccess {bool} Settings.DarkMode Darkmode enabled? | ||||||
| 	 * @apiSuccess {uint32} Settings.VideoNr total number of videos | 	 * @apiSuccess {Object} Sizes Sizes object | ||||||
| 	 * @apiSuccess {float32} Settings.DBSize total size of database | 	 * @apiSuccess {uint32} Sizes.VideoNr total number of videos | ||||||
| 	 * @apiSuccess {uint32} Settings.DifferentTags number of different tags available | 	 * @apiSuccess {float32} Sizes.DBSize total size of database | ||||||
| 	 * @apiSuccess {uint32} Settings.TagsAdded number of different tags added to videos | 	 * @apiSuccess {uint32} Sizes.DifferentTags number of different tags available | ||||||
| 	 * @apiSuccess {string} Settings.PathPrefix | 	 * @apiSuccess {uint32} Sizes.TagsAdded number of different tags added to videos | ||||||
| 	 */ | 	 */ | ||||||
| 	AddHandler("loadGeneralSettings", SettingsNode, func(info *HandlerInfo) []byte { | 	AddHandler("loadGeneralSettings", SettingsNode, func(info *HandlerInfo) []byte { | ||||||
| 		result := database.GetSettings() | 		result, _, sizes := database.GetSettings() | ||||||
| 		return jsonify(result) |  | ||||||
|  | 		var ret = struct { | ||||||
|  | 			Settings *types.SettingsType | ||||||
|  | 			Sizes    *types.SettingsSizeType | ||||||
|  | 		}{ | ||||||
|  | 			Settings: &result, | ||||||
|  | 			Sizes:    &sizes, | ||||||
|  | 		} | ||||||
|  | 		return jsonify(ret) | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| @@ -94,21 +102,17 @@ func saveSettingsToDB() { | |||||||
| 	 * @apiName saveGeneralSettings | 	 * @apiName saveGeneralSettings | ||||||
| 	 * @apiGroup Settings | 	 * @apiGroup Settings | ||||||
| 	 * | 	 * | ||||||
| 	 * @apiParam {Object} Settings Settings object | 	 * @apiParam {string} VideoPath webserver path to the videos | ||||||
| 	 * @apiParam {string} Settings.VideoPath webserver path to the videos | 	 * @apiParam {string} EpisodePath webserver path to the tvshows | ||||||
| 	 * @apiParam {string} Settings.EpisodePath webserver path to the tvshows | 	 * @apiParam {string} MediacenterName overall name of the mediacenter | ||||||
| 	 * @apiParam {string} Settings.MediacenterName overall name of the mediacenter | 	 * @apiParam {string} Password new server password (-1 if no password set) | ||||||
| 	 * @apiParam {string} Settings.Password new server password (-1 if no password set) | 	 * @apiParam {bool} TMDBGrabbing TMDB grabbing support to grab tag info and thumbnails | ||||||
| 	 * @apiParam {bool} Settings.TMDBGrabbing TMDB grabbing support to grab tag info and thumbnails | 	 * @apiParam {bool} DarkMode Darkmode enabled? | ||||||
| 	 * @apiParam {bool} Settings.DarkMode Darkmode enabled? |  | ||||||
| 	 * | 	 * | ||||||
| 	 * @apiSuccess {string} result 'success' if successfully or error message if not | 	 * @apiSuccess {string} result 'success' if successfully or error message if not | ||||||
| 	 */ | 	 */ | ||||||
| 	AddHandler("saveGeneralSettings", SettingsNode, func(info *HandlerInfo) []byte { | 	AddHandler("saveGeneralSettings", SettingsNode, func(info *HandlerInfo) []byte { | ||||||
| 		// todo correct type here! | 		var args types.SettingsType | ||||||
| 		var args struct { |  | ||||||
| 			Settings types.SettingsType |  | ||||||
| 		} |  | ||||||
| 		if err := FillStruct(&args, info.Data); err != nil { | 		if err := FillStruct(&args, info.Data); err != nil { | ||||||
| 			fmt.Println(err.Error()) | 			fmt.Println(err.Error()) | ||||||
| 			return nil | 			return nil | ||||||
| @@ -124,8 +128,8 @@ func saveSettingsToDB() { | |||||||
|                         DarkMode=? |                         DarkMode=? | ||||||
|                     WHERE 1` |                     WHERE 1` | ||||||
| 		return database.SuccessQuery(query, | 		return database.SuccessQuery(query, | ||||||
| 			args.Settings.VideoPath, args.Settings.EpisodePath, args.Settings.Password, | 			args.VideoPath, args.EpisodePath, args.Password, | ||||||
| 			args.Settings.MediacenterName, args.Settings.TMDBGrabbing, args.Settings.DarkMode) | 			args.MediacenterName, args.TMDBGrabbing, args.DarkMode) | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -46,13 +46,13 @@ type SettingsType struct { | |||||||
| 	PasswordEnabled bool | 	PasswordEnabled bool | ||||||
| 	TMDBGrabbing    bool | 	TMDBGrabbing    bool | ||||||
| 	DarkMode        bool | 	DarkMode        bool | ||||||
|  | } | ||||||
|  |  | ||||||
|  | type SettingsSizeType struct { | ||||||
| 	VideoNr       uint32 | 	VideoNr       uint32 | ||||||
| 	DBSize        float32 | 	DBSize        float32 | ||||||
| 	DifferentTags uint32 | 	DifferentTags uint32 | ||||||
| 	TagsAdded     uint32 | 	TagsAdded     uint32 | ||||||
|  |  | ||||||
| 	PathPrefix string |  | ||||||
| } | } | ||||||
|  |  | ||||||
| type TVShow struct { | type TVShow struct { | ||||||
|   | |||||||
| @@ -90,9 +90,7 @@ func Close() { | |||||||
| 	db.Close() | 	db.Close() | ||||||
| } | } | ||||||
|  |  | ||||||
| func GetSettings() types.SettingsType { | func GetSettings() (result types.SettingsType, PathPrefix string, sizes types.SettingsSizeType) { | ||||||
| 	var result types.SettingsType |  | ||||||
|  |  | ||||||
| 	// query settings and infotile values | 	// query settings and infotile values | ||||||
| 	query := fmt.Sprintf(` | 	query := fmt.Sprintf(` | ||||||
|                 SELECT ( |                 SELECT ( | ||||||
| @@ -120,7 +118,7 @@ func GetSettings() types.SettingsType { | |||||||
| 	var DarkMode int | 	var DarkMode int | ||||||
| 	var TMDBGrabbing 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) | 		&result.VideoPath, &result.EpisodePath, &result.Password, &result.MediacenterName, &TMDBGrabbing, &DarkMode) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -130,7 +128,6 @@ func GetSettings() types.SettingsType { | |||||||
| 	result.TMDBGrabbing = TMDBGrabbing != 0 | 	result.TMDBGrabbing = TMDBGrabbing != 0 | ||||||
| 	result.PasswordEnabled = result.Password != "-1" | 	result.PasswordEnabled = result.Password != "-1" | ||||||
| 	result.DarkMode = DarkMode != 0 | 	result.DarkMode = DarkMode != 0 | ||||||
| 	result.PathPrefix = SettingsVideoPrefix | 	PathPrefix = SettingsVideoPrefix | ||||||
|  | 	return | ||||||
| 	return result |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -19,9 +19,9 @@ func StartReindex() bool { | |||||||
| 	SendEvent("start") | 	SendEvent("start") | ||||||
| 	AppendMessage("starting reindex..") | 	AppendMessage("starting reindex..") | ||||||
|  |  | ||||||
| 	mSettings := database.GetSettings() | 	mSettings, PathPrefix, _ := database.GetSettings() | ||||||
| 	// add the path prefix to videopath | 	// add the path prefix to videopath | ||||||
| 	mSettings.VideoPath = mSettings.PathPrefix + mSettings.VideoPath | 	mSettings.VideoPath = PathPrefix + mSettings.VideoPath | ||||||
|  |  | ||||||
| 	// check if path even exists | 	// check if path even exists | ||||||
| 	if _, err := os.Stat(mSettings.VideoPath); os.IsNotExist(err) { | 	if _, err := os.Stat(mSettings.VideoPath); os.IsNotExist(err) { | ||||||
| @@ -64,9 +64,9 @@ func StartTVShowReindex() { | |||||||
| 	SendEvent("start") | 	SendEvent("start") | ||||||
| 	AppendMessage("starting tvshow reindex...") | 	AppendMessage("starting tvshow reindex...") | ||||||
|  |  | ||||||
| 	mSettings := database.GetSettings() | 	mSettings, PathPrefix, _ := database.GetSettings() | ||||||
| 	// add the path prefix to videopath | 	// add the path prefix to videopath | ||||||
| 	mSettings.EpisodePath = mSettings.PathPrefix + mSettings.EpisodePath | 	mSettings.EpisodePath = PathPrefix + mSettings.EpisodePath | ||||||
|  |  | ||||||
| 	// add slash suffix if not existing | 	// add slash suffix if not existing | ||||||
| 	if !strings.HasSuffix(mSettings.EpisodePath, "/") { | 	if !strings.HasSuffix(mSettings.EpisodePath, "/") { | ||||||
|   | |||||||
| @@ -11,7 +11,8 @@ import {SettingsTypes} from '../../types/ApiTypes'; | |||||||
| import {GeneralSuccess} from '../../types/GeneralTypes'; | import {GeneralSuccess} from '../../types/GeneralTypes'; | ||||||
|  |  | ||||||
| interface state { | interface state { | ||||||
|     generalSettings: SettingsTypes.loadGeneralSettingsType; |     generalSettings: SettingsTypes.SettingsType; | ||||||
|  |     sizes: SettingsTypes.SizesType; | ||||||
| } | } | ||||||
|  |  | ||||||
| interface Props {} | interface Props {} | ||||||
| @@ -27,16 +28,18 @@ class GeneralSettings extends React.Component<Props, state> { | |||||||
|         this.state = { |         this.state = { | ||||||
|             generalSettings: { |             generalSettings: { | ||||||
|                 DarkMode: true, |                 DarkMode: true, | ||||||
|                 DBSize: 0, |  | ||||||
|                 DifferentTags: 0, |  | ||||||
|                 EpisodePath: '', |                 EpisodePath: '', | ||||||
|                 MediacenterName: '', |                 MediacenterName: '', | ||||||
|                 Password: '', |                 Password: '', | ||||||
|                 PasswordEnabled: false, |                 PasswordEnabled: false, | ||||||
|                 TagsAdded: 0, |  | ||||||
|                 TMDBGrabbing: false, |                 TMDBGrabbing: false, | ||||||
|                 VideoNr: 0, |  | ||||||
|                 VideoPath: '' |                 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}> |                 <div className={style.infoheader}> | ||||||
|                     <InfoHeaderItem |                     <InfoHeaderItem | ||||||
|                         backColor='lightblue' |                         backColor='lightblue' | ||||||
|                         text={this.state.generalSettings.VideoNr} |                         text={this.state.sizes.VideoNr} | ||||||
|                         subtext='Videos in Gravity' |                         subtext='Videos in Gravity' | ||||||
|                         icon={faArchive} |                         icon={faArchive} | ||||||
|                     /> |                     /> | ||||||
|                     <InfoHeaderItem |                     <InfoHeaderItem | ||||||
|                         backColor='yellow' |                         backColor='yellow' | ||||||
|                         text={this.state.generalSettings.DBSize + ' MB'} |                         text={this.state.sizes.DBSize + ' MB'} | ||||||
|                         subtext='Database size' |                         subtext='Database size' | ||||||
|                         icon={faRulerVertical} |                         icon={faRulerVertical} | ||||||
|                     /> |                     /> | ||||||
|                     <InfoHeaderItem |                     <InfoHeaderItem | ||||||
|                         backColor='green' |                         backColor='green' | ||||||
|                         text={this.state.generalSettings.DifferentTags} |                         text={this.state.sizes.DifferentTags} | ||||||
|                         subtext='different Tags' |                         subtext='different Tags' | ||||||
|                         icon={faAddressCard} |                         icon={faAddressCard} | ||||||
|                     /> |                     /> | ||||||
|                     <InfoHeaderItem |                     <InfoHeaderItem | ||||||
|                         backColor='orange' |                         backColor='orange' | ||||||
|                         text={this.state.generalSettings.TagsAdded} |                         text={this.state.sizes.TagsAdded} | ||||||
|                         subtext='tags added' |                         subtext='tags added' | ||||||
|                         icon={faBalanceScaleLeft} |                         icon={faBalanceScaleLeft} | ||||||
|                     /> |                     /> | ||||||
| @@ -210,8 +213,16 @@ class GeneralSettings extends React.Component<Props, state> { | |||||||
|      * inital load of already specified settings from backend |      * inital load of already specified settings from backend | ||||||
|      */ |      */ | ||||||
|     loadSettings(): void { |     loadSettings(): void { | ||||||
|         callAPI(APINode.Settings, {action: 'loadGeneralSettings'}, (result: SettingsTypes.loadGeneralSettingsType) => { |         interface SettingsResponseType { | ||||||
|             this.setState({generalSettings: result}); |             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(); |         settings.DarkMode = GlobalInfos.isDarkTheme(); | ||||||
|  |  | ||||||
|  |         console.log(settings); | ||||||
|         callAPI( |         callAPI( | ||||||
|             APINode.Settings, |             APINode.Settings, | ||||||
|             { |             { | ||||||
|                 action: 'saveGeneralSettings', |                 action: 'saveGeneralSettings', | ||||||
|                 Settings: settings |                 ...settings | ||||||
|             }, |             }, | ||||||
|             (result: GeneralSuccess) => { |             (result: GeneralSuccess) => { | ||||||
|                 if (result.result) { |                 if (result.result) { | ||||||
|   | |||||||
| @@ -39,7 +39,7 @@ export namespace SettingsTypes { | |||||||
|         TVShowEnabled: boolean; |         TVShowEnabled: boolean; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     export interface loadGeneralSettingsType { |     export interface SettingsType { | ||||||
|         VideoPath: string; |         VideoPath: string; | ||||||
|         EpisodePath: string; |         EpisodePath: string; | ||||||
|         MediacenterName: string; |         MediacenterName: string; | ||||||
| @@ -47,7 +47,9 @@ export namespace SettingsTypes { | |||||||
|         PasswordEnabled: boolean; |         PasswordEnabled: boolean; | ||||||
|         TMDBGrabbing: boolean; |         TMDBGrabbing: boolean; | ||||||
|         DarkMode: boolean; |         DarkMode: boolean; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     export interface SizesType { | ||||||
|         VideoNr: number; |         VideoNr: number; | ||||||
|         DBSize: number; |         DBSize: number; | ||||||
|         DifferentTags: number; |         DifferentTags: number; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user