1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

fix for new git api

This commit is contained in:
slene
2014-05-25 20:16:11 +08:00
parent ab13a29cb5
commit 4ee6bc4fca
5 changed files with 61 additions and 19 deletions

View File

@@ -5,6 +5,7 @@
package repo
import (
"io"
"os"
"path/filepath"
@@ -26,20 +27,31 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) {
return
}
data, err := blob.Data()
dataRc, err := blob.Data()
if err != nil {
ctx.Handle(500, "repo.SingleDownload(Data)", err)
return
}
contentType, isTextFile := base.IsTextFile(data)
_, isImageFile := base.IsImageFile(data)
buf := make([]byte, 1024)
n, _ := dataRc.Read(buf)
if n > 0 {
buf = buf[:n]
}
defer func() {
dataRc.Close()
}()
contentType, isTextFile := base.IsTextFile(buf)
_, isImageFile := base.IsImageFile(buf)
ctx.Res.Header().Set("Content-Type", contentType)
if !isTextFile && !isImageFile {
ctx.Res.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(treename))
ctx.Res.Header().Set("Content-Transfer-Encoding", "binary")
}
ctx.Res.Write(data)
ctx.Res.Write(buf)
io.Copy(ctx.Res, dataRc)
}
func ZipDownload(ctx *middleware.Context, params martini.Params) {