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
|
package main
import (
"encoding/json"
"net/http"
"strings"
)
func (u *User) processUserPageJson(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/activity+json")
response := UserMeta{}
response.Context = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"}
response.ID = u.ID
response.PrefferedUsername = strings.TrimPrefix(u.UserName, "@")
response.Name = u.Name
response.Type = "Person"
response.Summary = u.Summary
response.Icon = ImageMeta{URL: u.Icon, MediaType: "image/jpeg", Type: "Image"}
response.PublicKey = PublicKeyMeta{PublicKey: u.PublicKey, Owner: u.ID, ID: (u.ID + "#main-key")}
response.Inbox = u.ID + "/inbox"
response.Outbox = u.ID + "/outbox"
data, _ := json.Marshal(response)
w.Write(data)
}
func (u *User) processUserPageRSS(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/rss+xml")
page := u.config.DefaultPage(r)
page.User = u
page.Posts = u.posts
u.config.XMLTemplates.ExecuteTemplate(w, "feed.tpl.xml", page)
}
func (u *User) processUserPage(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.Header.Get("accept"), "text/html") {
for _, post := range u.posts {
post.Likes = CacheCount(u, "likes", post.LocalID)
post.Shares = CacheCount(u, "shares", post.LocalID)
}
u.TotalFollowers = CacheCount(u, "followers", "")
u.TotalPosts = len(u.posts)
page := u.config.DefaultPage(r)
page.User = u
page.Posts = u.posts
u.config.Templates.ExecuteTemplate(w, "userpage.tpl.html", page)
return
}
u.processUserPageJson(w, r)
}
|