forked from tangled.org/core
this repo has no description

knotserver: fix a bunch of things

anirudh.fi f4b8dc96 27703946

verified
Changed files
+27 -26
cmd
knotserver
knotserver
+3 -3
cmd/knotserver/main.go
···
"github.com/icyphox/bild/config"
"github.com/icyphox/bild/db"
-
"github.com/icyphox/bild/routes"
+
"github.com/icyphox/bild/knotserver"
)
func main() {
···
log.Fatalf("failed to setup db: %s", err)
}
-
mux, err := routes.Setup(c, db)
+
mux, err := knotserver.Setup(c, db)
if err != nil {
log.Fatal(err)
}
···
addr := fmt.Sprintf("%s:%d", c.Server.Host, c.Server.Port)
log.Println("starting main server on", addr)
-
go http.ListenAndServe(addr, mux)
+
log.Fatal(http.ListenAndServe(addr, mux))
}
-1
go.mod
···
github.com/bluekeyes/go-gitdiff v0.8.0
github.com/bluesky-social/indigo v0.0.0-20250123072624-9e3b84fdbb20
github.com/dustin/go-humanize v1.0.1
-
github.com/go-chi/chi v1.5.5
github.com/go-chi/chi/v5 v5.2.0
github.com/go-git/go-git/v5 v5.12.0
github.com/google/uuid v1.6.0
-2
go.sum
···
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
-
github.com/go-chi/chi v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
-
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
github.com/go-chi/chi/v5 v5.2.0 h1:Aj1EtB0qR2Rdo2dG4O94RIU35w2lvQSj6BRA4+qwFL0=
github.com/go-chi/chi/v5 v5.2.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
+8 -8
knotserver/git.go
···
"net/http"
"path/filepath"
+
"github.com/go-chi/chi/v5"
"github.com/icyphox/bild/knotserver/git/service"
)
+
func (d *Handle) InfoRefs(w http.ResponseWriter, r *http.Request) {
-
name := displayRepoName(r)
-
name = filepath.Clean(name)
-
-
repo := filepath.Join(d.c.Repo.ScanPath, name)
+
did := chi.URLParam(r, "did")
+
name := chi.URLParam(r, "name")
+
repo := filepath.Join(d.c.Repo.ScanPath, did, name)
w.Header().Set("content-type", "application/x-git-upload-pack-advertisement")
w.WriteHeader(http.StatusOK)
···
}
func (d *Handle) UploadPack(w http.ResponseWriter, r *http.Request) {
-
name := displayRepoName(r)
-
name = filepath.Clean(name)
-
-
repo := filepath.Join(d.c.Repo.ScanPath, name)
+
did := chi.URLParam(r, "did")
+
name := chi.URLParam(r, "name")
+
repo := filepath.Join(d.c.Repo.ScanPath, did, name)
w.Header().Set("content-type", "application/x-git-upload-pack-result")
w.Header().Set("Connection", "Keep-Alive")
+9 -9
knotserver/handler.go
···
package knotserver
import (
+
"fmt"
"net/http"
-
"github.com/go-chi/chi"
+
"github.com/go-chi/chi/v5"
"github.com/icyphox/bild/config"
"github.com/icyphox/bild/db"
)
···
// r.Put("/new", h.NewRepo)
// })
+
r.Get("/", h.Index)
r.Route("/{did}", func(r chi.Router) {
-
r.Get("/", h.Index)
-
// Repo routes
r.Route("/{name}", func(r chi.Router) {
-
r.Get("/", h.Multiplex)
-
r.Post("/", h.Multiplex)
+
r.Get("/", h.RepoIndex)
+
r.Get("/info/refs", h.InfoRefs)
+
r.Post("/git-upload-pack", h.UploadPack)
r.Route("/tree/{ref}", func(r chi.Router) {
r.Get("/*", h.RepoTree)
···
r.Get("/archive/{file}", h.Archive)
r.Get("/commit/{ref}", h.Diff)
r.Get("/refs/", h.Refs)
-
-
// Catch-all routes
-
r.Get("/*", h.Multiplex)
-
r.Post("/*", h.Multiplex)
})
})
···
w.Write([]byte("no pushing allowed!"))
return
}
+
+
fmt.Println(r.URL.RawQuery)
+
fmt.Println(r.Method)
if path == "info/refs" &&
r.URL.RawQuery == "service=git-upload-pack" &&
+1 -1
knotserver/http_util.go
···
}
func writeMsg(w http.ResponseWriter, msg string) {
-
writeJson(w, map[string]string{"msg": msg})
+
writeJSON(w, map[string]string{"msg": msg})
}
+2
knotserver/routes.go
···
writeMsg(w, "repo empty")
return
} else {
+
log.Println(err)
notFound(w)
return
}
···
}
func (h *Handle) Log(w http.ResponseWriter, r *http.Request) {
+
fmt.Println(r.URL.Path)
ref := chi.URLParam(r, "ref")
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
+4 -2
knotserver/util.go
···
return fmt.Sprintf("@%s/%s", handle.Handle.String(), name)
}
-
func didPath(r *http.Request, did string) string {
-
path := filepath.Join(did, chi.URLParam(r, "name"))
+
func didPath(r *http.Request) string {
+
did := chi.URLParam(r, "did")
+
name := chi.URLParam(r, "name")
+
path := filepath.Join(did, name)
filepath.Clean(path)
return path
}