aboutsummaryrefslogtreecommitdiff
path: root/modules/base
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-03-28 10:51:42 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-03-28 10:51:42 +0800
commit89258e868b070ff3046de912e1d9a3009f923b62 (patch)
tree96d582c68daf862d0328e0734ede3da88e308fb8 /modules/base
parent922a189f4061796b0d4afeeb45e508c36cc5e7fc (diff)
parent5344a0300383c4921e4a5810dff58c7686412f0c (diff)
Merge branch 'master' of github.com:gogits/gogs
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/markdown.go8
-rw-r--r--modules/base/tool.go17
2 files changed, 16 insertions, 9 deletions
diff --git a/modules/base/markdown.go b/modules/base/markdown.go
index c722f04b..962e1ae1 100644
--- a/modules/base/markdown.go
+++ b/modules/base/markdown.go
@@ -51,6 +51,14 @@ func IsTextFile(data []byte) (string, bool) {
return contentType, false
}
+func IsImageFile(data []byte) (string, bool) {
+ contentType := http.DetectContentType(data)
+ if strings.Index(contentType, "image/") != -1 {
+ return contentType, true
+ }
+ return contentType, false
+}
+
func IsReadmeFile(name string) bool {
name = strings.ToLower(name)
if len(name) < 6 {
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 6f4fbe83..9ddb90f7 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -412,6 +412,11 @@ func (f StrTo) Int() (int, error) {
return int(v), err
}
+func (f StrTo) Int64() (int64, error) {
+ v, err := strconv.ParseInt(f.String(), 10, 64)
+ return int64(v), err
+}
+
func (f StrTo) String() string {
if f.Exist() {
return string(f)
@@ -541,16 +546,10 @@ func ActionDesc(act Actioner, avatarLink string) string {
}
func DiffTypeToStr(diffType int) string {
- switch diffType {
- case 1:
- return "add"
- case 2:
- return "modify"
- case 3:
- return "del"
- default:
- return "unknown"
+ diffTypes := map[int]string{
+ 1: "add", 2: "modify", 3: "del",
}
+ return diffTypes[diffType]
}
func DiffLineTypeToStr(diffType int) string {