From 72495f4538215051540eb05c14db0ed16142e06e Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sun, 23 Jun 2024 17:04:27 +0200 Subject: ref: Move binary handling up to the handler Now it is up to the handler to decide whether it wants to render a file or not, git only returns the content. --- pkg/service/git.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'pkg/service') diff --git a/pkg/service/git.go b/pkg/service/git.go index 654d6ac..8e25261 100644 --- a/pkg/service/git.go +++ b/pkg/service/git.go @@ -139,37 +139,55 @@ func (g *GitService) GetTree(name, ref, path string) (*object.Tree, error) { return repo.Tree(path) } -func (g *GitService) GetFileContent(name, ref, path string) (string, error) { +func (g *GitService) IsBinary(name, ref, path string) (bool, error) { r := g.configRepo.GetByName(name) if r == nil { - return "", RepositoryNotFoundErr + return false, RepositoryNotFoundErr } repo, err := git.OpenRepository(r.Path) if err != nil { - return "", err + return false, err } err = repo.SetRef(ref) if err != nil { - return "", err + return false, err + } + + return repo.IsBinary(path) +} + +func (g *GitService) GetFileContent(name, ref, path string) ([]byte, error) { + r := g.configRepo.GetByName(name) + if r == nil { + return nil, RepositoryNotFoundErr + } + + repo, err := git.OpenRepository(r.Path) + if err != nil { + return nil, err + } + err = repo.SetRef(ref) + if err != nil { + return nil, err } return repo.FileContent(path) } -func (g *GitService) GetAbout(name string) (string, error) { +func (g *GitService) GetAbout(name string) ([]byte, error) { r := g.configRepo.GetByName(name) if r == nil { - return "", RepositoryNotFoundErr + return nil, RepositoryNotFoundErr } repo, err := git.OpenRepository(r.Path) if err != nil { - return "", err + return nil, err } err = repo.SetRef("") if err != nil { - return "", err + return nil, err } return repo.FileContent(r.About) -- cgit v1.2.3