-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
42 lines (33 loc) · 1.27 KB
/
utils.go
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
package views
import (
"html/template"
"strings"
"github.com/gofiber/fiber/v2"
"github.com/horkruxes/hkxserver/model"
"github.com/horkruxes/hkxserver/service"
"github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday/v2"
)
func FormToBasicMessage(c *fiber.Ctx) model.Message {
message := model.Message{}
message.SignatureBase64 = strings.TrimSpace(c.FormValue("signature"))
message.AuthorBase64 = strings.TrimSpace(c.FormValue("public-key"))
message.Content = strings.TrimSpace(c.FormValue("message"))
message.DisplayedName = strings.TrimSpace(c.FormValue("name"))
message.MessageID = strings.TrimSpace(c.FormValue("answer-to"))
message.Pod = strings.TrimSpace(c.FormValue("pod-to-post-to"))
return message
}
func parseFormsToService(c *fiber.Ctx, s service.Service) service.ClientConfig {
public := !(c.FormValue("hide-friends") == "on")
s.ClientConfig.PublicPods = public
return s.ClientConfig
}
func MarkDowner(policy *bluemonday.Policy) func(string) template.HTML {
return func(content string) template.HTML {
markdownBytes := blackfriday.Run([]byte(content), blackfriday.WithExtensions(blackfriday.HardLineBreak|blackfriday.NoEmptyLineBeforeBlock))
safeBytes := policy.SanitizeBytes(markdownBytes)
//#nosec
return template.HTML(safeBytes)
}
}