git-sync-web 自动提交 2026-09-08 19:13:24
This commit is contained in:
@@ -43,6 +43,8 @@ func NewServer(e *Engine, static fs.FS, password string) *Server {
|
||||
mux.HandleFunc("POST /api/repos/{name}/stop", s.wrapRepo(s.stopRepo))
|
||||
mux.HandleFunc("POST /api/repos/{name}/sync", s.wrapRepo(s.syncRepo))
|
||||
mux.HandleFunc("POST /api/repos/{name}/action", s.wrapRepo(s.actionRepo))
|
||||
mux.HandleFunc("POST /api/repos/{name}/force-push", s.wrapRepo(s.forcePushRepo))
|
||||
mux.HandleFunc("POST /api/repos/{name}/abort-push", s.wrapRepo(s.abortPushRepo))
|
||||
mux.HandleFunc("GET /api/repos/{name}/conflicts", s.wrapRepo(s.conflictsRepo))
|
||||
mux.HandleFunc("GET /api/repos/{name}/log", s.wrapRepo(s.logRepo))
|
||||
mux.HandleFunc("GET /api/repos/{name}/stats", s.wrapRepo(s.statsRepo))
|
||||
@@ -52,6 +54,7 @@ func NewServer(e *Engine, static fs.FS, password string) *Server {
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// 访问密码保护:静态资源开放,/api/* 需要会话(登录接口除外)
|
||||
if s.password != "" && strings.HasPrefix(r.URL.Path, "/api/") &&
|
||||
@@ -311,3 +314,19 @@ func (s *Server) handleEvents(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) forcePushRepo(w http.ResponseWriter, r *http.Request, name string) {
|
||||
if err := s.engine.ForcePush(name); err != nil {
|
||||
writeErr(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, 200, map[string]any{"ok": true})
|
||||
}
|
||||
|
||||
func (s *Server) abortPushRepo(w http.ResponseWriter, r *http.Request, name string) {
|
||||
if err := s.engine.AbortPush(name); err != nil {
|
||||
writeErr(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, 200, map[string]any{"ok": true})
|
||||
}
|
||||
Reference in New Issue
Block a user