diff options
Diffstat (limited to 'routes')
-rw-r--r-- | routes/404.go | 4 | ||||
-rw-r--r-- | routes/admin.go | 50 | ||||
-rw-r--r-- | routes/index.go | 7 | ||||
-rw-r--r-- | routes/outbox.go | 21 | ||||
-rw-r--r-- | routes/post.go | 8 |
5 files changed, 76 insertions, 14 deletions
diff --git a/routes/404.go b/routes/404.go index 64ea167..94b96e8 100644 --- a/routes/404.go +++ b/routes/404.go @@ -1,6 +1,8 @@ package routes -import "github.com/gofiber/fiber/v2" +import ( + "github.com/gofiber/fiber/v2" +) func NotFound(c *fiber.Ctx) error { return c.Status(404).Render("404", fiber.Map{}, "layouts/main") diff --git a/routes/admin.go b/routes/admin.go index 068dda3..528e40c 100644 --- a/routes/admin.go +++ b/routes/admin.go @@ -1,6 +1,11 @@ package routes -import "github.com/gofiber/fiber/v2" +import ( + "github.com/FChannel0/FChannel-Server/config" + "github.com/FChannel0/FChannel-Server/db" + "github.com/FChannel0/FChannel-Server/webfinger" + "github.com/gofiber/fiber/v2" +) func AdminVerify(c *fiber.Ctx) error { // STUB @@ -14,10 +19,47 @@ func AdminAuth(c *fiber.Ctx) error { return c.SendString("admin auth") } -func AdminIndex(c *fiber.Ctx) error { - // STUB +func AdminIndex(ctx *fiber.Ctx) error { + actor, err := webfinger.GetActor(config.Domain) + + if err != nil { + return err + } + + follow, _ := webfinger.GetActorCollection(actor.Following) + follower, _ := webfinger.GetActorCollection(actor.Followers) + + var following []string + var followers []string + + for _, e := range follow.Items { + following = append(following, e.Id) + } + + for _, e := range follower.Items { + followers = append(followers, e.Id) + } + + var adminData AdminPage + adminData.Following = following + adminData.Followers = followers + adminData.Actor = actor.Id + adminData.Key = config.Key + adminData.Domain = config.Domain + adminData.Board.ModCred, _ = db.GetPasswordFromSession(ctx) + adminData.Title = actor.Name + " Admin page" + + adminData.Boards = db.Boards + + adminData.Board.Post.Actor = actor.Id + + adminData.PostBlacklist, _ = db.GetRegexBlacklistDB() + + adminData.Themes = &config.Themes - return c.SendString("admin index") + return ctx.Render("admin", fiber.Map{ + "page": adminData, + }) } func AdminAddBoard(c *fiber.Ctx) error { diff --git a/routes/index.go b/routes/index.go index 3599455..5ff2bd4 100644 --- a/routes/index.go +++ b/routes/index.go @@ -3,6 +3,7 @@ package routes import ( "github.com/FChannel0/FChannel-Server/config" "github.com/FChannel0/FChannel-Server/db" + "github.com/FChannel0/FChannel-Server/util" "github.com/FChannel0/FChannel-Server/webfinger" "github.com/gofiber/fiber/v2" ) @@ -13,6 +14,12 @@ func Index(ctx *fiber.Ctx) error { return err } + // this is a activitpub json request return json instead of html page + if util.AcceptActivity(ctx.Get("Accept")) { + db.GetActorInfo(ctx, actor.Id) + return nil + } + var data PageData data.Title = "Welcome to " + actor.PreferredUsername data.PreferredUsername = actor.PreferredUsername diff --git a/routes/outbox.go b/routes/outbox.go index b00f946..1277011 100644 --- a/routes/outbox.go +++ b/routes/outbox.go @@ -16,6 +16,14 @@ func Outbox(ctx *fiber.Ctx) error { } func OutboxGet(ctx *fiber.Ctx) error { + + actor := db.GetActorByName(ctx.Params("actor")) + + if util.AcceptActivity(ctx.Get("Accept")) { + db.GetActorInfo(ctx, actor.Id) + return nil + } + collection, valid, err := wantToServePage(ctx.Params("actor"), 0) if err != nil { return err @@ -24,12 +32,13 @@ func OutboxGet(ctx *fiber.Ctx) error { return ctx.SendString("404") } - actor := collection.Actor - + var page int postNum := ctx.Query("page") - page, err := strconv.Atoi(postNum) - if err != nil { - return err + if postNum != "" { + page, err = strconv.Atoi(postNum) + if err != nil { + return err + } } var returnData PageData @@ -39,7 +48,7 @@ func OutboxGet(ctx *fiber.Ctx) error { returnData.Board.Summary = actor.Summary returnData.Board.InReplyTo = "" returnData.Board.To = actor.Outbox - returnData.Board.Actor = *actor + returnData.Board.Actor = actor returnData.Board.ModCred, _ = getPassword(ctx) returnData.Board.Domain = config.Domain returnData.Board.Restricted = actor.Restricted diff --git a/routes/post.go b/routes/post.go index 24dbbc3..e074f67 100644 --- a/routes/post.go +++ b/routes/post.go @@ -1,13 +1,13 @@ package routes import ( - "regexp" - + "fmt" "github.com/FChannel0/FChannel-Server/config" "github.com/FChannel0/FChannel-Server/db" "github.com/FChannel0/FChannel-Server/util" "github.com/FChannel0/FChannel-Server/webfinger" "github.com/gofiber/fiber/v2" + "regexp" ) func PostGet(ctx *fiber.Ctx) error { @@ -112,6 +112,8 @@ func CatalogGet(ctx *fiber.Ctx) error { collection, err := db.GetObjectFromDBCatalog(actor.Id) + fmt.Println(err) + // TODO: implement this in template functions // "showArchive": func() bool { // col, err := db.GetActorCollectionDBTypeLimit(collection.Actor.Id, "Archive", 1) @@ -162,7 +164,7 @@ func CatalogGet(ctx *fiber.Ctx) error { returnData.Themes = &config.Themes returnData.ThemeCookie = getThemeCookie(ctx) - return ctx.Render("ncatalog", fiber.Map{ + return ctx.Render("catalog", fiber.Map{ "page": returnData, }, "layouts/main") } |