readme file is now rendering in repo. can now view files and edit them. can switch between branches with dropdown menu

This commit is contained in:
2026-05-07 11:28:06 +02:00
parent 779a1fdb82
commit dad82a79de
41 changed files with 2463 additions and 141 deletions
+48
View File
@@ -160,6 +160,54 @@ func (h *RepoHandler) Blob(w http.ResponseWriter, r *http.Request) {
jsonOK(w, map[string]string{"content": string(content), "path": path, "ref": ref})
}
func (h *RepoHandler) UpdateBlob(w http.ResponseWriter, r *http.Request) {
repo, ok := h.lookupRepo(w, r)
if !ok {
return
}
userID, ok := middleware.UserIDFromContext(r.Context())
if !ok {
jsonError(w, "unauthorized", http.StatusUnauthorized)
return
}
var u models.User
if has, _ := h.db.ID(userID).Get(&u); !has {
jsonError(w, "user not found", http.StatusUnauthorized)
return
}
var req struct {
Path string `json:"path"`
Content string `json:"content"`
Message string `json:"message"`
Branch string `json:"branch"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
jsonError(w, "invalid body", http.StatusBadRequest)
return
}
if req.Path == "" || req.Message == "" {
jsonError(w, "path and message are required", http.StatusBadRequest)
return
}
if req.Branch == "" {
req.Branch = repo.DefaultBranch
}
authorEmail := u.Email
if authorEmail == "" {
authorEmail = u.Username + "@forgebucket.local"
}
gitdomain.SetRepoRoot(h.cfg.RepoRoot)
if err := gitdomain.WriteFile(repo.DiskPath, req.Branch, req.Path, req.Content, u.Username, authorEmail, req.Message); err != nil {
jsonError(w, "could not save file: "+err.Error(), http.StatusInternalServerError)
return
}
jsonOK(w, map[string]string{"status": "ok"})
}
func (h *RepoHandler) Branches(w http.ResponseWriter, r *http.Request) {
repo, ok := h.lookupRepo(w, r)
if !ok {