Commit 9b99c614 authored by Marin Jankovski's avatar Marin Jankovski

Reuse xsendfile to download the object.

parent 03b7df08
...@@ -113,35 +113,6 @@ func handleStoreLfsObject(w http.ResponseWriter, r *gitRequest, rpc string) { ...@@ -113,35 +113,6 @@ func handleStoreLfsObject(w http.ResponseWriter, r *gitRequest, rpc string) {
} }
func handleRetreiveLfsObject(w http.ResponseWriter, r *gitRequest, rpc string) {
log.Printf("I should download %s", r)
urlPath := r.URL.Path
regExp := regexp.MustCompile(`([0-9a-f]{64})\z`)
oid := regExp.FindString(urlPath)
if len(oid) == 0 {
log.Printf("Found no object for download: %s", urlPath)
return
}
log.Printf("Found oid: %s", oid)
path := filepath.Join(r.StoreLFSPath, transformKey(oid))
content, err := os.Open(path)
if err != nil {
fail500(w, "Cannot get file: ", err)
return
}
defer content.Close()
io.Copy(w, content)
log.Printf("Sent the LFS object to client, oid: %s", oid)
return
}
func transformKey(key string) string { func transformKey(key string) string {
if len(key) < 5 { if len(key) < 5 {
return key return key
......
...@@ -65,7 +65,7 @@ var gitServices = [...]gitService{ ...@@ -65,7 +65,7 @@ var gitServices = [...]gitService{
gitService{"GET", regexp.MustCompile(`/repository/archive.tar.gz\z`), repoPreAuth, handleGetArchive, "tar.gz"}, gitService{"GET", regexp.MustCompile(`/repository/archive.tar.gz\z`), repoPreAuth, handleGetArchive, "tar.gz"},
gitService{"GET", regexp.MustCompile(`/repository/archive.tar.bz2\z`), repoPreAuth, handleGetArchive, "tar.bz2"}, gitService{"GET", regexp.MustCompile(`/repository/archive.tar.bz2\z`), repoPreAuth, handleGetArchive, "tar.bz2"},
gitService{"PUT", regexp.MustCompile(`/gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`), repoPreAuth, handleStoreLfsObject, "lfs-object-receive"}, gitService{"PUT", regexp.MustCompile(`/gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`), repoPreAuth, handleStoreLfsObject, "lfs-object-receive"},
gitService{"GET", regexp.MustCompile(`/gitlab-lfs/objects/([0-9a-f]{64})\z`), repoPreAuth, handleRetreiveLfsObject, "lfs-object-upload"}, gitService{"GET", regexp.MustCompile(`/gitlab-lfs/objects/([0-9a-f]{64})\z`), xSendFile, nil, "lfs-object-upload"},
gitService{"GET", regexp.MustCompile(`/uploads/`), xSendFile, nil, ""}, gitService{"GET", regexp.MustCompile(`/uploads/`), xSendFile, nil, ""},
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment