mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-15 19:49:53 +01:00
prime fun + user stash
This commit is contained in:
55
ober.go
55
ober.go
@@ -28,6 +28,7 @@ func RunWebserv() {
|
||||
r.GET("/api/chat/{id}", Headers(ChatGet))
|
||||
r.GET("/api/log", Headers(LogGet))
|
||||
r.GET("/api/user/{user?}", Headers(UserGet))
|
||||
r.GET("/api/userdata/{user}/{data}", Headers(UserStashGet))
|
||||
r.GET("/api/watch/{user?}", Headers(WatchGet))
|
||||
r.GET("/api/watchext/{user?}", Headers(WatchExtendedGet))
|
||||
r.POST("/api/appointment/{user}", Headers(AppointmentPost))
|
||||
@@ -35,6 +36,7 @@ func RunWebserv() {
|
||||
r.POST("/api/register", Headers(Register))
|
||||
r.POST("/api/watch/{user}", Headers(WatchPost))
|
||||
r.PATCH("/api/register", Headers(RegisterUpdate))
|
||||
r.PUT("/api/userdata/{user}/{data}", Headers(UserStashPut))
|
||||
r.DELETE("/api/appointment/{user}", Headers(AppointmentDelete))
|
||||
r.DELETE("/api/register", Headers(UnRegister))
|
||||
r.DELETE("/api/watch/{user}", Headers(WatchDelete))
|
||||
@@ -327,6 +329,10 @@ func UserGet(ctx *fasthttp.RequestCtx) {
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
func UserStashGet(ctx *fasthttp.RequestCtx) {
|
||||
processUserStashReq(ctx, false)
|
||||
}
|
||||
|
||||
func WatchGet(ctx *fasthttp.RequestCtx) {
|
||||
animeUsers, err := watchGetLogic(ctx)
|
||||
if err != nil {
|
||||
@@ -585,6 +591,10 @@ func WatchPost(ctx *fasthttp.RequestCtx) {
|
||||
processUpdateReq(ctx, true)
|
||||
}
|
||||
|
||||
func UserStashPut(ctx *fasthttp.RequestCtx) {
|
||||
processUserStashReq(ctx, true)
|
||||
}
|
||||
|
||||
func AppointmentDelete(ctx *fasthttp.RequestCtx) {
|
||||
processUpdateAppointmentReq(ctx, false)
|
||||
}
|
||||
@@ -875,6 +885,51 @@ func processUpdateAppointmentReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
}
|
||||
|
||||
func processUserStashReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
|
||||
dataPath := fmt.Sprintf("%s", ctx.UserValue("data"))
|
||||
if auth == nil || string(auth) == "" || dataPath == "" {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
username := fmt.Sprintf("%s", ctx.UserValue("user"))
|
||||
legit, _ := GheddoAuth(username, string(auth))
|
||||
if !legit {
|
||||
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if update {
|
||||
compressed, err := CompressZstd(ctx.PostBody())
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
err = DbSave(bucketStash, fmt.Sprintf("%s.%s", username, dataPath), compressed)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetStatusCode(fasthttp.StatusAccepted)
|
||||
} else {
|
||||
compressed, err := DbRead(bucketStash, []byte(fmt.Sprintf("%s.%s", username, dataPath)))
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
decompressed, err := DecompressZstd(compressed)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetBody(decompressed)
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func writeResponseBody(ctx *fasthttp.RequestCtx, bytes []byte) error {
|
||||
_, err := ctx.Write(bytes)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user