mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 08:57:54 +01:00
fix image display
This commit is contained in:
parent
16cb1e974c
commit
346db02d89
@ -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, "img/") != -1 {
|
||||
return contentType, true
|
||||
}
|
||||
return contentType, false
|
||||
}
|
||||
|
||||
func IsReadmeFile(name string) bool {
|
||||
name = strings.ToLower(name)
|
||||
if len(name) < 6 {
|
||||
|
@ -120,8 +120,12 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
||||
|
||||
data := blob.Contents()
|
||||
_, isTextFile := base.IsTextFile(data)
|
||||
_, isImageFile := base.IsImageFile(data)
|
||||
ctx.Data["FileIsText"] = isTextFile
|
||||
|
||||
if isImageFile {
|
||||
ctx.Data["IsImageFile"] = true
|
||||
} else {
|
||||
readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name)
|
||||
ctx.Data["ReadmeExist"] = readmeExist
|
||||
if readmeExist {
|
||||
@ -132,6 +136,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Directory and file list.
|
||||
@ -236,9 +241,9 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) {
|
||||
|
||||
data := blob.Contents()
|
||||
contentType, isTextFile := base.IsTextFile(data)
|
||||
_, isImageFile := base.IsImageFile(data)
|
||||
ctx.Res.Header().Set("Content-Type", contentType)
|
||||
if !isTextFile {
|
||||
ctx.Res.Header().Set("Content-Type", contentType)
|
||||
ctx.Res.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(treename))
|
||||
ctx.Res.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
}
|
||||
|
@ -23,7 +23,11 @@
|
||||
</div>
|
||||
{{if not .FileIsText}}
|
||||
<div class="panel-footer text-center">
|
||||
{{if .IsImageFile}}
|
||||
<img src="{{.FileLink}}">
|
||||
{{else}}
|
||||
<a href="{{.FileLink}}" class="btn btn-default">View Raw</a>
|
||||
{{end}}
|
||||
</div>
|
||||
{{else}}
|
||||
{{if .ReadmeExist}}
|
||||
|
Loading…
Reference in New Issue
Block a user