mirror of
https://github.com/lus/pasty.git
synced 2023-08-10 21:13:09 +03:00
implement raw paste handler
This commit is contained in:
@@ -2,6 +2,7 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
|
"github.com/lus/pasty/internal/pastes"
|
||||||
"github.com/lus/pasty/internal/storage"
|
"github.com/lus/pasty/internal/storage"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@@ -39,9 +40,19 @@ type Server struct {
|
|||||||
func (server *Server) Start() error {
|
func (server *Server) Start() error {
|
||||||
router := chi.NewRouter()
|
router := chi.NewRouter()
|
||||||
|
|
||||||
// Serve the web frontend
|
// Register the web frontend handler
|
||||||
router.Get("/*", frontendHandler(router.NotFoundHandler()))
|
router.Get("/*", frontendHandler(router.NotFoundHandler()))
|
||||||
|
|
||||||
|
// Register the raw paste handler
|
||||||
|
router.With(server.v2MiddlewareInjectPaste).Get("/{paste_id}/raw", func(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
paste, ok := request.Context().Value("paste").(*pastes.Paste)
|
||||||
|
if !ok {
|
||||||
|
writeString(writer, http.StatusInternalServerError, "missing paste object")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _ = writer.Write([]byte(paste.Content))
|
||||||
|
})
|
||||||
|
|
||||||
// Register the paste API endpoints
|
// Register the paste API endpoints
|
||||||
router.Get("/api/*", router.NotFoundHandler())
|
router.Get("/api/*", router.NotFoundHandler())
|
||||||
router.With(server.v2MiddlewareInjectPaste).Get("/api/v2/pastes/{paste_id}", server.v2EndpointGetPaste)
|
router.With(server.v2MiddlewareInjectPaste).Get("/api/v2/pastes/{paste_id}", server.v2EndpointGetPaste)
|
||||||
|
Reference in New Issue
Block a user