Maintenance

This commit is contained in:
daru
2022-04-15 20:34:59 +02:00
parent be195bed30
commit c59d1ba68b
3 changed files with 37 additions and 5 deletions

21
ober.go
View File

@@ -19,8 +19,7 @@ func RunWebserv() {
r.GET("/api/watch/{user?}", WatchGet)
r.POST("/api/register", Register)
r.POST("/api/watch/{user}", WatchPost)
r.PATCH("/api/watch/{user}", Start)
r.DELETE("/api/watch/{user}", Start)
r.DELETE("/api/watch/{user}", WatchDelete)
log.Fatal(fasthttp.ListenAndServe(":"+strconv.Itoa(*webServerPort), r.Handler))
}
@@ -197,6 +196,7 @@ func WatchPost(ctx *fasthttp.RequestCtx) {
return
}
anime.Users = animeData.Users
fmt.Printf("%+v\n", anime)
}
// TODO
@@ -221,6 +221,23 @@ func WatchPost(ctx *fasthttp.RequestCtx) {
}
}
func WatchDelete(ctx *fasthttp.RequestCtx) {
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
if ctx.UserValue("user") == nil || auth == nil || string(auth) == "" || string(ctx.Request.Header.ContentType()) != "application/json" {
ctx.SetStatusCode(fasthttp.StatusBadRequest)
return
}
username := fmt.Sprintf("%s", ctx.UserValue("user"))
legit, userId := GheddoAuth(username, string(auth))
if !legit {
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
return
}
// TODO
fmt.Printf("%+v\n", userId)
}
func GheddoAuth(username, auth string) (bool, int64) {
user, err := ReadUser(username)
if err != nil {