From 56530a8a66937194fb4e99af95bcea6bb0281f66 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Wed, 18 May 2022 10:59:07 -0600 Subject: Implement asset deletion and fix redirect logic --- srv/src/api/api.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'srv/src/api/api.go') diff --git a/srv/src/api/api.go b/srv/src/api/api.go index cf34157..a5ada2d 100644 --- a/srv/src/api/api.go +++ b/srv/src/api/api.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "html/template" "net" "net/http" "net/http/httputil" @@ -101,6 +102,8 @@ type API interface { type api struct { params Params srv *http.Server + + redirectTpl *template.Template } // New initializes and returns a new API instance, including setting up all @@ -122,6 +125,8 @@ func New(params Params) (API, error) { params: params, } + a.redirectTpl = a.mustParseTpl("redirect.html") + a.srv = &http.Server{Handler: a.handler()} go func() { @@ -201,11 +206,13 @@ func (a *api) handler() http.Handler { v2Mux := http.NewServeMux() v2Mux.Handle("/follow.html", a.renderDumbHandler("follow.html")) v2Mux.Handle("/posts/", a.renderPostHandler()) - v2Mux.Handle("/assets", apiutil.MethodMux(map[string]http.Handler{ - "GET": a.renderPostAssetsIndexHandler(), - "POST": formMiddleware(a.uploadPostAssetHandler()), - })) - v2Mux.Handle("/assets/", a.servePostAssetHandler()) + v2Mux.Handle("/assets/", http.StripPrefix("/assets", + apiutil.MethodMux(map[string]http.Handler{ + "GET": a.getPostAssetHandler(), + "POST": formMiddleware(a.postPostAssetHandler()), + "DELETE": formMiddleware(a.deletePostAssetHandler()), + }), + )) v2Mux.Handle("/", a.renderIndexHandler()) mux.Handle("/v2/", http.StripPrefix("/v2", v2Mux)) -- cgit v1.2.3