2021-02-23 16:01:29 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-09-16 20:38:28 +00:00
|
|
|
"openmediacenter/apiGo/api/api"
|
2021-02-23 16:01:29 +00:00
|
|
|
"openmediacenter/apiGo/api/types"
|
2021-09-09 21:33:04 +00:00
|
|
|
"openmediacenter/apiGo/config"
|
2021-02-23 16:01:29 +00:00
|
|
|
"openmediacenter/apiGo/database"
|
2021-04-16 19:12:56 +00:00
|
|
|
"openmediacenter/apiGo/database/settings"
|
2021-02-23 16:01:29 +00:00
|
|
|
"openmediacenter/apiGo/videoparser"
|
2021-04-16 19:12:56 +00:00
|
|
|
"regexp"
|
|
|
|
"strings"
|
2021-02-23 16:01:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func AddSettingsHandlers() {
|
|
|
|
saveSettingsToDB()
|
|
|
|
getSettingsFromDB()
|
|
|
|
reIndexHandling()
|
|
|
|
}
|
|
|
|
|
|
|
|
func getSettingsFromDB() {
|
2021-05-23 12:21:44 +00:00
|
|
|
/**
|
|
|
|
* @api {post} /api/settings [loadGeneralSettings]
|
|
|
|
* @apiDescription Get the settings object
|
|
|
|
* @apiName loadGeneralSettings
|
|
|
|
* @apiGroup Settings
|
|
|
|
*
|
|
|
|
* @apiSuccess {Object} Settings Settings object
|
|
|
|
* @apiSuccess {string} Settings.VideoPath webserver path to the videos
|
|
|
|
* @apiSuccess {string} Settings.EpisodePath webserver path to the tvshows
|
|
|
|
* @apiSuccess {string} Settings.MediacenterName overall name of the mediacenter
|
|
|
|
* @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?
|
2021-07-11 12:26:10 +00:00
|
|
|
* @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
|
2021-05-23 12:21:44 +00:00
|
|
|
*/
|
2021-09-16 20:38:28 +00:00
|
|
|
api.AddHandler("loadGeneralSettings", api.SettingsNode, api.PermUser, func(context api.Context) {
|
2021-07-11 12:26:10 +00:00
|
|
|
result, _, sizes := database.GetSettings()
|
|
|
|
|
|
|
|
var ret = struct {
|
|
|
|
Settings *types.SettingsType
|
|
|
|
Sizes *types.SettingsSizeType
|
|
|
|
}{
|
|
|
|
Settings: &result,
|
|
|
|
Sizes: &sizes,
|
|
|
|
}
|
2021-09-16 20:38:28 +00:00
|
|
|
context.Json(ret)
|
2021-02-23 16:01:29 +00:00
|
|
|
})
|
2021-05-22 19:33:32 +00:00
|
|
|
|
2021-05-23 12:21:44 +00:00
|
|
|
/**
|
|
|
|
* @api {post} /api/settings [loadInitialData]
|
|
|
|
* @apiDescription load startdata to display on homepage
|
|
|
|
* @apiName loadInitialData
|
|
|
|
* @apiGroup Settings
|
|
|
|
*
|
|
|
|
* @apiSuccess {string} VideoPath webserver path to the videos
|
|
|
|
* @apiSuccess {string} EpisodePath webserver path to the tvshows
|
|
|
|
* @apiSuccess {string} MediacenterName overall name of the mediacenter
|
|
|
|
* @apiSuccess {string} Pasword new server password (-1 if no password set)
|
|
|
|
* @apiSuccess {bool} DarkMode Darkmode enabled?
|
2021-06-08 19:55:54 +00:00
|
|
|
* @apiSuccess {bool} TVShowEnabled is are TVShows enabled
|
2021-05-23 12:21:44 +00:00
|
|
|
*/
|
2021-09-16 20:38:28 +00:00
|
|
|
api.AddHandler("loadInitialData", api.SettingsNode, api.PermUser, func(context api.Context) {
|
2021-04-16 19:12:56 +00:00
|
|
|
sett := settings.LoadSettings()
|
|
|
|
|
|
|
|
type InitialDataTypeResponse struct {
|
2021-09-03 10:09:51 +00:00
|
|
|
DarkMode bool
|
|
|
|
Pasword bool
|
|
|
|
MediacenterName string
|
|
|
|
VideoPath string
|
|
|
|
TVShowPath string
|
|
|
|
TVShowEnabled bool
|
|
|
|
FullDeleteEnabled bool
|
2021-04-16 19:12:56 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 20:44:56 +00:00
|
|
|
regexMatchUrl := regexp.MustCompile("^http(|s)://([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}:[0-9]{1,5}")
|
2021-04-16 19:12:56 +00:00
|
|
|
videoUrl := regexMatchUrl.FindString(sett.VideoPath)
|
2021-04-16 20:44:56 +00:00
|
|
|
tvshowurl := regexMatchUrl.FindString(sett.TVShowPath)
|
2021-04-16 19:12:56 +00:00
|
|
|
serverVideoPath := strings.TrimPrefix(sett.VideoPath, videoUrl)
|
2021-04-16 20:44:56 +00:00
|
|
|
serverTVShowPath := strings.TrimPrefix(sett.TVShowPath, tvshowurl)
|
2021-04-16 19:12:56 +00:00
|
|
|
|
|
|
|
res := InitialDataTypeResponse{
|
2021-09-03 10:09:51 +00:00
|
|
|
DarkMode: sett.DarkMode,
|
|
|
|
Pasword: sett.Pasword != "-1",
|
|
|
|
MediacenterName: sett.MediacenterName,
|
|
|
|
VideoPath: serverVideoPath,
|
|
|
|
TVShowPath: serverTVShowPath,
|
2021-09-09 21:33:04 +00:00
|
|
|
TVShowEnabled: !config.GetConfig().Features.DisableTVSupport,
|
|
|
|
FullDeleteEnabled: config.GetConfig().Features.FullyDeletableVideos,
|
2021-04-16 19:12:56 +00:00
|
|
|
}
|
|
|
|
|
2021-09-16 20:38:28 +00:00
|
|
|
context.Json(res)
|
2021-04-16 19:12:56 +00:00
|
|
|
})
|
2021-02-23 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func saveSettingsToDB() {
|
2021-05-23 12:21:44 +00:00
|
|
|
/**
|
|
|
|
* @api {post} /api/settings [saveGeneralSettings]
|
|
|
|
* @apiDescription Save the global settings provided
|
|
|
|
* @apiName saveGeneralSettings
|
|
|
|
* @apiGroup Settings
|
|
|
|
*
|
2021-07-11 12:26:10 +00:00
|
|
|
* @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?
|
2021-05-23 12:21:44 +00:00
|
|
|
*
|
2021-09-16 20:38:28 +00:00
|
|
|
* @apiSuccess {string} result 'success' if successfully or Error message if not
|
2021-05-23 12:21:44 +00:00
|
|
|
*/
|
2021-09-16 20:38:28 +00:00
|
|
|
api.AddHandler("saveGeneralSettings", api.SettingsNode, api.PermUser, func(context api.Context) {
|
2021-07-11 12:26:10 +00:00
|
|
|
var args types.SettingsType
|
2021-09-16 20:38:28 +00:00
|
|
|
err := api.DecodeRequest(context.GetRequest(), &args)
|
|
|
|
if err != nil {
|
|
|
|
context.Error("unable to decode arguments")
|
|
|
|
return
|
2021-05-22 19:33:32 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 16:01:29 +00:00
|
|
|
query := `
|
|
|
|
UPDATE settings SET
|
|
|
|
video_path=?,
|
|
|
|
episode_path=?,
|
|
|
|
password=?,
|
|
|
|
mediacenter_name=?,
|
|
|
|
TMDB_grabbing=?,
|
|
|
|
DarkMode=?
|
|
|
|
WHERE 1`
|
2021-09-16 20:38:28 +00:00
|
|
|
// todo avoid conversion
|
|
|
|
context.Text(string(database.SuccessQuery(query,
|
2021-07-11 12:26:10 +00:00
|
|
|
args.VideoPath, args.EpisodePath, args.Password,
|
2021-09-16 20:38:28 +00:00
|
|
|
args.MediacenterName, args.TMDBGrabbing, args.DarkMode)))
|
2021-02-23 16:01:29 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// methods for handling reindexing and cleanup of db gravity
|
|
|
|
func reIndexHandling() {
|
2021-05-23 12:21:44 +00:00
|
|
|
/**
|
|
|
|
* @api {post} /api/settings [startReindex]
|
|
|
|
* @apiDescription Start Database video reindex Job
|
|
|
|
* @apiName startReindex
|
|
|
|
* @apiGroup Settings
|
|
|
|
*
|
2021-09-16 20:38:28 +00:00
|
|
|
* @apiSuccess {string} result 'success' if successfully or Error message if not
|
2021-05-23 12:21:44 +00:00
|
|
|
*/
|
2021-09-16 20:38:28 +00:00
|
|
|
api.AddHandler("startReindex", api.SettingsNode, api.PermUser, func(context api.Context) {
|
2021-02-23 16:01:29 +00:00
|
|
|
videoparser.StartReindex()
|
2021-09-16 20:38:28 +00:00
|
|
|
context.Text(string(database.ManualSuccessResponse(nil)))
|
2021-02-23 16:01:29 +00:00
|
|
|
})
|
|
|
|
|
2021-05-23 12:21:44 +00:00
|
|
|
/**
|
|
|
|
* @api {post} /api/settings [startTVShowReindex]
|
|
|
|
* @apiDescription Start Database TVShow reindex job
|
|
|
|
* @apiName startTVShowReindex
|
|
|
|
* @apiGroup Settings
|
|
|
|
*
|
2021-09-16 20:38:28 +00:00
|
|
|
* @apiSuccess {string} result 'success' if successfully or Error message if not
|
2021-05-23 12:21:44 +00:00
|
|
|
*/
|
2021-09-16 20:38:28 +00:00
|
|
|
api.AddHandler("startTVShowReindex", api.SettingsNode, api.PermUser, func(context api.Context) {
|
2021-04-16 20:44:56 +00:00
|
|
|
videoparser.StartTVShowReindex()
|
2021-09-16 20:38:28 +00:00
|
|
|
context.Text(string(database.ManualSuccessResponse(nil)))
|
2021-04-16 20:44:56 +00:00
|
|
|
})
|
|
|
|
|
2021-05-23 12:21:44 +00:00
|
|
|
/**
|
|
|
|
* @api {post} /api/settings [cleanupGravity]
|
|
|
|
* @apiDescription Start Database cleanup job
|
|
|
|
* @apiName cleanupGravity
|
|
|
|
* @apiGroup Settings
|
|
|
|
*/
|
2021-09-16 20:38:28 +00:00
|
|
|
api.AddHandler("cleanupGravity", api.SettingsNode, api.PermUser, func(context api.Context) {
|
2021-02-23 16:01:29 +00:00
|
|
|
videoparser.StartCleanup()
|
|
|
|
})
|
|
|
|
}
|