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

15
nuss.go
View File

@@ -37,7 +37,7 @@ func AddUserToAnime(username string, userId, animeId int64) (*Anime, error) {
e, err := tx.Get(bucketAnime, keyBytes)
var users []WatchUser
if err != nil {
users = make([]WatchUser, 1)
users = make([]WatchUser, 0)
} else {
// parse user list
users, err = parseUserList(e.Value)
@@ -45,6 +45,17 @@ func AddUserToAnime(username string, userId, animeId int64) (*Anime, error) {
return err
}
}
// check if user already part
for _, u := range users {
if u.MalID == userId {
// early terminate
anime = Anime{
Anime: animeId,
Users: users,
}
return err
}
}
// add user
users = append(users, WatchUser{
@@ -72,7 +83,7 @@ func ReadAnimes() ([]Anime, error) {
if err != nil {
return err
}
animes = make([]Anime, len(entries))
animes = make([]Anime, 0)
// iterate entries
for _, e := range entries {
// decode anime list

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 {

View File

@@ -18,8 +18,12 @@ func Arbeiten() {
color.Errorln(err.Error())
}
}
}
}
err = DbClean()
func LangeArbeiten() {
for range time.Tick(time.Hour * 24) {
err := DbClean()
if err != nil {
color.Errorln(err.Error())
}