mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 17:29:54 +01:00
DELETE watching
This commit is contained in:
67
ober.go
67
ober.go
@@ -163,6 +163,14 @@ func Register(ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
|
||||
func WatchPost(ctx *fasthttp.RequestCtx) {
|
||||
processUpdateReq(ctx, true)
|
||||
}
|
||||
|
||||
func WatchDelete(ctx *fasthttp.RequestCtx) {
|
||||
processUpdateReq(ctx, false)
|
||||
}
|
||||
|
||||
func processUpdateReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
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)
|
||||
@@ -188,53 +196,42 @@ func WatchPost(ctx *fasthttp.RequestCtx) {
|
||||
for i, anime := range animes {
|
||||
// check if anime is in season
|
||||
_, err = SearchSeason(anime.Anime)
|
||||
if err == nil {
|
||||
// anime exitsts => save
|
||||
animeData, err := AddUserToAnime(username, userId, anime.Anime)
|
||||
if err != nil {
|
||||
// anime not in season => holen sie diese
|
||||
_, _, err := GetAnimeDetailData(anime.Anime)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
ctx.WriteString(err.Error())
|
||||
ctx.SetStatusCode(fasthttp.StatusNotFound)
|
||||
return
|
||||
}
|
||||
animes[i].Users = animeData.Users
|
||||
}
|
||||
|
||||
// TODO
|
||||
detail, _, err := GetAnimeDetailData(anime.Anime)
|
||||
if err != nil {
|
||||
ctx.WriteString(err.Error())
|
||||
ctx.SetStatusCode(fasthttp.StatusNotFound)
|
||||
return
|
||||
var animeData *Anime
|
||||
// update or delete request
|
||||
if update {
|
||||
// anime exitsts => save
|
||||
animeData, err = AddUserToAnime(username, userId, anime.Anime)
|
||||
} else {
|
||||
// anime exitsts => delete
|
||||
animeData, err = DeleteUserFromAnime(username, userId, anime.Anime)
|
||||
}
|
||||
fmt.Printf("%+v\n", detail)
|
||||
|
||||
data, err := json.Marshal(animes)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
err = writeResponseBody(ctx, data)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
animes[i].Users = animeData.Users
|
||||
}
|
||||
|
||||
// TODO
|
||||
fmt.Printf("%+v\n", userId)
|
||||
data, err := json.Marshal(animes)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
err = writeResponseBody(ctx, data)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func GheddoAuth(username, auth string) (bool, int64) {
|
||||
|
||||
Reference in New Issue
Block a user