diff --git a/app/http/endpoints/api/whitelabelgeterrors.go b/app/http/endpoints/api/whitelabelgeterrors.go new file mode 100644 index 0000000..29dc71c --- /dev/null +++ b/app/http/endpoints/api/whitelabelgeterrors.go @@ -0,0 +1,24 @@ +package api + +import ( + "github.com/TicketsBot/GoPanel/database" + "github.com/gin-gonic/gin" +) + +func WhitelabelGetErrors(ctx *gin.Context) { + userId := ctx.Keys["userid"].(uint64) + + errors, err := database.Client.WhitelabelErrors.GetRecent(userId, 10) + if err != nil { + ctx.JSON(500, gin.H{ + "success": false, + "error": err.Error(), + }) + return + } + + ctx.JSON(200, gin.H{ + "success": true, + "errors": errors, + }) +} diff --git a/app/http/server.go b/app/http/server.go index 5561f4a..2d0586e 100644 --- a/app/http/server.go +++ b/app/http/server.go @@ -114,6 +114,7 @@ func StartServer() { userGroup.GET("/guilds", api.GetGuilds) userGroup.GET("/whitelabel", api.WhitelabelGet) + userGroup.GET("/whitelabel/errors", api.WhitelabelGetErrors) userGroup.Group("/").Use(createLimiter(10, time.Minute)).POST("/whitelabel", api.WhitelabelPost) userGroup.Group("/").Use(createLimiter(1, time.Second * 5)).POST("/whitelabel/status", api.WhitelabelStatusPost) diff --git a/go.mod b/go.mod index 3648a34..1f677fa 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/TicketsBot/archiverclient v0.0.0-20200425115930-0ca198cc8306 github.com/TicketsBot/common v0.0.0-20200529141045-7426ad13f1a4 - github.com/TicketsBot/database v0.0.0-20200612175645-63696c6f8675 + github.com/TicketsBot/database v0.0.0-20200612180221-a26ff96874ea github.com/apex/log v1.1.2 github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible diff --git a/public/templates/views/whitelabel.tmpl b/public/templates/views/whitelabel.tmpl index 9df850c..0c49ee0 100644 --- a/public/templates/views/whitelabel.tmpl +++ b/public/templates/views/whitelabel.tmpl @@ -151,7 +151,7 @@ showToast('Success', 'Updated status successfully') } - async function loadDetails() { + async function loadStatus() { const res = await axios.get('/user/whitelabel'); if (res.status !== 200 || !res.data.success) { showToast('Error', res.data.error); @@ -160,6 +160,16 @@ // set status document.getElementById('status').value = res.data.status; + } + + loadStatus(); + + async function loadErrors() { + const res = await axios.get('/user/whitelabel/errors'); + if (res.status !== 200 || !res.data.success) { + showToast('Error', res.data.error); + return; + } // append errors for (error of res.data.errors) { @@ -169,6 +179,6 @@ } } - loadDetails(); + loadErrors(); {{end}} \ No newline at end of file