summaryrefslogtreecommitdiffstats
path: root/modules/git/commit.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-09-02 04:08:05 -0400
committerUnknwon <u@gogs.io>2015-09-02 04:08:05 -0400
commit37e0cee8770fc4f14857e16eabe83ab7e93a0646 (patch)
tree2eacd8816cb783f208b2afd061d6162cfeafca0e /modules/git/commit.go
parent65e73c4ac63b4d8cb5cd1ec6077fa6085e46895c (diff)
downloadgitea-37e0cee8770fc4f14857e16eabe83ab7e93a0646.tar.gz
gitea-37e0cee8770fc4f14857e16eabe83ab7e93a0646.zip
finish PR UI
Diffstat (limited to 'modules/git/commit.go')
-rw-r--r--modules/git/commit.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 4e254dcec1..da0ab64463 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -7,6 +7,7 @@ package git
import (
"bufio"
"container/list"
+ "net/http"
"strings"
)
@@ -132,3 +133,30 @@ func (c *Commit) GetSubModules() (map[string]*SubModule, error) {
return c.submodules, nil
}
+
+func isImageFile(data []byte) (string, bool) {
+ contentType := http.DetectContentType(data)
+ if strings.Index(contentType, "image/") != -1 {
+ return contentType, true
+ }
+ return contentType, false
+}
+
+func (c *Commit) IsImageFile(name string) bool {
+ blob, err := c.GetBlobByPath(name)
+ if err != nil {
+ return false
+ }
+
+ dataRc, err := blob.Data()
+ if err != nil {
+ return false
+ }
+ buf := make([]byte, 1024)
+ n, _ := dataRc.Read(buf)
+ if n > 0 {
+ buf = buf[:n]
+ }
+ _, isImage := isImageFile(buf)
+ return isImage
+}