blob: 8049bd5c8121ed57f2786bfb53cbec4b99aea63e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package routes
import (
"strconv"
"github.com/FChannel0/FChannel-Server/activitypub"
"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"
)
func Outbox(ctx *fiber.Ctx) error {
// STUB
return ctx.SendString("main outbox")
}
func OutboxGet(ctx *fiber.Ctx) error {
actor := webfinger.GetActorByName(ctx.Params("actor"))
if activitypub.AcceptActivity(ctx.Get("Accept")) {
activitypub.GetActorInfo(ctx, actor.Id)
return nil
}
collection, valid, err := wantToServePage(ctx.Params("actor"), 0)
if err != nil {
return err
} else if !valid {
// TODO: 404 template
return ctx.SendString("404")
}
var page int
postNum := ctx.Query("page")
if postNum != "" {
page, err = strconv.Atoi(postNum)
if err != nil {
return err
}
}
var offset = 15
var pages []int
pageLimit := (float64(collection.TotalItems) / float64(offset))
if pageLimit > 11 {
pageLimit = 11
}
for i := 0.0; i < pageLimit; i++ {
pages = append(pages, int(i))
}
var data PageData
data.Board.Name = actor.Name
data.Board.PrefName = actor.PreferredUsername
data.Board.Summary = actor.Summary
data.Board.InReplyTo = ""
data.Board.To = actor.Outbox
data.Board.Actor = actor
data.Board.ModCred, _ = getPassword(ctx)
data.Board.Domain = config.Domain
data.Board.Restricted = actor.Restricted
data.CurrentPage = page
data.ReturnTo = "feed"
data.Board.Post.Actor = actor.Id
capt, err := db.GetRandomCaptcha()
if err != nil {
return err
}
data.Board.Captcha = config.Domain + "/" + capt
data.Board.CaptchaCode = util.GetCaptchaCode(data.Board.Captcha)
data.Title = "/" + actor.Name + "/ - " + actor.PreferredUsername
data.Key = config.Key
data.Boards = webfinger.Boards
data.Posts = collection.OrderedItems
data.Pages = pages
data.TotalPage = len(data.Pages) - 1
data.Meta.Description = data.Board.Summary
data.Meta.Url = data.Board.Actor.Id
data.Meta.Title = data.Title
data.Themes = &config.Themes
data.ThemeCookie = getThemeCookie(ctx)
return ctx.Render("nposts", fiber.Map{
"page": data,
}, "layouts/main")
}
|