fix image display
This commit is contained in:
parent
16cb1e974c
commit
346db02d89
3 changed files with 26 additions and 9 deletions
|
@ -51,6 +51,14 @@ func IsTextFile(data []byte) (string, bool) {
|
||||||
return contentType, false
|
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 {
|
func IsReadmeFile(name string) bool {
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
if len(name) < 6 {
|
if len(name) < 6 {
|
||||||
|
|
|
@ -120,15 +120,20 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
||||||
|
|
||||||
data := blob.Contents()
|
data := blob.Contents()
|
||||||
_, isTextFile := base.IsTextFile(data)
|
_, isTextFile := base.IsTextFile(data)
|
||||||
|
_, isImageFile := base.IsImageFile(data)
|
||||||
ctx.Data["FileIsText"] = isTextFile
|
ctx.Data["FileIsText"] = isTextFile
|
||||||
|
|
||||||
readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name)
|
if isImageFile {
|
||||||
ctx.Data["ReadmeExist"] = readmeExist
|
ctx.Data["IsImageFile"] = true
|
||||||
if readmeExist {
|
|
||||||
ctx.Data["FileContent"] = string(base.RenderMarkdown(data, ""))
|
|
||||||
} else {
|
} else {
|
||||||
if isTextFile {
|
readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name)
|
||||||
ctx.Data["FileContent"] = string(data)
|
ctx.Data["ReadmeExist"] = readmeExist
|
||||||
|
if readmeExist {
|
||||||
|
ctx.Data["FileContent"] = string(base.RenderMarkdown(data, ""))
|
||||||
|
} else {
|
||||||
|
if isTextFile {
|
||||||
|
ctx.Data["FileContent"] = string(data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,9 +241,9 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) {
|
||||||
|
|
||||||
data := blob.Contents()
|
data := blob.Contents()
|
||||||
contentType, isTextFile := base.IsTextFile(data)
|
contentType, isTextFile := base.IsTextFile(data)
|
||||||
|
_, isImageFile := base.IsImageFile(data)
|
||||||
ctx.Res.Header().Set("Content-Type", contentType)
|
ctx.Res.Header().Set("Content-Type", contentType)
|
||||||
if !isTextFile {
|
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-Disposition", "attachment; filename="+filepath.Base(treename))
|
||||||
ctx.Res.Header().Set("Content-Transfer-Encoding", "binary")
|
ctx.Res.Header().Set("Content-Transfer-Encoding", "binary")
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,11 @@
|
||||||
</div>
|
</div>
|
||||||
{{if not .FileIsText}}
|
{{if not .FileIsText}}
|
||||||
<div class="panel-footer text-center">
|
<div class="panel-footer text-center">
|
||||||
<a href="{{.FileLink}}" class="btn btn-default">View Raw</a>
|
{{if .IsImageFile}}
|
||||||
|
<img src="{{.FileLink}}">
|
||||||
|
{{else}}
|
||||||
|
<a href="{{.FileLink}}" class="btn btn-default">View Raw</a>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{if .ReadmeExist}}
|
{{if .ReadmeExist}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue