aboutsummaryrefslogtreecommitdiff
path: root/service/transport.go
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-01-08 18:16:06 +0000
committerr <r@freesoftwareextremist.com>2020-01-08 18:16:06 +0000
commita8dbbec988cf1ed42a051d1a0dfa9987d890d440 (patch)
treef8f882b495cab8014d09a1f8387cdea9dc7b736f /service/transport.go
parentca711e62ec85a763f1b17c9443125579a0f0be7a (diff)
downloadbloat-a8dbbec988cf1ed42a051d1a0dfa9987d890d440.tar.gz
bloat-a8dbbec988cf1ed42a051d1a0dfa9987d890d440.zip
Add fluoride mode
Diffstat (limited to 'service/transport.go')
-rw-r--r--service/transport.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/service/transport.go b/service/transport.go
index 041330d..d89b854 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -2,6 +2,8 @@ package service
import (
"context"
+ "encoding/json"
+ "io"
"mime/multipart"
"net/http"
"path"
@@ -232,6 +234,70 @@ func NewHandler(s Service, staticDir string) http.Handler {
w.WriteHeader(http.StatusFound)
}).Methods(http.MethodPost)
+ r.HandleFunc("/fluoride/like/{id}", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+ id, _ := mux.Vars(req)["id"]
+ count, err := s.Like(ctx, w, nil, id)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+
+ err = serveJson(w, count)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+ }).Methods(http.MethodPost)
+
+ r.HandleFunc("/fluoride/unlike/{id}", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+ id, _ := mux.Vars(req)["id"]
+ count, err := s.UnLike(ctx, w, nil, id)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+
+ err = serveJson(w, count)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+ }).Methods(http.MethodPost)
+
+ r.HandleFunc("/fluoride/retweet/{id}", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+ id, _ := mux.Vars(req)["id"]
+ count, err := s.Retweet(ctx, w, nil, id)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+
+ err = serveJson(w, count)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+ }).Methods(http.MethodPost)
+
+ r.HandleFunc("/fluoride/unretweet/{id}", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+ id, _ := mux.Vars(req)["id"]
+ count, err := s.UnRetweet(ctx, w, nil, id)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+
+ err = serveJson(w, count)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+ }).Methods(http.MethodPost)
+
r.HandleFunc("/post", func(w http.ResponseWriter, req *http.Request) {
ctx := getContextWithSession(context.Background(), req)
@@ -381,11 +447,13 @@ func NewHandler(s Service, staticDir string) http.Handler {
copyScope := req.FormValue("copy_scope") == "true"
threadInNewTab := req.FormValue("thread_in_new_tab") == "true"
maskNSFW := req.FormValue("mask_nsfw") == "true"
+ fluorideMode := req.FormValue("fluoride_mode") == "true"
settings := &model.Settings{
DefaultVisibility: visibility,
CopyScope: copyScope,
ThreadInNewTab: threadInNewTab,
MaskNSFW: maskNSFW,
+ FluorideMode: fluorideMode,
}
err := s.SaveSettings(ctx, w, nil, settings)
@@ -430,3 +498,9 @@ func getMultipartFormValue(mf *multipart.Form, key string) (val string) {
}
return vals[0]
}
+
+func serveJson(w io.Writer, data interface{}) (err error) {
+ var d = make(map[string]interface{})
+ d["data"] = data
+ return json.NewEncoder(w).Encode(d)
+}