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
|
package router
import (
"net/url"
"strings"
"github.com/SayaAndy/saya-today-web/internal/mailer"
"github.com/SayaAndy/saya-today-web/locale"
"github.com/gofiber/fiber/v2"
)
func init() {
assert(0, tm.Add("personal-page-status", "views/partials/personal-page-status.html"))
}
func Api_V1_Subs_Put(l map[string]*locale.LocaleConfig) func(c *fiber.Ctx) error {
return func(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8)
id := c.IP()
lang := "en"
var referer, path string
var pathParts []string
var urlStruct *url.URL
var err error
referer = c.Get("Referer", "")
if referer == "" {
goto skipFetchingLang
}
urlStruct, err = url.ParseRequestURI(referer)
if err != nil {
goto skipFetchingLang
}
path = urlStruct.EscapedPath()
pathParts = strings.Split(strings.Trim(path, "/"), "/")
if len(pathParts) == 0 {
goto skipFetchingLang
}
lang = pathParts[0]
skipFetchingLang:
subscriptionType := c.FormValue("tags")
var subscriptionTypeEnum mailer.SubscriptionType
switch subscriptionType {
case "all":
subscriptionTypeEnum = mailer.All
case "none":
subscriptionTypeEnum = mailer.None
case "specific":
subscriptionTypeEnum = mailer.Specific
default:
return api_v1_email_sendStatusHtml(c, "subs-message", l, "Failed", fiber.StatusUnprocessableEntity, lang, l[lang].UserProfile.SubscribeInvalidType, map[string]string{})
}
specificTags := c.FormValue("tags_picked")
if err = Mailer.Subscribe(id, subscriptionTypeEnum, specificTags); err != nil {
return api_v1_email_sendStatusHtml(c, "subs-message", l, "Failed", fiber.StatusUnprocessableEntity, lang, l[lang].UserProfile.FailedToSubscribe, map[string]string{})
}
return api_v1_email_sendStatusHtml(c, "subs-message", l, "OK", fiber.StatusOK, lang, l[lang].UserProfile.SubscribedSuccessfully, map[string]string{})
}
}
|