aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
authorFChannel <>2022-05-02 17:43:39 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit328c9150228156c04d1045469c7dbcd7b5f4fedf (patch)
treeae4e281b4e0b6df3c54919756d55bfeff90f0ef0 /routes
parent62edcb3745f414212ee102c13429056f02cf31bd (diff)
admin auth and manage page working for initial pass through
Diffstat (limited to 'routes')
-rw-r--r--routes/actor.go12
-rw-r--r--routes/admin.go142
-rw-r--r--routes/follow.go17
-rw-r--r--routes/structs.go1
4 files changed, 154 insertions, 18 deletions
diff --git a/routes/actor.go b/routes/actor.go
index d8b6631..d564850 100644
--- a/routes/actor.go
+++ b/routes/actor.go
@@ -403,16 +403,12 @@ func ActorOutbox(ctx *fiber.Ctx) error {
return nil
}
-func ActorFollowing(c *fiber.Ctx) error {
- // STUB
-
- return c.SendString("actor following")
+func ActorFollowing(ctx *fiber.Ctx) error {
+ return activitypub.GetActorFollowing(ctx, config.Domain+"/"+ctx.Params("actor"))
}
-func ActorFollowers(c *fiber.Ctx) error {
- // STUB
-
- return c.SendString("actor followers")
+func ActorFollowers(ctx *fiber.Ctx) error {
+ return activitypub.GetActorFollowers(ctx, config.Domain+"/"+ctx.Params("actor"))
}
func ActorReported(c *fiber.Ctx) error {
diff --git a/routes/admin.go b/routes/admin.go
index a6978f4..e80d24f 100644
--- a/routes/admin.go
+++ b/routes/admin.go
@@ -3,10 +3,10 @@ package routes
import (
"bytes"
"encoding/json"
- "fmt"
"io/ioutil"
"log"
"net/http"
+ "regexp"
"time"
"github.com/FChannel0/FChannel-Server/activitypub"
@@ -96,7 +96,6 @@ func AdminAuth(ctx *fiber.Ctx) error {
}
func AdminIndex(ctx *fiber.Ctx) error {
- fmt.Println("admin index")
id, _ := db.GetPasswordFromSession(ctx)
actor, _ := webfinger.GetActorFromPath(ctx.Path(), "/"+config.Key+"/")
@@ -150,6 +149,77 @@ func AdminIndex(ctx *fiber.Ctx) error {
})
}
+func AdminFollow(ctx *fiber.Ctx) error {
+ actor, _ := webfinger.GetActorFromPath(ctx.Path(), "/"+config.Key+"/")
+
+ following := regexp.MustCompile(`(.+)\/following`)
+ followers := regexp.MustCompile(`(.+)\/followers`)
+
+ follow := ctx.FormValue("follow")
+ actorId := ctx.FormValue("actor")
+
+ //follow all of boards following
+ if following.MatchString(follow) {
+ followingActor, _ := webfinger.FingerActor(follow)
+ col, _ := webfinger.GetActorCollection(followingActor.Following)
+
+ var nObj activitypub.ObjectBase
+ nObj.Id = followingActor.Id
+
+ col.Items = append(col.Items, nObj)
+
+ for _, e := range col.Items {
+ if isFollowing, _ := activitypub.IsAlreadyFollowing(actorId, e.Id); isFollowing && e.Id != config.Domain && e.Id != actorId {
+ followActivity, _ := db.MakeFollowActivity(actorId, e.Id)
+
+ if actor, _ := webfinger.FingerActor(e.Id); actor.Id != "" {
+ db.MakeActivityRequestOutbox(followActivity)
+ }
+ }
+ }
+
+ //follow all of boards followers
+ } else if followers.MatchString(follow) {
+ followersActor, _ := webfinger.FingerActor(follow)
+ col, _ := webfinger.GetActorCollection(followersActor.Followers)
+
+ var nObj activitypub.ObjectBase
+ nObj.Id = followersActor.Id
+
+ col.Items = append(col.Items, nObj)
+
+ for _, e := range col.Items {
+ if isFollowing, _ := activitypub.IsAlreadyFollowing(actorId, e.Id); isFollowing && e.Id != config.Domain && e.Id != actorId {
+ followActivity, _ := db.MakeFollowActivity(actorId, e.Id)
+ if actor, _ := webfinger.FingerActor(e.Id); actor.Id != "" {
+ db.MakeActivityRequestOutbox(followActivity)
+ }
+ }
+ }
+
+ //do a normal follow to a single board
+ } else {
+ followActivity, _ := db.MakeFollowActivity(actorId, follow)
+
+ if isLocal, _ := activitypub.IsActorLocal(followActivity.Object.Actor); !isLocal && followActivity.Actor.Id == config.Domain {
+ _, err := ctx.Write([]byte("main board can only follow local boards. Create a new board and then follow outside boards from it."))
+ return err
+ }
+
+ if actor, _ := webfinger.FingerActor(follow); actor.Id != "" {
+ db.MakeActivityRequestOutbox(followActivity)
+ }
+ }
+
+ var redirect string
+
+ if actor.Name != "main" {
+ redirect = "/" + actor.Name
+ }
+
+ return ctx.Redirect("/"+config.Key+"/"+redirect, http.StatusSeeOther)
+}
+
func AdminAddBoard(c *fiber.Ctx) error {
// STUB
@@ -167,3 +237,71 @@ func AdminNewsDelete(c *fiber.Ctx) error {
return c.SendString("admin news delete")
}
+
+func AdminActorIndex(ctx *fiber.Ctx) error {
+ actor, _ := webfinger.GetActorFromPath(ctx.Path(), "/"+config.Key+"/")
+
+ follow, _ := webfinger.GetActorCollection(actor.Following)
+ follower, _ := webfinger.GetActorCollection(actor.Followers)
+ reported, _ := activitypub.GetActorCollectionReq(actor.Id + "/reported")
+
+ var following []string
+ var followers []string
+ var reports []db.Report
+
+ for _, e := range follow.Items {
+ following = append(following, e.Id)
+ }
+
+ for _, e := range follower.Items {
+ followers = append(followers, e.Id)
+ }
+
+ for _, e := range reported.Items {
+ var r db.Report
+ r.Count = int(e.Size)
+ r.ID = e.Id
+ r.Reason = e.Content
+ reports = append(reports, r)
+ }
+
+ localReports, _ := db.GetLocalReportDB(actor.Name)
+
+ for _, e := range localReports {
+ var r db.Report
+ r.Count = e.Count
+ r.ID = e.ID
+ r.Reason = e.Reason
+ reports = append(reports, r)
+ }
+
+ var data AdminPage
+ data.Following = following
+ data.Followers = followers
+ data.Reported = reports
+ data.Domain = config.Domain
+ data.IsLocal, _ = activitypub.IsActorLocal(actor.Id)
+
+ data.Title = "Manage /" + actor.Name + "/"
+ data.Boards = webfinger.Boards
+ data.Board.Name = actor.Name
+ data.Board.Actor = actor
+ data.Key = config.Key
+ data.Board.TP = config.TP
+
+ data.Board.Post.Actor = actor.Id
+
+ data.AutoSubscribe, _ = activitypub.GetActorAutoSubscribeDB(actor.Id)
+
+ data.Themes = &config.Themes
+
+ data.RecentPosts = activitypub.GetRecentPostsDB(actor.Id)
+
+ if cookie := ctx.Cookies("theme"); cookie != "" {
+ data.ThemeCookie = cookie
+ }
+
+ return ctx.Render("manage", fiber.Map{
+ "page": data,
+ })
+}
diff --git a/routes/follow.go b/routes/follow.go
index 2578983..3dbf9cf 100644
--- a/routes/follow.go
+++ b/routes/follow.go
@@ -1,15 +1,16 @@
package routes
-import "github.com/gofiber/fiber/v2"
+import (
+ "github.com/FChannel0/FChannel-Server/activitypub"
+ "github.com/FChannel0/FChannel-Server/config"
+ "github.com/gofiber/fiber/v2"
+)
-func Following(c *fiber.Ctx) error {
- // STUB
-
- return c.SendString("main following")
+func Following(ctx *fiber.Ctx) error {
+ return activitypub.GetActorFollowing(ctx, config.Domain)
}
-func Followers(c *fiber.Ctx) error {
+func Followers(ctx *fiber.Ctx) error {
// STUB
-
- return c.SendString("main followers")
+ return activitypub.GetActorFollowers(ctx, config.Domain)
}
diff --git a/routes/structs.go b/routes/structs.go
index 7c6e980..1c85676 100644
--- a/routes/structs.go
+++ b/routes/structs.go
@@ -42,6 +42,7 @@ type AdminPage struct {
IsLocal bool
PostBlacklist []util.PostBlacklist
AutoSubscribe bool
+ RecentPosts []activitypub.ObjectBase
Themes *[]string
ThemeCookie string