add missing apidoc, dont show sendrequest form on docpage
fix unit tests
This commit is contained in:
parent
31ad6ec1e5
commit
b59b6a17f4
@ -5,13 +5,13 @@ import (
|
||||
)
|
||||
|
||||
func cleanUp() {
|
||||
handlers = nil
|
||||
handlers = make(map[string]Handler)
|
||||
}
|
||||
|
||||
func TestAddHandler(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
AddHandler("test", ActorNode, nil, func() []byte {
|
||||
AddHandler("test", ActorNode, func(info *HandlerInfo) []byte {
|
||||
return nil
|
||||
})
|
||||
if len(handlers) != 1 {
|
||||
@ -23,13 +23,13 @@ func TestCallOfHandler(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
i := 0
|
||||
AddHandler("test", ActorNode, nil, func() []byte {
|
||||
AddHandler("test", ActorNode, func(info *HandlerInfo) []byte {
|
||||
i++
|
||||
return nil
|
||||
})
|
||||
|
||||
// simulate the call of the api
|
||||
handleAPICall("test", "", ActorNode)
|
||||
handleAPICall("test", "", ActorNode, nil)
|
||||
|
||||
if i != 1 {
|
||||
t.Errorf("Unexpected number of Lambda calls : %d/1", i)
|
||||
@ -39,26 +39,32 @@ func TestCallOfHandler(t *testing.T) {
|
||||
func TestDecodingOfArguments(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
var myvar struct {
|
||||
Test string
|
||||
TestInt int
|
||||
}
|
||||
AddHandler("test", ActorNode, &myvar, func() []byte {
|
||||
AddHandler("test", ActorNode, func(info *HandlerInfo) []byte {
|
||||
var args struct {
|
||||
Test string
|
||||
TestInt int
|
||||
}
|
||||
err := FillStruct(&args, info.Data)
|
||||
if err != nil {
|
||||
t.Errorf("Error parsing args: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
if args.TestInt != 42 || args.Test != "myString" {
|
||||
t.Errorf("Wrong parsing of argument parameters : %d/42 - %s/myString", args.TestInt, args.Test)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
// simulate the call of the api
|
||||
handleAPICall("test", `{"Test":"myString","TestInt":42}`, ActorNode)
|
||||
|
||||
if myvar.TestInt != 42 || myvar.Test != "myString" {
|
||||
t.Errorf("Wrong parsing of argument parameters : %d/42 - %s/myString", myvar.TestInt, myvar.Test)
|
||||
}
|
||||
handleAPICall("test", `{"Test":"myString","TestInt":42}`, ActorNode, nil)
|
||||
}
|
||||
|
||||
func TestNoHandlerCovers(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
ret := handleAPICall("test", "", ActorNode)
|
||||
ret := handleAPICall("test", "", ActorNode, nil)
|
||||
|
||||
if ret != nil {
|
||||
t.Error("Expect nil return within unhandled api action")
|
||||
|
@ -18,11 +18,42 @@ func AddSettingsHandlers() {
|
||||
}
|
||||
|
||||
func getSettingsFromDB() {
|
||||
/**
|
||||
* @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?
|
||||
* @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
|
||||
*/
|
||||
AddHandler("loadGeneralSettings", SettingsNode, func(info *HandlerInfo) []byte {
|
||||
result := database.GetSettings()
|
||||
return jsonify(result)
|
||||
})
|
||||
|
||||
/**
|
||||
* @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?
|
||||
*/
|
||||
AddHandler("loadInitialData", SettingsNode, func(info *HandlerInfo) []byte {
|
||||
sett := settings.LoadSettings()
|
||||
|
||||
@ -54,7 +85,24 @@ func getSettingsFromDB() {
|
||||
}
|
||||
|
||||
func saveSettingsToDB() {
|
||||
/**
|
||||
* @api {post} /api/settings [saveGeneralSettings]
|
||||
* @apiDescription Save the global settings provided
|
||||
* @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?
|
||||
*
|
||||
* @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
|
||||
}
|
||||
@ -80,16 +128,38 @@ func saveSettingsToDB() {
|
||||
|
||||
// methods for handling reindexing and cleanup of db gravity
|
||||
func reIndexHandling() {
|
||||
/**
|
||||
* @api {post} /api/settings [startReindex]
|
||||
* @apiDescription Start Database video reindex Job
|
||||
* @apiName startReindex
|
||||
* @apiGroup Settings
|
||||
*
|
||||
* @apiSuccess {string} result 'success' if successfully or error message if not
|
||||
*/
|
||||
AddHandler("startReindex", SettingsNode, func(info *HandlerInfo) []byte {
|
||||
videoparser.StartReindex()
|
||||
return database.ManualSuccessResponse(nil)
|
||||
})
|
||||
|
||||
/**
|
||||
* @api {post} /api/settings [startTVShowReindex]
|
||||
* @apiDescription Start Database TVShow reindex job
|
||||
* @apiName startTVShowReindex
|
||||
* @apiGroup Settings
|
||||
*
|
||||
* @apiSuccess {string} result 'success' if successfully or error message if not
|
||||
*/
|
||||
AddHandler("startTVShowReindex", SettingsNode, func(info *HandlerInfo) []byte {
|
||||
videoparser.StartTVShowReindex()
|
||||
return database.ManualSuccessResponse(nil)
|
||||
})
|
||||
|
||||
/**
|
||||
* @api {post} /api/settings [cleanupGravity]
|
||||
* @apiDescription Start Database cleanup job
|
||||
* @apiName cleanupGravity
|
||||
* @apiGroup Settings
|
||||
*/
|
||||
AddHandler("cleanupGravity", SettingsNode, func(info *HandlerInfo) []byte {
|
||||
videoparser.StartCleanup()
|
||||
return nil
|
||||
|
@ -6,12 +6,36 @@ import (
|
||||
)
|
||||
|
||||
func AddTvshowHandlers() {
|
||||
/**
|
||||
* @api {post} /api/tvshow [getTVShows]
|
||||
* @apiDescription get all available tv shows
|
||||
* @apiName getTVShows
|
||||
* @apiGroup TVshow
|
||||
*
|
||||
* @apiSuccess {Object[]} .
|
||||
* @apiSuccess {uint32} .Id tvshow id
|
||||
* @apiSuccess {string} .Name tvshow name
|
||||
*/
|
||||
AddHandler("getTVShows", TVShowNode, func(info *HandlerInfo) []byte {
|
||||
query := "SELECT id, name FROM tvshow"
|
||||
rows := database.Query(query)
|
||||
return jsonify(readTVshowsFromResultset(rows))
|
||||
})
|
||||
|
||||
/**
|
||||
* @api {post} /api/tvshow [getEpisodes]
|
||||
* @apiDescription get all Episodes of a TVShow
|
||||
* @apiName getEpisodes
|
||||
* @apiGroup TVshow
|
||||
*
|
||||
* @apiParam {uint32} ShowID id of tvshow to get episodes from
|
||||
*
|
||||
* @apiSuccess {Object[]} .
|
||||
* @apiSuccess {uint32} .ID episode id
|
||||
* @apiSuccess {string} .Name episode name
|
||||
* @apiSuccess {uint8} .Season Season number
|
||||
* @apiSuccess {uint8} .Episode Episode number
|
||||
*/
|
||||
AddHandler("getEpisodes", TVShowNode, func(info *HandlerInfo) []byte {
|
||||
var args struct {
|
||||
ShowID uint32
|
||||
@ -46,6 +70,20 @@ func AddTvshowHandlers() {
|
||||
return jsonify(episodes)
|
||||
})
|
||||
|
||||
/**
|
||||
* @api {post} /api/tvshow [loadEpisode]
|
||||
* @apiDescription load all info of episode
|
||||
* @apiName loadEpisode
|
||||
* @apiGroup TVshow
|
||||
*
|
||||
* @apiParam {uint32} ID id of episode
|
||||
*
|
||||
* @apiSuccess {uint32} TVShowID episode id
|
||||
* @apiSuccess {string} Name episode name
|
||||
* @apiSuccess {uint8} Season Season number
|
||||
* @apiSuccess {uint8} Episode Episode number
|
||||
* @apiSuccess {string} Path webserver path of video file
|
||||
*/
|
||||
AddHandler("loadEpisode", TVShowNode, func(info *HandlerInfo) []byte {
|
||||
var args struct {
|
||||
ID uint32
|
||||
@ -83,6 +121,16 @@ WHERE tvshow_episodes.id=%d`, args.ID)
|
||||
return jsonify(ret)
|
||||
})
|
||||
|
||||
/**
|
||||
* @api {post} /api/tvshow [readThumbnail]
|
||||
* @apiDescription Load Thubnail of specific episode
|
||||
* @apiName readThumbnail
|
||||
* @apiGroup TVshow
|
||||
*
|
||||
* @apiParam {int} Id id of episode to load thumbnail
|
||||
*
|
||||
* @apiSuccess {string} . Base64 encoded Thubnail
|
||||
*/
|
||||
AddHandler("readThumbnail", TVShowNode, func(info *HandlerInfo) []byte {
|
||||
var args struct {
|
||||
Id int
|
||||
|
@ -13,6 +13,17 @@ func AddTagHandlers() {
|
||||
}
|
||||
|
||||
func deleteFromDB() {
|
||||
/**
|
||||
* @api {post} /api/tags [deleteTag]
|
||||
* @apiDescription Start Database video reindex Job
|
||||
* @apiName deleteTag
|
||||
* @apiGroup Tags
|
||||
*
|
||||
* @apiParam {bool} [Force] force delete tag with its constraints
|
||||
* @apiParam {int} TagId id of tag to delete
|
||||
*
|
||||
* @apiSuccess {string} result 'success' if successfully or error message if not
|
||||
*/
|
||||
AddHandler("deleteTag", TagNode, func(info *HandlerInfo) []byte {
|
||||
var args struct {
|
||||
TagId int
|
||||
@ -44,7 +55,7 @@ func deleteFromDB() {
|
||||
// check with regex if its the key constraint error
|
||||
r := regexp.MustCompile("^.*a foreign key constraint fails.*$")
|
||||
if r.MatchString(err.Error()) {
|
||||
return []byte(`{"result":"not empty tag"}`)
|
||||
return database.ManualSuccessResponse(fmt.Errorf("not empty tag"))
|
||||
} else {
|
||||
return database.ManualSuccessResponse(err)
|
||||
}
|
||||
@ -53,6 +64,16 @@ func deleteFromDB() {
|
||||
}
|
||||
|
||||
func getFromDB() {
|
||||
/**
|
||||
* @api {post} /api/tags [getAllTags]
|
||||
* @apiDescription get all available Tags
|
||||
* @apiName getAllTags
|
||||
* @apiGroup Tags
|
||||
*
|
||||
* @apiSuccess {Object[]} array of tag objects
|
||||
* @apiSuccess {uint32} TagId
|
||||
* @apiSuccess {string} TagName name of the Tag
|
||||
*/
|
||||
AddHandler("getAllTags", TagNode, func(info *HandlerInfo) []byte {
|
||||
query := "SELECT tag_id,tag_name from tags"
|
||||
return jsonify(readTagsFromResultset(database.Query(query)))
|
||||
@ -60,6 +81,16 @@ func getFromDB() {
|
||||
}
|
||||
|
||||
func addToDB() {
|
||||
/**
|
||||
* @api {post} /api/tags [createTag]
|
||||
* @apiDescription create a new tag
|
||||
* @apiName createTag
|
||||
* @apiGroup Tags
|
||||
*
|
||||
* @apiParam {string} TagName name of the tag
|
||||
*
|
||||
* @apiSuccess {string} result 'success' if successfully or error message if not
|
||||
*/
|
||||
AddHandler("createTag", TagNode, func(info *HandlerInfo) []byte {
|
||||
var args struct {
|
||||
TagName string
|
||||
@ -73,6 +104,17 @@ func addToDB() {
|
||||
return database.SuccessQuery(query, args.TagName)
|
||||
})
|
||||
|
||||
/**
|
||||
* @api {post} /api/tags [addTag]
|
||||
* @apiDescription Add new tag to video
|
||||
* @apiName addTag
|
||||
* @apiGroup Tags
|
||||
*
|
||||
* @apiParam {int} TagId Tag id to add to video
|
||||
* @apiParam {int} MovieId Video Id of video to add tag to
|
||||
*
|
||||
* @apiSuccess {string} result 'success' if successfully or error message if not
|
||||
*/
|
||||
AddHandler("addTag", TagNode, func(info *HandlerInfo) []byte {
|
||||
var args struct {
|
||||
MovieId int
|
||||
|
@ -79,5 +79,11 @@
|
||||
"prettier-config": "^1.0.0",
|
||||
"react-scripts": "4.0.3",
|
||||
"apidoc": "^0.28.1"
|
||||
},
|
||||
"apidoc":{
|
||||
"name": "OpenMediaCenter",
|
||||
"description": "API Documentation of OpenMediaCenter",
|
||||
"title": "OpenMediaCenter Doc",
|
||||
"sampleUrl": null
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user