mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	zip archive download
This commit is contained in:
		@@ -145,7 +145,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if entry != nil && entry.IsFile() {
 | 
			
		||||
	if entry != nil && !entry.IsDir() {
 | 
			
		||||
		blob := entry.Blob()
 | 
			
		||||
 | 
			
		||||
		if data, err := blob.Data(); err != nil {
 | 
			
		||||
@@ -154,7 +154,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
 | 
			
		||||
			ctx.Data["FileSize"] = blob.Size()
 | 
			
		||||
			ctx.Data["IsFile"] = true
 | 
			
		||||
			ctx.Data["FileName"] = blob.Name
 | 
			
		||||
			ext := path.Ext(blob.Name)
 | 
			
		||||
			ext := path.Ext(blob.Name())
 | 
			
		||||
			if len(ext) > 0 {
 | 
			
		||||
				ext = ext[1:]
 | 
			
		||||
			}
 | 
			
		||||
@@ -168,7 +168,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
 | 
			
		||||
			if isImageFile {
 | 
			
		||||
				ctx.Data["IsImageFile"] = true
 | 
			
		||||
			} else {
 | 
			
		||||
				readmeExist := base.IsMarkdownFile(blob.Name) || base.IsReadmeFile(blob.Name)
 | 
			
		||||
				readmeExist := base.IsMarkdownFile(blob.Name()) || base.IsReadmeFile(blob.Name())
 | 
			
		||||
				ctx.Data["ReadmeExist"] = readmeExist
 | 
			
		||||
				if readmeExist {
 | 
			
		||||
					ctx.Data["FileContent"] = string(base.RenderMarkdown(data, ""))
 | 
			
		||||
@@ -193,7 +193,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
 | 
			
		||||
		files := make([][]interface{}, 0, len(entries))
 | 
			
		||||
 | 
			
		||||
		for _, te := range entries {
 | 
			
		||||
			c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name))
 | 
			
		||||
			c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name()))
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				ctx.Handle(404, "repo.Single(SubTree)", err)
 | 
			
		||||
				return
 | 
			
		||||
@@ -207,7 +207,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
 | 
			
		||||
		var readmeFile *git.Blob
 | 
			
		||||
 | 
			
		||||
		for _, f := range entries {
 | 
			
		||||
			if !f.IsFile() || !base.IsReadmeFile(f.Name) {
 | 
			
		||||
			if f.IsDir() || !base.IsReadmeFile(f.Name()) {
 | 
			
		||||
				continue
 | 
			
		||||
			} else {
 | 
			
		||||
				readmeFile = f.Blob()
 | 
			
		||||
@@ -260,32 +260,6 @@ func Single(ctx *middleware.Context, params martini.Params) {
 | 
			
		||||
	ctx.HTML(200, "repo/single")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func SingleDownload(ctx *middleware.Context, params martini.Params) {
 | 
			
		||||
	// Get tree path
 | 
			
		||||
	treename := params["_1"]
 | 
			
		||||
 | 
			
		||||
	blob, err := ctx.Repo.Commit.GetBlobByPath(treename)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Handle(404, "repo.SingleDownload(GetBlobByPath)", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	data, err := blob.Data()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Handle(404, "repo.SingleDownload(Data)", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	contentType, isTextFile := base.IsTextFile(data)
 | 
			
		||||
	_, isImageFile := base.IsImageFile(data)
 | 
			
		||||
	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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func basicEncode(username, password string) string {
 | 
			
		||||
	auth := username + ":" + password
 | 
			
		||||
	return base64.StdEncoding.EncodeToString([]byte(auth))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user