diff options
-rw-r--r-- | activitypub/activity.go | 17 | ||||
-rw-r--r-- | db/database.go | 11 | ||||
-rw-r--r-- | post/util.go | 2 | ||||
-rw-r--r-- | routes/actor.go | 24 |
4 files changed, 22 insertions, 32 deletions
diff --git a/activitypub/activity.go b/activitypub/activity.go index aef060b..22c9f06 100644 --- a/activitypub/activity.go +++ b/activitypub/activity.go @@ -243,26 +243,23 @@ func HasContextFromJson(context []byte) (bool, error) { } func IsActivityLocal(activity Activity) (bool, error) { + for _, e := range activity.To { - if res, err := GetActorFromDB(e); err == nil && res.Id != "" { + if res, _ := GetActorFromDB(e); res.Id != "" { return true, nil - } else if err != nil { - return false, err } } for _, e := range activity.Cc { - if res, err := GetActorFromDB(e); err == nil && res.Id != "" { + if res, _ := GetActorFromDB(e); res.Id != "" { return true, nil - } else if err != nil { - return false, err } } - if res, err := GetActorFromDB(activity.Actor.Id); err == nil && activity.Actor != nil && res.Id != "" { - return true, nil - } else if err != nil { - return false, err + if activity.Actor != nil { + if res, _ := GetActorFromDB(activity.Actor.Id); res.Id != "" { + return true, nil + } } return false, nil diff --git a/db/database.go b/db/database.go index 1ceac40..fcdb5f9 100644 --- a/db/database.go +++ b/db/database.go @@ -591,14 +591,7 @@ func IsHashBanned(hash string) (bool, error) { query := `select hash from bannedmedia where hash=$1` - rows, err := config.DB.Query(query, hash) - if err != nil { - return true, err - } - defer rows.Close() - - rows.Next() - err = rows.Scan(&h) + _ = config.DB.QueryRow(query, hash).Scan(&h) - return h == hash, err + return h == hash, nil } diff --git a/post/util.go b/post/util.go index cead842..0b87d42 100644 --- a/post/util.go +++ b/post/util.go @@ -155,7 +155,7 @@ func IsMediaBanned(f multipart.File) (bool, error) { hash := util.HashBytes(fileBytes) - // f.Seek(0, 0) + f.Seek(0, 0) return db.IsHashBanned(hash) } diff --git a/routes/actor.go b/routes/actor.go index 6e5955e..7b57309 100644 --- a/routes/actor.go +++ b/routes/actor.go @@ -42,18 +42,19 @@ func ActorOutbox(ctx *fiber.Ctx) error { valid, err := post.CheckCaptcha(ctx.FormValue("captcha")) if err == nil && hasCaptcha && valid { header, _ := ctx.FormFile("file") - if header != nil { f, _ := header.Open() defer f.Close() if header.Size > (7 << 20) { - return ctx.Render("403", fiber.Map{ - "message": "7MB max file size", - }) - } else if res, err := post.IsMediaBanned(f); err == nil && res { + ctx.Response().Header.SetStatusCode(403) + _, err := ctx.Write([]byte("7MB max file size")) + return err + } else if isBanned, err := post.IsMediaBanned(f); err == nil && isBanned { //Todo add logging fmt.Println("media banned") - return ctx.Redirect("/", 301) + ctx.Response().Header.SetStatusCode(403) + _, err := ctx.Write([]byte("media banned")) + return err } else if err != nil { return err } @@ -61,9 +62,9 @@ func ActorOutbox(ctx *fiber.Ctx) error { contentType, _ := util.GetFileContentType(f) if !post.SupportedMIMEType(contentType) { - return ctx.Render("403", fiber.Map{ - "message": "file type not supported", - }) + ctx.Response().Header.SetStatusCode(403) + _, err := ctx.Write([]byte("file type not supported")) + return err } } @@ -381,11 +382,10 @@ func ActorPost(ctx *fiber.Ctx) error { } defer resp.Body.Close() + body, _ := ioutil.ReadAll(resp.Body) if resp.StatusCode == 200 { - body, _ := ioutil.ReadAll(resp.Body) - var obj activitypub.ObjectBase obj = post.ParseOptions(ctx, obj) @@ -404,7 +404,7 @@ func ActorPost(ctx *fiber.Ctx) error { if resp.StatusCode == 403 { return ctx.Render("403", fiber.Map{ - "message": "Incorrect Captcha", + "message": string(body), }) } |