feat: improved visibility of dataset and improved speed for expand import zip file
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
dbtypes "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/goccy/go-json"
|
||||
)
|
||||
|
||||
@@ -43,6 +44,7 @@ type Handle struct {
|
||||
posts []HandleFunc
|
||||
deletes []HandleFunc
|
||||
Config Config
|
||||
validate *validator.Validate
|
||||
}
|
||||
|
||||
func decodeBody(r *http.Request) (string, *Error) {
|
||||
@@ -79,6 +81,17 @@ func (x *Handle) Post(path string, fn func(c *Context) *Error) {
|
||||
x.posts = append(x.posts, HandleFunc{path, fn})
|
||||
}
|
||||
|
||||
|
||||
func (x *Handle) PostAuth(path string, authLevel int, fn func(c *Context) *Error) {
|
||||
inner_fn := func(c *Context) *Error {
|
||||
if !c.CheckAuthLevel(authLevel) {
|
||||
return nil
|
||||
}
|
||||
return fn(c)
|
||||
}
|
||||
x.posts = append(x.posts, HandleFunc{path, inner_fn})
|
||||
}
|
||||
|
||||
func (x *Handle) Delete(path string, fn func(c *Context) *Error) {
|
||||
x.deletes = append(x.deletes, HandleFunc{path, fn})
|
||||
}
|
||||
@@ -195,6 +208,12 @@ func (c Context) ToJSON(dat any) *Error {
|
||||
return c.Error500(err)
|
||||
}
|
||||
|
||||
err = c.Handle.validate.Struct(dat)
|
||||
if err != nil {
|
||||
c.Logger.Error("Failed invalid json passed", "dat", dat, "err", err)
|
||||
return c.JsonBadRequest("Bad Request! Invalid body passed!")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -476,7 +495,8 @@ func NewHandler(db *sql.DB, config Config) *Handle {
|
||||
var gets []HandleFunc
|
||||
var posts []HandleFunc
|
||||
var deletes []HandleFunc
|
||||
x := &Handle{db, gets, posts, deletes, config}
|
||||
validate := validator.New()
|
||||
x := &Handle{db, gets, posts, deletes, config, validate}
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user