diff options
Diffstat (limited to 'pkg/handler')
| -rw-r--r-- | pkg/handler/git/handler.go | 29 | 
1 files changed, 25 insertions, 4 deletions
| diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go index 8bb4002..4c5d198 100644 --- a/pkg/handler/git/handler.go +++ b/pkg/handler/git/handler.go @@ -35,8 +35,9 @@ type (  		ListCommits(name string, ref string, count int) ([]*object.Commit, error)  		GetHead(name string) (*plumbing.Reference, error)  		GetTree(name, ref, path string) (*object.Tree, error) -		GetFileContent(name, ref, path string) (string, error) -		GetAbout(name string) (string, error) +		IsBinary(name, ref, path string) (bool, error) +		GetFileContent(name, ref, path string) ([]byte, error) +		GetAbout(name string) ([]byte, error)  		ListTags(name string) ([]*plumbing.Reference, error)  		ListBranches(name string) ([]*plumbing.Reference, error)  		WriteTarGZip(w io.Writer, name, ref, prefix string) error @@ -165,7 +166,7 @@ func (g *GitHandler) About(w http.ResponseWriter, r *http.Request) error {  	extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock  	p := parser.NewWithExtensions(extensions) -	doc := p.Parse([]byte(file)) +	doc := p.Parse(file)  	htmlFlag := markdownhtml.CommonFlags | markdownhtml.HrefTargetBlank  	opts := markdownhtml.RendererOptions{Flags: htmlFlag} @@ -244,6 +245,25 @@ func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) error {  	ref := r.PathValue("ref")  	rest := r.PathValue("rest") +	isBin, err := g.gitService.IsBinary(name, ref, rest) +	if err != nil { +		return err +	} + +	// if it is binary no need to over all the chroma process +	if isBin { +		gitList := &templates.GitItemPage{ +			Name: name, +			Ref:  ref, +			GitItemBase: &templates.GitItemBlobPage{ +				File:    rest, +				Content: []byte("Binary file"), +			}, +		} +		templates.WritePageTemplate(w, gitList) +		return nil +	} +  	file, err := g.gitService.GetFileContent(name, ref, rest)  	if err != nil {  		return err @@ -255,7 +275,8 @@ func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) error {  	formatter := html.New(  		html.WithLineNumbers(true),  	) -	iterator, err := lexer.Tokenise(nil, file) + +	iterator, err := lexer.Tokenise(nil, string(file))  	if err != nil {  		return err  	} | 
