Skip to content

Commit

Permalink
API fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aunefyren committed Nov 13, 2023
1 parent 76adf38 commit 1e09a8d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 65 deletions.
2 changes: 1 addition & 1 deletion files/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion modules/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
41 changes: 17 additions & 24 deletions routes/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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{},
}

Expand Down
10 changes: 2 additions & 8 deletions routes/both.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -319,6 +313,6 @@ func ApiWrapperGetStatistics(context *gin.Context) {
return
}

context.JSON(http.StatusBadRequest, wrapperrReply)
context.JSON(http.StatusOK, wrapperrReply)
return
}
30 changes: 4 additions & 26 deletions routes/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
9 changes: 4 additions & 5 deletions web/js/get_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
}
};
Expand Down

0 comments on commit 1e09a8d

Please sign in to comment.