|
|
@ -5,8 +5,9 @@ |
|
|
|
package repo |
|
|
|
package repo |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"path" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/git" |
|
|
|
"code.gitea.io/git" |
|
|
|
|
|
|
|
|
|
|
@ -22,14 +23,19 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error { |
|
|
|
buf = buf[:n] |
|
|
|
buf = buf[:n] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !base.IsTextFile(buf) { |
|
|
|
ctx.Resp.Header().Set("Cache-Control", "public,max-age=86400") |
|
|
|
if !base.IsImageFile(buf) { |
|
|
|
|
|
|
|
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename=\""+path.Base(ctx.Repo.TreePath)+"\"") |
|
|
|
// Google Chrome dislike commas in filenames, so let's change it to a space
|
|
|
|
ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary") |
|
|
|
name = strings.Replace(name, ",", " ", -1) |
|
|
|
} |
|
|
|
|
|
|
|
} else if !ctx.QueryBool("render") { |
|
|
|
if base.IsTextFile(buf) || ctx.QueryBool("render") { |
|
|
|
ctx.Resp.Header().Set("Content-Type", "text/plain; charset=utf-8") |
|
|
|
ctx.Resp.Header().Set("Content-Type", "text/plain; charset=utf-8") |
|
|
|
|
|
|
|
} else if base.IsImageFile(buf) || base.IsPDFFile(buf) { |
|
|
|
|
|
|
|
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name)) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Resp.Write(buf) |
|
|
|
ctx.Resp.Write(buf) |
|
|
|
_, err := io.Copy(ctx.Resp, reader) |
|
|
|
_, err := io.Copy(ctx.Resp, reader) |
|
|
|
return err |
|
|
|
return err |
|
|
|