package main
import (
"io"
"net/http"
)
const (
REPO = "repo" // repo where the file is located
ID = "id" // a sha in Git, nodeid in Mercurial, etc.
)
// Sends a response containing the file blob, if it exists
// Currently uses request params - to change to path params?
// i.e. /file/repo/id instead of
// /file?repo=repo1&id=sha1sha
func GetFile(w http.ResponseWriter, r *http.Request) {
repoName := r.URL.Query().Get(REPO)
id := r.URL.Query().Get(ID)
if len(repoName) != 0 && len(id) != 0 {
//GetRepository(repoName).GetFile(id)
repo := GetRepository(repoName)
w.Header().Set("Content-Type", "application/octet-stream")
w.Write(repo.GetFile(id))
}
}
// Sends a true or false response depending on whether the file exists
// Currently uses request params - to change to path params?
// i.e. /file/repo/name/id instead of
// /file?repo=repo1&id=sha1
func FileExists(w http.ResponseWriter, r *http.Request