mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 07:24:55 +08:00
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
dashboard "bat-api/web"
|
|
)
|
|
|
|
const adminDashboardPath = "/admin/dashboard"
|
|
|
|
var adminDashboardFileServer = http.FileServer(http.FS(dashboard.Assets))
|
|
|
|
func (s *Server) handleAdminDashboard(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
|
writeErrorJSON(w, http.StatusMethodNotAllowed, "method_not_allowed", "method not allowed")
|
|
return
|
|
}
|
|
w.Header().Set("Cache-Control", "no-store")
|
|
if r.URL.Path == adminDashboardPath {
|
|
http.Redirect(w, r, adminDashboardPath+"/", http.StatusMovedPermanently)
|
|
return
|
|
}
|
|
if !strings.HasPrefix(r.URL.Path, adminDashboardPath+"/") {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
http.StripPrefix(adminDashboardPath+"/", adminDashboardFileServer).ServeHTTP(w, r)
|
|
}
|
|
|
|
func dashboardAuthExemptPaths() []string {
|
|
return []string{adminDashboardPath, adminDashboardPath + "/"}
|
|
}
|
|
|
|
func isAdminDashboardPath(path string) bool {
|
|
return path == adminDashboardPath || strings.HasPrefix(path, adminDashboardPath+"/")
|
|
}
|