diff --git a/repo/repo.go b/repo/repo.go index ffe6146..df9720e 100644 --- a/repo/repo.go +++ b/repo/repo.go @@ -4,6 +4,8 @@ import ( "bytes" "errors" "fmt" + "io" + "os" "strconv" "strings" "time" @@ -218,6 +220,15 @@ func (repo *Repo) GetRepo() map[string]*content.RepoNode { return response } +// WriteRepoBytes get the whole repo in all dimensions +func (repo *Repo) WriteRepoBytes(w io.Writer) { + f, err := os.Open(repo.history.getCurrentFilename()) + _, err = io.Copy(w, f) + if err != nil { + Log.Error("failed to serve Repo JSON", zap.Error(err)) + } +} + // Update - reload contents of repository with json from repo.server func (repo *Repo) Update() (updateResponse *responses.Update) { floatSeconds := func(nanoSeconds int64) float64 { diff --git a/server/handlerequest.go b/server/handlerequest.go index e0f4c86..2d14a34 100644 --- a/server/handlerequest.go +++ b/server/handlerequest.go @@ -51,11 +51,12 @@ func handleRequest(r *repo.Repo, handler Handler, jsonBytes []byte, source strin processIfJSONIsOk(json.Unmarshal(jsonBytes, &updateRequest), func() { reply = r.Update() }) - case HandlerGetRepo: - repoRequest := &requests.Repo{} - processIfJSONIsOk(json.Unmarshal(jsonBytes, &repoRequest), func() { - reply = r.GetRepo() - }) + // case HandlerGetRepo: + // repoRequest := &requests.Repo{} + // processIfJSONIsOk(json.Unmarshal(jsonBytes, &repoRequest), func() { + // reply = r.GetRepo() + // }) + default: reply = responses.NewError(1, "unknown handler: "+string(handler)) } diff --git a/server/webserver.go b/server/webserver.go index e12b7f1..64c4f29 100644 --- a/server/webserver.go +++ b/server/webserver.go @@ -35,7 +35,13 @@ func (s *webServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, "failed to read incoming request", http.StatusBadRequest) return } - reply, errReply := handleRequest(s.r, Handler(strings.TrimPrefix(r.URL.Path, s.path+"/")), jsonBytes, "webserver") + h := Handler(strings.TrimPrefix(r.URL.Path, s.path+"/")) + if h == HandlerGetRepo { + s.r.WriteRepoBytes(w) + w.Header().Set("Content-Type", "application/json") + return + } + reply, errReply := handleRequest(s.r, h, jsonBytes, "webserver") if errReply != nil { http.Error(w, errReply.Error(), http.StatusInternalServerError) return