From 4f1425febf6efb45eaf91aff19b215b8c7e77bec Mon Sep 17 00:00:00 2001 From: r Date: Sat, 30 Jan 2021 16:51:09 +0000 Subject: Add filters --- service/transport.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'service/transport.go') diff --git a/service/transport.go b/service/transport.go index 096b44e..1180f6c 100644 --- a/service/transport.go +++ b/service/transport.go @@ -262,6 +262,10 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return s.SettingsPage(c) }, SESSION, HTML) + filtersPage := handle(func(c *client) error { + return s.FiltersPage(c) + }, SESSION, HTML) + signin := handle(func(c *client) error { instance := c.Req.FormValue("instance") url, sid, err := s.NewSession(instance) @@ -589,6 +593,27 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return nil }, CSRF, HTML) + filter := handle(func(c *client) error { + phrase := c.Req.FormValue("phrase") + wholeWord := c.Req.FormValue("whole_word") == "true" + err := s.Filter(c, phrase, wholeWord) + if err != nil { + return err + } + redirect(c, c.Req.FormValue("referrer")) + return nil + }, CSRF, HTML) + + unFilter := handle(func(c *client) error { + id, _ := mux.Vars(c.Req)["id"] + err := s.UnFilter(c, id) + if err != nil { + return err + } + redirect(c, c.Req.FormValue("referrer")) + return nil + }, CSRF, HTML) + signout := handle(func(c *client) error { s.Signout(c) setSessionCookie(c, "", 0) @@ -648,6 +673,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet) r.HandleFunc("/search", searchPage).Methods(http.MethodGet) r.HandleFunc("/settings", settingsPage).Methods(http.MethodGet) + r.HandleFunc("/filters", filtersPage).Methods(http.MethodGet) r.HandleFunc("/signin", signin).Methods(http.MethodPost) r.HandleFunc("/oauth_callback", oauthCallback).Methods(http.MethodGet) r.HandleFunc("/post", post).Methods(http.MethodPost) @@ -673,6 +699,8 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/notifications/read", readNotifications).Methods(http.MethodPost) r.HandleFunc("/bookmark/{id}", bookmark).Methods(http.MethodPost) r.HandleFunc("/unbookmark/{id}", unBookmark).Methods(http.MethodPost) + r.HandleFunc("/filter", filter).Methods(http.MethodPost) + r.HandleFunc("/unfilter/{id}", unFilter).Methods(http.MethodPost) r.HandleFunc("/signout", signout).Methods(http.MethodPost) r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost) r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost) -- cgit v1.2.3