git-sync-web 自动提交 2026-09-09 14:55:18
This commit is contained in:
@@ -53,6 +53,7 @@ func NewServer(e *Engine, static fs.FS, password string) *Server {
|
||||
mux.HandleFunc("GET /api/repos/{name}/tree", s.wrapRepo(s.treeRepo))
|
||||
mux.HandleFunc("GET /api/repos/{name}/file", s.wrapRepo(s.fileRepo))
|
||||
mux.HandleFunc("PUT /api/repos/{name}/file", s.wrapRepo(s.fileWriteRepo))
|
||||
mux.HandleFunc("POST /api/repos/{name}/resolve-file", s.wrapRepo(s.resolveFileRepo))
|
||||
mux.HandleFunc("POST /api/repos/{name}/commit", s.wrapRepo(s.commitFileRepo))
|
||||
mux.HandleFunc("GET /api/repos/{name}/diff", s.wrapRepo(s.diffRepo))
|
||||
mux.HandleFunc("GET /api/cron-next", s.handleCronNext)
|
||||
@@ -377,6 +378,28 @@ func (s *Server) fileWriteRepo(w http.ResponseWriter, r *http.Request, name stri
|
||||
writeJSON(w, 200, map[string]any{"ok": true})
|
||||
}
|
||||
|
||||
// resolveFileRepo 网页端解决单个冲突文件:写入 + 暂存,finish=true 时尝试结束合并/变基
|
||||
func (s *Server) resolveFileRepo(w http.ResponseWriter, r *http.Request, name string) {
|
||||
var req struct {
|
||||
Path string `json:"path"`
|
||||
Content string `json:"content"`
|
||||
Finish bool `json:"finish"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
writeErr(w, 400, "请求体格式错误")
|
||||
return
|
||||
}
|
||||
if req.Path == "" {
|
||||
writeErr(w, 400, "缺少 path")
|
||||
return
|
||||
}
|
||||
if err := s.engine.ResolveConflictFile(name, req.Path, req.Content, req.Finish); err != nil {
|
||||
writeErr(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, 200, map[string]any{"ok": true})
|
||||
}
|
||||
|
||||
func (s *Server) commitFileRepo(w http.ResponseWriter, r *http.Request, name string) {
|
||||
var req struct {
|
||||
Path string `json:"path"`
|
||||
@@ -403,7 +426,8 @@ func (s *Server) diffRepo(w http.ResponseWriter, r *http.Request, name string) {
|
||||
scope = "working"
|
||||
}
|
||||
// path 可选:传入时只对比该文件(用于编辑器「对比此文件」)
|
||||
res, err := s.engine.WorkingDiff(name, scope, r.URL.Query().Get("path"))
|
||||
// mode = word 时返回 --word-diff=plain 结果(词级差异)
|
||||
res, err := s.engine.WorkingDiff(name, scope, r.URL.Query().Get("path"), r.URL.Query().Get("mode"))
|
||||
if err != nil {
|
||||
writeErr(w, 400, err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user