2019-12-13 18:08:26 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2020-01-08 18:16:06 +00:00
|
|
|
"encoding/json"
|
2023-10-01 13:04:07 +00:00
|
|
|
"fmt"
|
2020-11-22 17:29:58 +00:00
|
|
|
"log"
|
2023-10-01 13:04:07 +00:00
|
|
|
"mime/multipart"
|
2019-12-13 18:08:26 +00:00
|
|
|
"net/http"
|
2019-12-26 19:18:09 +00:00
|
|
|
"strconv"
|
2019-12-29 05:59:31 +00:00
|
|
|
"time"
|
2020-01-01 15:58:27 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
"bloat/mastodon"
|
2020-01-01 15:58:27 +00:00
|
|
|
"bloat/model"
|
2019-12-13 18:08:26 +00:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
const (
|
2021-03-20 05:12:48 +00:00
|
|
|
HTML int = iota
|
2020-11-22 17:29:58 +00:00
|
|
|
JSON
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-03-20 05:12:48 +00:00
|
|
|
NOAUTH int = iota
|
2020-11-22 17:29:58 +00:00
|
|
|
SESSION
|
|
|
|
CSRF
|
|
|
|
)
|
|
|
|
|
2023-10-15 15:53:44 +00:00
|
|
|
const csp = "default-src 'none';" +
|
|
|
|
" img-src *;" +
|
|
|
|
" media-src *;" +
|
|
|
|
" font-src *;" +
|
|
|
|
" child-src *;" +
|
|
|
|
" connect-src 'self';" +
|
|
|
|
" script-src 'self';" +
|
|
|
|
" style-src 'self'"
|
|
|
|
|
2023-09-09 06:30:38 +00:00
|
|
|
func NewHandler(s *service, verbose bool, staticDir string) http.Handler {
|
2019-12-13 18:08:26 +00:00
|
|
|
r := mux.NewRouter()
|
|
|
|
|
2021-04-03 06:39:06 +00:00
|
|
|
writeError := func(c *client, err error, t int, retry bool) {
|
2020-11-22 17:29:58 +00:00
|
|
|
switch t {
|
|
|
|
case HTML:
|
2021-03-20 05:12:48 +00:00
|
|
|
c.w.WriteHeader(http.StatusInternalServerError)
|
2021-04-03 06:39:06 +00:00
|
|
|
s.ErrorPage(c, err, retry)
|
2020-11-22 17:29:58 +00:00
|
|
|
case JSON:
|
2021-03-20 05:12:48 +00:00
|
|
|
c.w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
json.NewEncoder(c.w).Encode(map[string]string{
|
2020-11-22 17:29:58 +00:00
|
|
|
"error": err.Error(),
|
|
|
|
})
|
2020-02-18 22:15:37 +00:00
|
|
|
}
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2019-12-13 18:08:26 +00:00
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
handle := func(f func(c *client) error, at int, rt int) http.HandlerFunc {
|
2020-11-22 17:29:58 +00:00
|
|
|
return func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
var err error
|
2021-03-20 05:12:48 +00:00
|
|
|
c := &client{
|
|
|
|
ctx: req.Context(),
|
|
|
|
w: w,
|
|
|
|
r: req,
|
|
|
|
}
|
2019-12-13 18:08:26 +00:00
|
|
|
|
2023-09-09 06:30:38 +00:00
|
|
|
if verbose {
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
log.Printf("path=%s, err=%v, took=%v\n",
|
|
|
|
req.URL.Path, err, time.Since(begin))
|
|
|
|
}(time.Now())
|
|
|
|
}
|
2020-01-05 18:55:37 +00:00
|
|
|
|
2023-10-15 15:53:44 +00:00
|
|
|
h := c.w.Header()
|
2020-11-22 17:29:58 +00:00
|
|
|
switch rt {
|
|
|
|
case HTML:
|
2023-10-15 15:53:44 +00:00
|
|
|
h.Set("Content-Type", "text/html; charset=utf-8")
|
|
|
|
h.Set("Content-Security-Policy", csp)
|
2020-11-22 17:29:58 +00:00
|
|
|
case JSON:
|
2023-10-15 15:53:44 +00:00
|
|
|
h.Set("Content-Type", "application/json")
|
2020-11-22 17:29:58 +00:00
|
|
|
}
|
2020-01-30 15:32:37 +00:00
|
|
|
|
2023-09-18 10:07:54 +00:00
|
|
|
err = c.authenticate(at, s.instance)
|
2020-01-30 15:32:37 +00:00
|
|
|
if err != nil {
|
2021-04-03 06:39:06 +00:00
|
|
|
writeError(c, err, rt, req.Method == http.MethodGet)
|
2020-01-30 15:32:37 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-15 15:53:44 +00:00
|
|
|
// Override the CSP header to allow custom CSS
|
|
|
|
if rt == HTML && len(c.s.Settings.CSS) > 0 &&
|
|
|
|
len(c.s.Settings.CSSHash) > 0 {
|
|
|
|
v := fmt.Sprintf("%s 'sha256-%s'", csp, c.s.Settings.CSSHash)
|
|
|
|
h.Set("Content-Security-Policy", v)
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
err = f(c)
|
2020-01-28 17:51:00 +00:00
|
|
|
if err != nil {
|
2021-04-03 06:39:06 +00:00
|
|
|
writeError(c, err, rt, req.Method == http.MethodGet)
|
2020-01-28 17:51:00 +00:00
|
|
|
return
|
|
|
|
}
|
2020-01-08 18:16:06 +00:00
|
|
|
}
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2020-01-25 10:07:06 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
rootPage := handle(func(c *client) error {
|
2023-09-18 10:07:54 +00:00
|
|
|
err := c.authenticate(SESSION, "")
|
2020-01-08 18:16:06 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
if err == errInvalidSession {
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect("/signin")
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
2020-01-08 18:16:06 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
if !c.s.IsLoggedIn() {
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect("/signin")
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
2020-01-08 18:16:06 +00:00
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
return s.RootPage(c)
|
|
|
|
}, NOAUTH, HTML)
|
2020-01-08 18:16:06 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
navPage := handle(func(c *client) error {
|
|
|
|
return s.NavPage(c)
|
|
|
|
}, SESSION, HTML)
|
2019-12-14 20:19:02 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
signinPage := handle(func(c *client) error {
|
|
|
|
instance, ok := s.SingleInstance()
|
|
|
|
if !ok {
|
|
|
|
return s.SigninPage(c)
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
url, sess, err := s.NewSession(c, instance)
|
2020-11-22 17:29:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.setSession(sess)
|
|
|
|
c.redirect(url)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, NOAUTH, HTML)
|
|
|
|
|
|
|
|
timelinePage := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
tType, _ := mux.Vars(c.r)["type"]
|
|
|
|
q := c.r.URL.Query()
|
2021-01-23 08:44:05 +00:00
|
|
|
instance := q.Get("instance")
|
2022-02-11 11:18:02 +00:00
|
|
|
list := q.Get("list")
|
2020-11-22 17:29:58 +00:00
|
|
|
maxID := q.Get("max_id")
|
|
|
|
minID := q.Get("min_id")
|
2022-10-17 01:48:46 +00:00
|
|
|
tag := q.Get("tag")
|
|
|
|
return s.TimelinePage(c, tType, instance, list, maxID, minID, tag)
|
2020-11-22 17:29:58 +00:00
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
defaultTimelinePage := handle(func(c *client) error {
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect("/timeline/home")
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
threadPage := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
q := c.r.URL.Query()
|
2020-11-22 17:29:58 +00:00
|
|
|
reply := q.Get("reply")
|
|
|
|
return s.ThreadPage(c, id, len(reply) > 1)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
2021-09-05 17:17:59 +00:00
|
|
|
quickReplyPage := handle(func(c *client) error {
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
return s.QuickReplyPage(c, id)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
likedByPage := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-11-22 17:29:58 +00:00
|
|
|
return s.LikedByPage(c, id)
|
|
|
|
}, SESSION, HTML)
|
2022-10-19 14:33:43 +00:00
|
|
|
|
|
|
|
reactedByPage := handle(func(c *client) error {
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
return s.ReactedByPage(c, id)
|
|
|
|
}, SESSION, HTML)
|
2020-11-22 17:29:58 +00:00
|
|
|
|
|
|
|
retweetedByPage := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-11-22 17:29:58 +00:00
|
|
|
return s.RetweetedByPage(c, id)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
notificationsPage := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
q := c.r.URL.Query()
|
2020-11-22 17:29:58 +00:00
|
|
|
maxID := q.Get("max_id")
|
|
|
|
minID := q.Get("min_id")
|
|
|
|
return s.NotificationPage(c, maxID, minID)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
userPage := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
pageType, _ := mux.Vars(c.r)["type"]
|
|
|
|
q := c.r.URL.Query()
|
2020-11-22 17:29:58 +00:00
|
|
|
maxID := q.Get("max_id")
|
|
|
|
minID := q.Get("min_id")
|
|
|
|
return s.UserPage(c, id, pageType, maxID, minID)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
userSearchPage := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
q := c.r.URL.Query()
|
2020-11-22 17:29:58 +00:00
|
|
|
sq := q.Get("q")
|
|
|
|
offset, _ := strconv.Atoi(q.Get("offset"))
|
|
|
|
return s.UserSearchPage(c, id, sq, offset)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
2022-12-17 08:26:51 +00:00
|
|
|
mutePage := handle(func(c *client) error {
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
return s.MutePage(c, id)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
aboutPage := handle(func(c *client) error {
|
|
|
|
return s.AboutPage(c)
|
|
|
|
}, SESSION, HTML)
|
2022-10-12 10:34:41 +00:00
|
|
|
|
|
|
|
aboutInstance := handle(func(c *client) error {
|
|
|
|
return s.AboutInstance(c)
|
|
|
|
}, SESSION, HTML)
|
2020-11-22 17:29:58 +00:00
|
|
|
|
|
|
|
emojisPage := handle(func(c *client) error {
|
|
|
|
return s.EmojiPage(c)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
searchPage := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
q := c.r.URL.Query()
|
2020-11-22 17:29:58 +00:00
|
|
|
sq := q.Get("q")
|
|
|
|
qType := q.Get("type")
|
|
|
|
offset, _ := strconv.Atoi(q.Get("offset"))
|
|
|
|
return s.SearchPage(c, sq, qType, offset)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
settingsPage := handle(func(c *client) error {
|
|
|
|
return s.SettingsPage(c)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
2021-01-30 16:51:09 +00:00
|
|
|
filtersPage := handle(func(c *client) error {
|
|
|
|
return s.FiltersPage(c)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
2023-10-01 13:04:07 +00:00
|
|
|
profilePage := handle(func(c *client) error {
|
|
|
|
return s.ProfilePage(c)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
profileUpdate := handle(func(c *client) error {
|
|
|
|
name := c.r.FormValue("name")
|
|
|
|
bio := c.r.FormValue("bio")
|
|
|
|
var avatar, banner *multipart.FileHeader
|
|
|
|
if f := c.r.MultipartForm.File["avatar"]; len(f) > 0 {
|
|
|
|
avatar = f[0]
|
|
|
|
}
|
|
|
|
if f := c.r.MultipartForm.File["banner"]; len(f) > 0 {
|
|
|
|
banner = f[0]
|
|
|
|
}
|
|
|
|
var fields []mastodon.Field
|
|
|
|
for i := 0; i < 16; i++ {
|
|
|
|
n := c.r.FormValue(fmt.Sprintf("field-name-%d", i))
|
|
|
|
v := c.r.FormValue(fmt.Sprintf("field-value-%d", i))
|
|
|
|
if len(n) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
f := mastodon.Field{Name: n, Value: v}
|
|
|
|
fields = append(fields, f)
|
|
|
|
}
|
|
|
|
locked := c.r.FormValue("locked") == "true"
|
|
|
|
err := s.ProfileUpdate(c, name, bio, avatar, banner, fields, locked)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.redirect("/")
|
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
|
|
|
profileDelAvatar := handle(func(c *client) error {
|
|
|
|
err := s.ProfileDelAvatar(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
|
|
|
profileDelBanner := handle(func(c *client) error {
|
|
|
|
err := s.ProfileDelBanner(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
signin := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
instance := c.r.FormValue("instance")
|
2022-11-11 22:20:49 +00:00
|
|
|
url, sess, err := s.NewSession(c, instance)
|
2020-11-22 17:29:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.setSession(sess)
|
|
|
|
c.redirect(url)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, NOAUTH, HTML)
|
|
|
|
|
|
|
|
oauthCallback := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
q := c.r.URL.Query()
|
2020-11-22 17:29:58 +00:00
|
|
|
token := q.Get("code")
|
2021-03-20 05:12:48 +00:00
|
|
|
err := s.Signin(c, token)
|
2020-11-22 17:29:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect("/")
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
post := handle(func(c *client) error {
|
2022-10-16 22:46:26 +00:00
|
|
|
spoilerText := c.r.FormValue("title")
|
2021-03-20 05:12:48 +00:00
|
|
|
content := c.r.FormValue("content")
|
|
|
|
replyToID := c.r.FormValue("reply_to_id")
|
|
|
|
format := c.r.FormValue("format")
|
|
|
|
visibility := c.r.FormValue("visibility")
|
|
|
|
isNSFW := c.r.FormValue("is_nsfw") == "true"
|
2021-09-05 17:17:59 +00:00
|
|
|
quickReply := c.r.FormValue("quickreply") == "true"
|
2021-03-20 05:12:48 +00:00
|
|
|
files := c.r.MultipartForm.File["attachments"]
|
2023-11-10 22:20:20 +00:00
|
|
|
var mediaDescription []string
|
|
|
|
for i := 0; i < len(files); i++ {
|
|
|
|
v := c.r.FormValue(fmt.Sprintf("media-descr-%d", i))
|
|
|
|
mediaDescription = append(mediaDescription, v)
|
|
|
|
}
|
2022-10-31 15:26:16 +00:00
|
|
|
edit := c.r.FormValue("edit-status-id")
|
2023-11-09 20:14:42 +00:00
|
|
|
language := c.r.FormValue("lang-code")
|
|
|
|
expiresIn, err := strconv.Atoi(c.r.FormValue("expires-in"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-11-09 22:27:22 +00:00
|
|
|
scheduledAt := c.r.FormValue("scheduled")
|
|
|
|
if scheduledAt != "" {
|
|
|
|
scheduled, err := time.Parse("2006-01-02T15:04", scheduledAt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
scheduledAt = string(scheduled.UTC().Format(time.RFC3339))
|
|
|
|
}
|
2023-11-10 15:00:13 +00:00
|
|
|
var pollOptions []string
|
2023-11-10 21:18:45 +00:00
|
|
|
for i := 0; i < 20; i++ {
|
2023-11-10 15:00:13 +00:00
|
|
|
v := c.r.FormValue(fmt.Sprintf("poll-option-%d", i))
|
|
|
|
if len(v) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
pollOptions = append(pollOptions, v)
|
|
|
|
}
|
|
|
|
pollExpiresIn, err := strconv.Atoi(c.r.FormValue("poll-expires-in"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pollHideTotals := c.r.FormValue("poll-hide-totals") == "true"
|
|
|
|
pollMultiple := c.r.FormValue("poll-is-multiple") == "true"
|
2019-12-14 20:19:02 +00:00
|
|
|
|
2023-11-10 22:20:20 +00:00
|
|
|
id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit, language, expiresIn, scheduledAt, pollOptions, pollExpiresIn, pollHideTotals, pollMultiple, mediaDescription)
|
2019-12-13 18:08:26 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
|
|
|
|
2021-09-05 17:17:59 +00:00
|
|
|
var location string
|
2019-12-13 20:23:15 +00:00
|
|
|
if len(replyToID) > 0 {
|
2021-09-05 17:17:59 +00:00
|
|
|
if quickReply {
|
|
|
|
location = "/quickreply/" + id + "#status-" + id
|
|
|
|
} else {
|
|
|
|
location = "/thread/" + replyToID + "#status-" + id
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
location = c.r.FormValue("referrer")
|
2019-12-13 20:23:15 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(location)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2019-12-20 18:30:20 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
like := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
rid := c.r.FormValue("retweeted_by_id")
|
2020-05-24 04:38:34 +00:00
|
|
|
_, err := s.Like(c, id)
|
2019-12-20 18:30:20 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2019-12-20 18:30:20 +00:00
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
if len(rid) > 0 {
|
|
|
|
id = rid
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer") + "#status-" + id)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2019-12-20 18:30:20 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
unlike := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
rid := c.r.FormValue("retweeted_by_id")
|
2020-05-24 04:38:34 +00:00
|
|
|
_, err := s.UnLike(c, id)
|
2019-12-20 18:30:20 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2019-12-20 18:30:20 +00:00
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
if len(rid) > 0 {
|
|
|
|
id = rid
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer") + "#status-" + id)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2019-12-20 18:30:20 +00:00
|
|
|
|
2022-10-17 17:01:11 +00:00
|
|
|
putreact := handle(func(c *client) error {
|
|
|
|
q := c.r.URL.Query()
|
|
|
|
emoji := q.Get("emoji")
|
2022-10-25 22:16:13 +00:00
|
|
|
if len(emoji) <= 0 {
|
|
|
|
emoji = c.r.FormValue("akkoma-reaction")
|
|
|
|
}
|
|
|
|
|
2022-10-17 17:01:11 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
_, err := s.PutReact(c, id, emoji)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer")+"#status-"+id)
|
2022-10-17 17:01:11 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
2022-10-19 12:47:31 +00:00
|
|
|
unreact := handle(func(c *client) error {
|
|
|
|
q := c.r.URL.Query()
|
|
|
|
emoji := q.Get("emoji")
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
_, err := s.UnReact(c, id, emoji)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer")+"#status-"+id)
|
2022-10-19 12:47:31 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
2022-10-17 17:01:11 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
retweet := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
rid := c.r.FormValue("retweeted_by_id")
|
2022-12-02 01:45:19 +00:00
|
|
|
visibility := c.r.FormValue("retweet_visibility")
|
|
|
|
_, err := s.Retweet(c, id, visibility)
|
2019-12-20 18:30:20 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2019-12-20 18:30:20 +00:00
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
if len(rid) > 0 {
|
|
|
|
id = rid
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer") + "#status-" + id)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2019-12-21 05:48:48 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
unretweet := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
rid := c.r.FormValue("retweeted_by_id")
|
2020-05-24 04:38:34 +00:00
|
|
|
_, err := s.UnRetweet(c, id)
|
2019-12-21 05:48:48 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2019-12-21 05:48:48 +00:00
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
if len(rid) > 0 {
|
|
|
|
id = rid
|
2019-12-22 18:10:42 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer") + "#status-" + id)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2019-12-26 19:18:09 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
vote := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
statusID := c.r.FormValue("status_id")
|
|
|
|
choices, _ := c.r.PostForm["choices"]
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.Vote(c, id, choices)
|
2020-02-09 13:42:16 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-02-09 13:42:16 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer") + "#status-" + statusID)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-02-09 13:42:16 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
follow := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
q := c.r.URL.Query()
|
2020-04-19 05:57:40 +00:00
|
|
|
var reblogs *bool
|
2020-11-22 17:29:58 +00:00
|
|
|
if r, ok := q["reblogs"]; ok && len(r) > 0 {
|
2020-04-19 05:57:40 +00:00
|
|
|
reblogs = new(bool)
|
|
|
|
*reblogs = r[0] == "true"
|
|
|
|
}
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.Follow(c, id, reblogs)
|
2019-12-26 19:18:09 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2019-12-26 19:18:09 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2019-12-26 19:18:09 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
unfollow := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.UnFollow(c, id)
|
2019-12-27 08:06:43 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2019-12-27 08:06:43 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2019-12-27 08:06:43 +00:00
|
|
|
|
2021-01-16 09:10:02 +00:00
|
|
|
accept := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2021-01-16 09:10:02 +00:00
|
|
|
err := s.Accept(c, id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2021-01-16 09:10:02 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
|
|
|
reject := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2021-01-16 09:10:02 +00:00
|
|
|
err := s.Reject(c, id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2021-01-16 09:10:02 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
mute := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2022-12-17 08:26:51 +00:00
|
|
|
notifications, _ := strconv.ParseBool(c.r.FormValue("notifications"))
|
|
|
|
duration, _ := strconv.Atoi(c.r.FormValue("duration"))
|
|
|
|
err := s.Mute(c, id, notifications, duration)
|
2020-02-08 10:49:06 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-02-08 10:49:06 +00:00
|
|
|
}
|
2022-12-17 08:26:51 +00:00
|
|
|
c.redirect("/user/" + id)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-02-08 10:49:06 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
unMute := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.UnMute(c, id)
|
2020-02-08 10:49:06 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-02-08 10:49:06 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-02-08 10:49:06 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
block := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.Block(c, id)
|
2020-02-08 10:49:06 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-02-08 10:49:06 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-02-08 10:49:06 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
unBlock := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.UnBlock(c, id)
|
2020-02-08 10:49:06 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-02-08 10:49:06 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-02-08 10:49:06 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
subscribe := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.Subscribe(c, id)
|
2020-04-17 17:19:11 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-04-17 17:19:11 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-04-17 17:19:11 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
unSubscribe := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.UnSubscribe(c, id)
|
2020-04-17 17:19:11 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-04-17 17:19:11 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-04-17 17:19:11 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
settings := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
visibility := c.r.FormValue("visibility")
|
|
|
|
format := c.r.FormValue("format")
|
|
|
|
copyScope := c.r.FormValue("copy_scope") == "true"
|
|
|
|
threadInNewTab := c.r.FormValue("thread_in_new_tab") == "true"
|
|
|
|
hideAttachments := c.r.FormValue("hide_attachments") == "true"
|
|
|
|
maskNSFW := c.r.FormValue("mask_nsfw") == "true"
|
|
|
|
ni, _ := strconv.Atoi(c.r.FormValue("notification_interval"))
|
|
|
|
fluorideMode := c.r.FormValue("fluoride_mode") == "true"
|
|
|
|
darkMode := c.r.FormValue("dark_mode") == "true"
|
|
|
|
antiDopamineMode := c.r.FormValue("anti_dopamine_mode") == "true"
|
2021-12-13 13:58:15 +00:00
|
|
|
hideUnsupportedNotifs := c.r.FormValue("hide_unsupported_notifs") == "true"
|
2022-10-20 23:03:19 +00:00
|
|
|
instanceEmojiFilter := c.r.FormValue("instance-emoji-filter")
|
2022-10-19 23:15:50 +00:00
|
|
|
addReactionsFilter := c.r.FormValue("pleroma-reactions-filter")
|
2021-04-03 09:22:43 +00:00
|
|
|
css := c.r.FormValue("css")
|
2020-01-28 17:51:00 +00:00
|
|
|
|
2019-12-27 08:06:43 +00:00
|
|
|
settings := &model.Settings{
|
2021-12-13 13:58:15 +00:00
|
|
|
DefaultVisibility: visibility,
|
|
|
|
DefaultFormat: format,
|
|
|
|
CopyScope: copyScope,
|
|
|
|
ThreadInNewTab: threadInNewTab,
|
|
|
|
HideAttachments: hideAttachments,
|
|
|
|
MaskNSFW: maskNSFW,
|
|
|
|
NotificationInterval: ni,
|
|
|
|
FluorideMode: fluorideMode,
|
|
|
|
DarkMode: darkMode,
|
|
|
|
AntiDopamineMode: antiDopamineMode,
|
|
|
|
HideUnsupportedNotifs: hideUnsupportedNotifs,
|
2022-10-20 23:03:19 +00:00
|
|
|
InstanceEmojiFilter: instanceEmojiFilter,
|
2022-10-19 23:15:50 +00:00
|
|
|
AddReactionsFilter: addReactionsFilter,
|
2021-12-13 13:58:15 +00:00
|
|
|
CSS: css,
|
2019-12-27 08:06:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.SaveSettings(c, settings)
|
2019-12-27 08:06:43 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2019-12-27 08:06:43 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect("/")
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2019-12-27 08:06:43 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
muteConversation := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.MuteConversation(c, id)
|
2020-02-02 07:24:06 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-02-02 07:24:06 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-02-02 07:24:06 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
unMuteConversation := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.UnMuteConversation(c, id)
|
2020-02-02 07:24:06 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-02-02 07:24:06 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-02-02 07:24:06 +00:00
|
|
|
|
2022-10-31 12:43:36 +00:00
|
|
|
pin := handle(func(c *client) error {
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
err := s.Pin(c, id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2022-10-31 12:43:36 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
|
|
|
unpin := handle(func(c *client) error {
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
err := s.UnPin(c, id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2022-10-31 12:43:36 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
delete := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.Delete(c, id)
|
2020-02-02 08:30:40 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-02-02 08:30:40 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-02-02 08:30:40 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
readNotifications := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
q := c.r.URL.Query()
|
2020-11-22 17:29:58 +00:00
|
|
|
maxID := q.Get("max_id")
|
2020-05-24 04:38:34 +00:00
|
|
|
err := s.ReadNotifications(c, maxID)
|
2020-02-18 22:15:37 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-02-18 22:15:37 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-02-18 22:15:37 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
bookmark := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
rid := c.r.FormValue("retweeted_by_id")
|
2020-09-27 09:29:17 +00:00
|
|
|
err := s.Bookmark(c, id)
|
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-09-27 09:29:17 +00:00
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
if len(rid) > 0 {
|
|
|
|
id = rid
|
2020-09-27 09:29:17 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer") + "#status-" + id)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-09-27 09:29:17 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
unBookmark := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
rid := c.r.FormValue("retweeted_by_id")
|
2020-09-27 09:29:17 +00:00
|
|
|
err := s.UnBookmark(c, id)
|
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-09-27 09:29:17 +00:00
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
if len(rid) > 0 {
|
|
|
|
id = rid
|
2020-09-27 09:29:17 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer") + "#status-" + id)
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-03-04 15:59:59 +00:00
|
|
|
|
2021-01-30 16:51:09 +00:00
|
|
|
filter := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
phrase := c.r.FormValue("phrase")
|
|
|
|
wholeWord := c.r.FormValue("whole_word") == "true"
|
2021-01-30 16:51:09 +00:00
|
|
|
err := s.Filter(c, phrase, wholeWord)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2021-01-30 16:51:09 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
|
|
|
unFilter := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2021-01-30 16:51:09 +00:00
|
|
|
err := s.UnFilter(c, id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2021-01-30 16:51:09 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
2022-02-11 11:18:02 +00:00
|
|
|
listsPage := handle(func(c *client) error {
|
|
|
|
return s.ListsPage(c)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
addList := handle(func(c *client) error {
|
|
|
|
title := c.r.FormValue("title")
|
|
|
|
err := s.AddList(c, title)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2022-02-11 11:18:02 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
|
|
|
removeList := handle(func(c *client) error {
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
err := s.RemoveList(c, id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2022-02-11 11:18:02 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
|
|
|
renameList := handle(func(c *client) error {
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
title := c.r.FormValue("title")
|
|
|
|
err := s.RenameList(c, id, title)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2022-02-11 11:18:02 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
|
|
|
listPage := handle(func(c *client) error {
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
q := c.r.URL.Query()
|
|
|
|
sq := q.Get("q")
|
|
|
|
return s.ListPage(c, id, sq)
|
|
|
|
}, SESSION, HTML)
|
|
|
|
|
|
|
|
listAddUser := handle(func(c *client) error {
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
q := c.r.URL.Query()
|
|
|
|
uid := q.Get("uid")
|
|
|
|
err := s.ListAddUser(c, id, uid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2022-02-11 11:18:02 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
|
|
|
listRemoveUser := handle(func(c *client) error {
|
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
|
|
|
q := c.r.URL.Query()
|
|
|
|
uid := q.Get("uid")
|
|
|
|
err := s.ListRemoveUser(c, id, uid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.redirect(c.r.FormValue("referrer"))
|
2022-02-11 11:18:02 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
signout := handle(func(c *client) error {
|
2023-10-02 06:44:26 +00:00
|
|
|
err := s.Signout(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.unsetSession()
|
|
|
|
c.redirect("/")
|
2020-11-22 17:29:58 +00:00
|
|
|
return nil
|
|
|
|
}, CSRF, HTML)
|
2020-03-04 15:59:59 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
fLike := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
count, err := s.Like(c, id)
|
2020-01-28 17:51:00 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
return c.writeJson(count)
|
2020-11-22 17:29:58 +00:00
|
|
|
}, CSRF, JSON)
|
2020-01-28 17:51:00 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
fUnlike := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
count, err := s.UnLike(c, id)
|
2020-01-28 17:51:00 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
return c.writeJson(count)
|
2020-11-22 17:29:58 +00:00
|
|
|
}, CSRF, JSON)
|
2020-01-28 17:51:00 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
fRetweet := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2022-12-02 01:45:19 +00:00
|
|
|
visibility := c.r.FormValue("retweet_visibility")
|
|
|
|
count, err := s.Retweet(c, id, visibility)
|
2020-01-28 17:51:00 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
return c.writeJson(count)
|
2020-11-22 17:29:58 +00:00
|
|
|
}, CSRF, JSON)
|
2020-01-28 17:51:00 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
fUnretweet := handle(func(c *client) error {
|
2021-03-20 05:12:48 +00:00
|
|
|
id, _ := mux.Vars(c.r)["id"]
|
2020-05-24 04:38:34 +00:00
|
|
|
count, err := s.UnRetweet(c, id)
|
2020-01-28 17:51:00 +00:00
|
|
|
if err != nil {
|
2020-11-22 17:29:58 +00:00
|
|
|
return err
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
return c.writeJson(count)
|
2020-11-22 17:29:58 +00:00
|
|
|
}, CSRF, JSON)
|
2020-01-28 17:51:00 +00:00
|
|
|
|
|
|
|
r.HandleFunc("/", rootPage).Methods(http.MethodGet)
|
2020-02-18 22:15:37 +00:00
|
|
|
r.HandleFunc("/nav", navPage).Methods(http.MethodGet)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/signin", signinPage).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/timeline/{type}", timelinePage).Methods(http.MethodGet)
|
2020-05-24 04:38:34 +00:00
|
|
|
r.HandleFunc("/timeline", defaultTimelinePage).Methods(http.MethodGet)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/thread/{id}", threadPage).Methods(http.MethodGet)
|
2021-09-05 17:17:59 +00:00
|
|
|
r.HandleFunc("/quickreply/{id}", quickReplyPage).Methods(http.MethodGet)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/likedby/{id}", likedByPage).Methods(http.MethodGet)
|
2022-10-19 14:33:43 +00:00
|
|
|
r.HandleFunc("/reactionspage/{id}", reactedByPage).Methods(http.MethodGet)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/retweetedby/{id}", retweetedByPage).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/notifications", notificationsPage).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/user/{id}", userPage).Methods(http.MethodGet)
|
2020-01-31 03:38:49 +00:00
|
|
|
r.HandleFunc("/user/{id}/{type}", userPage).Methods(http.MethodGet)
|
2020-01-30 15:32:37 +00:00
|
|
|
r.HandleFunc("/usersearch/{id}", userSearchPage).Methods(http.MethodGet)
|
2022-12-17 08:26:51 +00:00
|
|
|
r.HandleFunc("/mute/{id}", mutePage).Methods(http.MethodGet)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/about", aboutPage).Methods(http.MethodGet)
|
2022-10-12 10:34:41 +00:00
|
|
|
r.HandleFunc("/aboutinstance", aboutInstance).Methods(http.MethodGet)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/search", searchPage).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/settings", settingsPage).Methods(http.MethodGet)
|
2021-01-30 16:51:09 +00:00
|
|
|
r.HandleFunc("/filters", filtersPage).Methods(http.MethodGet)
|
2023-10-01 13:04:07 +00:00
|
|
|
r.HandleFunc("/profile", profilePage).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/profile", profileUpdate).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/profile/delavatar", profileDelAvatar).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/profile/delbanner", profileDelBanner).Methods(http.MethodPost)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/signin", signin).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/oauth_callback", oauthCallback).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/post", post).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/like/{id}", like).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/unlike/{id}", unlike).Methods(http.MethodPost)
|
2022-10-17 17:01:11 +00:00
|
|
|
r.HandleFunc("/react-with/{id}", putreact).Methods(http.MethodPost)
|
2022-10-19 12:47:31 +00:00
|
|
|
r.HandleFunc("/unreact-with/{id}", unreact).Methods(http.MethodPost)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/retweet/{id}", retweet).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/unretweet/{id}", unretweet).Methods(http.MethodPost)
|
2020-02-09 13:42:16 +00:00
|
|
|
r.HandleFunc("/vote/{id}", vote).Methods(http.MethodPost)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/follow/{id}", follow).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/unfollow/{id}", unfollow).Methods(http.MethodPost)
|
2021-01-16 09:10:02 +00:00
|
|
|
r.HandleFunc("/accept/{id}", accept).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/reject/{id}", reject).Methods(http.MethodPost)
|
2020-02-08 10:49:06 +00:00
|
|
|
r.HandleFunc("/mute/{id}", mute).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/unmute/{id}", unMute).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/block/{id}", block).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/unblock/{id}", unBlock).Methods(http.MethodPost)
|
2020-04-17 17:19:11 +00:00
|
|
|
r.HandleFunc("/subscribe/{id}", subscribe).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/unsubscribe/{id}", unSubscribe).Methods(http.MethodPost)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/settings", settings).Methods(http.MethodPost)
|
2020-02-02 07:24:06 +00:00
|
|
|
r.HandleFunc("/muteconv/{id}", muteConversation).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/unmuteconv/{id}", unMuteConversation).Methods(http.MethodPost)
|
2022-10-31 12:43:36 +00:00
|
|
|
r.HandleFunc("/pin/{id}", pin).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/unpin/{id}", unpin).Methods(http.MethodPost)
|
2020-02-02 08:30:40 +00:00
|
|
|
r.HandleFunc("/delete/{id}", delete).Methods(http.MethodPost)
|
2020-02-18 22:15:37 +00:00
|
|
|
r.HandleFunc("/notifications/read", readNotifications).Methods(http.MethodPost)
|
2020-09-27 09:29:17 +00:00
|
|
|
r.HandleFunc("/bookmark/{id}", bookmark).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/unbookmark/{id}", unBookmark).Methods(http.MethodPost)
|
2021-01-30 16:51:09 +00:00
|
|
|
r.HandleFunc("/filter", filter).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/unfilter/{id}", unFilter).Methods(http.MethodPost)
|
2022-02-11 11:18:02 +00:00
|
|
|
r.HandleFunc("/lists", listsPage).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/list", addList).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/list/{id}", listPage).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/list/{id}/remove", removeList).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/list/{id}/rename", renameList).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/list/{id}/adduser", listAddUser).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/list/{id}/removeuser", listRemoveUser).Methods(http.MethodPost)
|
2020-03-04 15:59:59 +00:00
|
|
|
r.HandleFunc("/signout", signout).Methods(http.MethodPost)
|
2020-01-28 17:51:00 +00:00
|
|
|
r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/fluoride/retweet/{id}", fRetweet).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/fluoride/unretweet/{id}", fUnretweet).Methods(http.MethodPost)
|
|
|
|
r.PathPrefix("/static").Handler(http.StripPrefix("/static",
|
2020-01-31 18:18:31 +00:00
|
|
|
http.FileServer(http.Dir(staticDir))))
|
2020-01-28 17:51:00 +00:00
|
|
|
|
|
|
|
return r
|
2020-01-08 18:16:06 +00:00
|
|
|
}
|