#2283 set text/plain for non-binary files in raw mode

tokarchuk/v1.17
Unknwon 9 years ago
parent 85af36332b
commit 93f03707a7
  1. 6
      modules/base/tool.go
  2. 2
      public/css/gogs.css
  3. 2
      public/less/_repository.less
  4. 2
      routers/repo/download.go
  5. 2
      templates/repo/view_file.tmpl

@ -53,7 +53,11 @@ func ShortSha(sha1 string) string {
} }
func DetectEncoding(content []byte) string { func DetectEncoding(content []byte) string {
_, name, certain := charset.DetermineEncoding(content, setting.Repository.AnsiCharset) _, name, certain := charset.DetermineEncoding(content, "")
if name != "utf-8" && len(setting.Repository.AnsiCharset) > 0 {
log.Debug("Using default AnsiCharset: %s", setting.Repository.AnsiCharset)
return setting.Repository.AnsiCharset
}
log.Debug("Detected encoding: %s (%v)", name, certain) log.Debug("Detected encoding: %s (%v)", name, certain)
return name return name
} }

@ -1902,7 +1902,7 @@ footer .container .links > *:first-child {
margin-top: -2px; margin-top: -2px;
} }
.repository.file.list #file-content .view-raw * { .repository.file.list #file-content .view-raw * {
width: 100%; max-width: 100%;
} }
.repository.file.list #file-content .view-raw img { .repository.file.list #file-content .view-raw img {
padding: 5px 5px 0 5px; padding: 5px 5px 0 5px;

@ -181,7 +181,7 @@
} }
.view-raw { .view-raw {
* { * {
width: 100%; max-width: 100%;
} }
img { img {
padding: 5px 5px 0 5px; padding: 5px 5px 0 5px;

@ -28,6 +28,8 @@ func ServeData(ctx *middleware.Context, name string, reader io.Reader) error {
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(ctx.Repo.TreeName)) ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(ctx.Repo.TreeName))
ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary") ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
} }
} else {
ctx.Resp.Header().Set("Content-Type", "text/plain")
} }
ctx.Resp.Write(buf) ctx.Resp.Write(buf)
_, err := io.Copy(ctx.Resp, reader) _, err := io.Copy(ctx.Resp, reader)

@ -28,7 +28,7 @@
{{if .ReadmeExist}} {{if .ReadmeExist}}
{{if .FileContent}}{{.FileContent | Str2html}}{{end}} {{if .FileContent}}{{.FileContent | Str2html}}{{end}}
{{else if not .IsFileText}} {{else if not .IsFileText}}
<div class="view-raw"> <div class="view-raw ui center">
{{if .IsImageFile}} {{if .IsImageFile}}
<img src="{{EscapePound .FileLink}}"> <img src="{{EscapePound .FileLink}}">
{{else}} {{else}}

Loading…
Cancel
Save