finish PR UI
This commit is contained in:
parent
65e73c4ac6
commit
37e0cee877
16 changed files with 302 additions and 111 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue