Files

50 lines
670 B
Go

package server
import (
"net/http"
"strings"
)
func (s *Server) handleEditorRoute(
w http.ResponseWriter,
r *http.Request,
) {
if strings.HasPrefix(r.URL.Path, "/e/-/") {
s.handleSemanticEditor(w, r)
return
}
// Known future editor adapters.
for _, prefix := range []string{
"/e/plain/",
"/e/hex/",
"/e/pdf/",
"/e/office/",
} {
if strings.HasPrefix(r.URL.Path, prefix) {
http.NotFound(w, r)
return
}
}
// Backward compatibility:
// /e/foo/bar -> /e/-/foo/bar
oldPath :=
strings.TrimPrefix(
r.URL.Path,
"/e",
)
if oldPath == "" {
oldPath = "/"
}
http.Redirect(
w,
r,
"/e/-"+oldPath,
http.StatusFound,
)
}