aboutsummaryrefslogtreecommitdiff
path: root/routes/actor.go
diff options
context:
space:
mode:
authorFChannel <>2022-05-03 22:42:24 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit493fc8e025fd613d9faf0b573d610e4a0e0c0228 (patch)
treefd7f217ca407c1aa8e584db26d0a95944c23b034 /routes/actor.go
parent328c9150228156c04d1045469c7dbcd7b5f4fedf (diff)
creating boards works
Diffstat (limited to 'routes/actor.go')
-rw-r--r--routes/actor.go203
1 files changed, 1 insertions, 202 deletions
diff --git a/routes/actor.go b/routes/actor.go
index d564850..5cd0fa9 100644
--- a/routes/actor.go
+++ b/routes/actor.go
@@ -35,13 +35,11 @@ func ActorInbox(ctx *fiber.Ctx) error {
if !db.VerifyHeaderSignature(ctx, *activity.Actor) {
response := activitypub.RejectActivity(activity)
-
return db.MakeActivityRequest(response)
}
switch activity.Type {
case "Create":
-
for _, e := range activity.To {
if res, err := activitypub.IsActorLocal(e); err == nil && res {
if res, err := activitypub.IsActorLocal(activity.Actor.Id); err == nil && res {
@@ -171,7 +169,6 @@ func ActorInbox(ctx *fiber.Ctx) error {
} else {
fmt.Println("follow request for rejected")
response := activitypub.RejectActivity(activity)
-
return db.MakeActivityRequest(response)
}
}
@@ -202,205 +199,7 @@ func ActorOutbox(ctx *fiber.Ctx) error {
return nil
}
- contentType := util.GetContentType(ctx.Get("content-type"))
-
- if contentType == "multipart/form-data" || contentType == "application/x-www-form-urlencoded" {
- hasCaptcha, err := db.BoardHasAuthType(actor.Name, "captcha")
- if err != nil {
- return err
- }
-
- 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) {
- 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")
- ctx.Response().Header.SetStatusCode(403)
- _, err := ctx.Write([]byte("media banned"))
- return err
- } else if err != nil {
- return err
- }
-
- contentType, _ := util.GetFileContentType(f)
-
- if !post.SupportedMIMEType(contentType) {
- ctx.Response().Header.SetStatusCode(403)
- _, err := ctx.Write([]byte("file type not supported"))
- return err
- }
- }
-
- var nObj = activitypub.CreateObject("Note")
- nObj, err := post.ObjectFromForm(ctx, nObj)
- if err != nil {
- return err
- }
-
- nObj.Actor = config.Domain + "/" + actor.Name
-
- nObj, err = activitypub.WriteObjectToDB(nObj)
- if err != nil {
- return err
- }
-
- if len(nObj.To) == 0 {
- if err := db.ArchivePosts(actor); err != nil {
- return err
- }
- }
-
- activity, err := webfinger.CreateActivity("Create", nObj)
- if err != nil {
- return err
- }
-
- activity, err = webfinger.AddFollowersToActivity(activity)
- if err != nil {
- return err
- }
-
- go db.MakeActivityRequest(activity)
-
- var id string
- op := len(nObj.InReplyTo) - 1
- if op >= 0 {
- if nObj.InReplyTo[op].Id == "" {
- id = nObj.Id
- } else {
- id = nObj.InReplyTo[0].Id + "|" + nObj.Id
- }
- }
-
- ctx.Response().Header.Set("Status", "200")
- _, err = ctx.Write([]byte(id))
- return err
- }
-
- ctx.Response().Header.Set("Status", "403")
- _, err = ctx.Write([]byte("captcha could not auth"))
- return err
- } else { // json request
- activity, err := activitypub.GetActivityFromJson(ctx)
- if err != nil {
- return err
- }
-
- if res, err := activitypub.IsActivityLocal(activity); err == nil && res {
- if res := db.VerifyHeaderSignature(ctx, *activity.Actor); err == nil && !res {
- ctx.Response().Header.Set("Status", "403")
- _, err = ctx.Write([]byte(""))
- return err
- }
-
- switch activity.Type {
- case "Create":
- ctx.Response().Header.Set("Status", "403")
- _, err = ctx.Write([]byte(""))
- break
-
- case "Follow":
- var validActor bool
- var validLocalActor bool
-
- validActor = (activity.Object.Actor != "")
- validLocalActor = (activity.Actor.Id == actor.Id)
-
- var rActivity activitypub.Activity
- if validActor && validLocalActor {
- rActivity = db.AcceptFollow(activity)
- rActivity, err = db.SetActorFollowingDB(rActivity)
- if err != nil {
- return err
- }
- if err := db.MakeActivityRequest(activity); err != nil {
- return err
- }
- }
-
- webfinger.FollowingBoards, err = activitypub.GetActorFollowingDB(config.Domain)
- if err != nil {
- return err
- }
-
- webfinger.Boards, err = webfinger.GetBoardCollection()
- if err != nil {
- return err
- }
- break
-
- case "Delete":
- fmt.Println("This is a delete")
- ctx.Response().Header.Set("Status", "403")
- _, err = ctx.Write([]byte("could not process activity"))
- break
-
- case "Note":
- ctx.Response().Header.Set("Satus", "403")
- _, err = ctx.Write([]byte("could not process activity"))
- break
-
- case "New":
- name := activity.Object.Alias
- prefname := activity.Object.Name
- summary := activity.Object.Summary
- restricted := activity.Object.Sensitive
-
- actor, err := db.CreateNewBoardDB(*activitypub.CreateNewActor(name, prefname, summary, config.AuthReq, restricted))
- if err != nil {
- return err
- }
-
- if actor.Id != "" {
- var board []activitypub.ObjectBase
- var item activitypub.ObjectBase
- var removed bool = false
-
- item.Id = actor.Id
- for _, e := range webfinger.FollowingBoards {
- if e.Id != item.Id {
- board = append(board, e)
- } else {
- removed = true
- }
- }
-
- if !removed {
- board = append(board, item)
- }
-
- webfinger.FollowingBoards = board
- webfinger.Boards, err = webfinger.GetBoardCollection()
- return err
- }
-
- ctx.Response().Header.Set("Status", "403")
- _, err = ctx.Write([]byte(""))
- break
-
- default:
- ctx.Response().Header.Set("status", "403")
- _, err = ctx.Write([]byte("could not process activity"))
- }
- } else if err != nil {
- return err
- } else {
- fmt.Println("is NOT activity")
- ctx.Response().Header.Set("Status", "403")
- _, err = ctx.Write([]byte("could not process activity"))
- return err
- }
- }
-
- return nil
+ return ParseOutboxRequest(ctx, actor)
}
func ActorFollowing(ctx *fiber.Ctx) error {