1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

Huge updates!!!!! Be careful to merge!!!!

This commit is contained in:
Unknwon
2014-07-26 02:28:04 -04:00
parent 3f38ff6c09
commit 5c4bc3c848
43 changed files with 2225 additions and 2125 deletions

View File

@@ -5,50 +5,41 @@
package repo
import (
// "io"
// "os"
// "path/filepath"
"io"
"path"
// "github.com/Unknwon/com"
// "github.com/gogits/git"
// "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware"
)
func SingleDownload(ctx *middleware.Context) {
// treename := params["_1"]
treename := ctx.Params("*")
// blob, err := ctx.Repo.Commit.GetBlobByPath(treename)
// if err != nil {
// ctx.Handle(500, "repo.SingleDownload(GetBlobByPath)", err)
// return
// }
blob, err := ctx.Repo.Commit.GetBlobByPath(treename)
if err != nil {
ctx.Handle(500, "GetBlobByPath", err)
return
}
// dataRc, err := blob.Data()
// if err != nil {
// ctx.Handle(500, "repo.SingleDownload(Data)", err)
// return
// }
dataRc, err := blob.Data()
if err != nil {
ctx.Handle(500, "repo.SingleDownload(Data)", err)
return
}
// buf := make([]byte, 1024)
// n, _ := dataRc.Read(buf)
// if n > 0 {
// buf = buf[:n]
// }
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(buf)
// io.Copy(ctx.Res, dataRc)
contentType, isTextFile := base.IsTextFile(buf)
_, isImageFile := base.IsImageFile(buf)
ctx.Resp.Header().Set("Content-Type", contentType)
if !isTextFile && !isImageFile {
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(treename))
ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
}
ctx.Resp.Write(buf)
io.Copy(ctx.Resp, dataRc)
}