diff --git a/files/config.go b/files/config.go index 980d255..da5893c 100644 --- a/files/config.go +++ b/files/config.go @@ -11,7 +11,7 @@ import ( "github.com/google/uuid" ) -const wrapperr_version_parameter = "v3.2.0" +const wrapperr_version_parameter = "v3.2.1" const minSecretKeySize = 32 var config_path, _ = filepath.Abs("./config/config.json") diff --git a/modules/statistics.go b/modules/statistics.go index 3cde91d..c199040 100644 --- a/modules/statistics.go +++ b/modules/statistics.go @@ -16,7 +16,10 @@ import ( func GetWrapperStatistics(user_name string, user_friendlyname string, user_id int, user_email string, config models.WrapperrConfig, adminConfig models.AdminConfig, cachingMode bool, cacheLimit int) (wrapperrReply models.WrapperrStatisticsReply, cachingComplete *bool, err error) { log.Println("Getting stats for: " + user_name + " " + user_friendlyname + " " + strconv.Itoa(user_id) + " " + user_email) - wrapperrReply = models.WrapperrStatisticsReply{} + wrapperrReply = models.WrapperrStatisticsReply{ + Message: "Statistics retrieved.", + Error: false, + } err = nil cachingComplete = nil diff --git a/routes/admin.go b/routes/admin.go index 3bec2aa..9ac0bfb 100644 --- a/routes/admin.go +++ b/routes/admin.go @@ -36,22 +36,15 @@ func ApiGetConfig(context *gin.Context) { payload, httpStatus, err := middlewares.AuthGetPayloadFromAuthorization(authorizationHeader, config, adminConfig) if err != nil { log.Println("Failed to get payload from Authorization token. Error: " + err.Error()) - context.JSON(httpStatus, gin.H{"error": err.Error()}) + context.JSON(httpStatus, gin.H{"error": "Failed to get payload from Authorization token."}) context.Abort() return } - configReply := models.ConfigReply{ - Data: config, - Message: "Retrieved Wrapperr config.", - Error: false, - Username: payload.Username, - } - ipString := utilities.GetOriginIPString(context) log.Println("Retrieved Wrapperr configuration." + ipString) - context.JSON(http.StatusOK, configReply) + context.JSON(http.StatusOK, gin.H{"data": config, "message": "Retrieved Wrapperr config.", "username": payload.Username}) return } @@ -260,15 +253,8 @@ func ApiGetLog(context *gin.Context) { return } - logLinesReturn := models.WrapperrLogLineReply{ - Message: "Log lines retrieved", - Error: false, - Data: logLines, - Limit: files.GetMaxLogLinesReturned(), - } - log.Println("Log lines retrieved for admin.") - context.JSON(http.StatusOK, logLinesReturn) + context.JSON(http.StatusOK, gin.H{"message": "Log lines retrieved", "data": logLines, "limit": files.GetMaxLogLinesReturned()}) return } @@ -362,13 +348,7 @@ func ApiWrapperCacheStatistics(context *gin.Context) { return } - booleanReply := models.BooleanReply{ - Message: "Completed caching request.", - Error: false, - Data: *cachingComplete, - } - - context.JSON(http.StatusBadRequest, booleanReply) + context.JSON(http.StatusBadRequest, gin.H{"message": "Completed caching request.", "error": false, "data": *cachingComplete}) return } @@ -464,11 +444,24 @@ func ApiSyncTautulliUsers(context *gin.Context) { for _, user := range users { wrapperrUser, err := modules.UsersGetUser(user.UserID) if err != nil { + var Active = false + if user.IsActive == 1 { + Active = true + } else if user.IsActive == 0 { + Active = false + } else { + log.Println("Failed to convert integer to bool. Error: " + err.Error()) + context.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to convert integer to bool."}) + context.Abort() + return + } + wrapperrUser = models.WrapperrUser{ FriendlyName: user.FriendlyName, User: user.Username, UserID: user.UserID, Email: user.Email, + Active: Active, Wrappings: []models.WrapperrHistoryEntry{}, } diff --git a/routes/both.go b/routes/both.go index ab3423d..944ae0c 100644 --- a/routes/both.go +++ b/routes/both.go @@ -119,16 +119,10 @@ func ApiCreateShareLink(context *gin.Context) { return } - stringReply := models.StringReply{ - Message: "Saved Wrapperr link.", - Error: false, - Data: strconv.Itoa(user_id) + "-" + hash_value, - } - ipString := utilities.GetOriginIPString(context) log.Println("Saved new Wrapperr share link for " + user_name + " (" + strconv.Itoa(user_id) + ")." + ipString) - context.JSON(http.StatusCreated, stringReply) + context.JSON(http.StatusCreated, gin.H{"message": "Saved Wrapperr link.", "error": false, "data": strconv.Itoa(user_id) + "-" + hash_value}) return } @@ -319,6 +313,6 @@ func ApiWrapperGetStatistics(context *gin.Context) { return } - context.JSON(http.StatusBadRequest, wrapperrReply) + context.JSON(http.StatusOK, wrapperrReply) return } diff --git a/routes/open.go b/routes/open.go index b5b3341..9c5edbe 100644 --- a/routes/open.go +++ b/routes/open.go @@ -22,10 +22,6 @@ func ApiGetWrapperrVersion(context *gin.Context) { context.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to retrieve configuration state."}) context.Abort() return - } else if !configBool { - context.JSON(http.StatusBadRequest, gin.H{"error": "Wrapperr is not configured."}) - context.Abort() - return } config, err := files.GetConfig() @@ -68,16 +64,10 @@ func ApiGetAdminState(context *gin.Context) { return } - booleanReply := models.BooleanReply{ - Message: "Retrieved Wrapperr version.", - Error: false, - Data: admin, - } - ipString := utilities.GetOriginIPString(context) log.Println("Retrieved Wrapperr admin state." + ipString) - context.JSON(http.StatusOK, booleanReply) + context.JSON(http.StatusOK, gin.H{"message": "Retrieved Wrapperr version.", "error": false, "data": admin}) return } @@ -101,7 +91,7 @@ func ApiGetFunctions(context *gin.Context) { ipString := utilities.GetOriginIPString(context) log.Println("Retrieved Wrapperr functions." + ipString) - context.JSON(http.StatusOK, functionReply) + context.JSON(http.StatusOK, gin.H{"message": "Functions retrieved.", "data": functionReply}) return } @@ -179,16 +169,10 @@ func ApiWrapperrConfigured(context *gin.Context) { context.Abort() return } else { - booleanReply := models.BooleanReply{ - Message: "Retrieved Wrapperr configuration state.", - Error: false, - Data: configBool, - } - ipString := utilities.GetOriginIPString(context) log.Println("Retrieved Wrapperr configuration state." + ipString) - context.JSON(http.StatusOK, booleanReply) + context.JSON(http.StatusOK, gin.H{"message": "Retrieved Wrapperr configuration state.", "error": false, "data": configBool}) return } } @@ -269,16 +253,10 @@ func ApiLogInAdmin(context *gin.Context) { return } - stringReply := models.StringReply{ - Message: "Login cookie created", - Error: false, - Data: token, - } - ipString := utilities.GetOriginIPString(context) log.Println("Created and retrieved admin login JWT Token." + ipString) - context.JSON(http.StatusOK, stringReply) + context.JSON(http.StatusOK, gin.H{"message": "Login cookie created.", "error": false, "data": token}) return } } diff --git a/web/js/get_functions.js b/web/js/get_functions.js index cd3ca48..a7ba9d9 100644 --- a/web/js/get_functions.js +++ b/web/js/get_functions.js @@ -15,12 +15,11 @@ function get_functions() { document.getElementById("plex_signout_button").style.opacity = '1'; document.getElementById('results_error').innerHTML = result.error; } else { - functions = result.wrapperr_customize; - functions.plex_auth = result.plex_auth - functions.create_share_links = result.create_share_links - functions.wrapperr_version = result.wrapperr_version + functions = result.data.wrapperr_customize; + functions.plex_auth = result.data.plex_auth + functions.create_share_links = result.data.create_share_links + functions.wrapperr_version = result.data.wrapperr_version get_stats(); - } } };