Files
2026-05-19 21:30:42 +09:00

104 lines
1.0 KiB
Go

package server
import (
"net/http"
"os"
"path/filepath"
"strings"
)
func (s *Server) handleObjectRoute(
w http.ResponseWriter,
r *http.Request,
) {
addr :=
strings.TrimPrefix(
r.URL.Path,
"/o/",
)
switch {
case strings.HasPrefix(
addr,
"path:",
):
s.resolvePathAddress(
w,
r,
strings.TrimPrefix(
addr,
"path:",
),
)
return
default:
http.NotFound(w, r)
return
}
}
func (s *Server) resolvePathAddress(
w http.ResponseWriter,
r *http.Request,
path string,
) {
switch {
case strings.HasPrefix(
path,
"/system/static/",
):
s.resolveStaticObject(
w,
r,
path,
)
return
default:
http.NotFound(w, r)
return
}
}
func (s *Server) resolveStaticObject(
w http.ResponseWriter,
r *http.Request,
path string,
) {
rel :=
strings.TrimPrefix(
path,
"/system/static/",
)
localPath :=
filepath.Join(
"static",
rel,
)
if _, err := os.Stat(localPath); err != nil {
http.NotFound(w, r)
return
}
http.ServeFile(
w,
r,
localPath,
)
}