init
This commit is contained in:
commit
fa6a4c650f
93 files changed
+6555
No files matched your search
@@ -0,0 +1,103 @@
|
||||
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,
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user