Skip to content

Commit 6d710e7

Browse files
committed
Fix missed method DownloadArchive
1 parent 9f48582 commit 6d710e7

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

routers/api/v1/repo/download.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"code.gitea.io/gitea/modules/git"
1010
"code.gitea.io/gitea/modules/gitrepo"
11+
"code.gitea.io/gitea/modules/setting"
1112
"code.gitea.io/gitea/services/context"
1213
archiver_service "code.gitea.io/gitea/services/repository/archiver"
1314
)
@@ -41,11 +42,18 @@ func DownloadArchive(ctx *context.APIContext) {
4142
return
4243
}
4344

45+
downloadName := prepareDownload(ctx, r)
46+
47+
if setting.Repository.StreamArchives {
48+
streamDownload(ctx, downloadName, r)
49+
return
50+
}
51+
4452
archive, err := r.Await(ctx)
4553
if err != nil {
4654
ctx.APIErrorInternal(err)
4755
return
4856
}
4957

50-
download(ctx, r.GetArchiveName(), archive)
58+
download(ctx, downloadName, archive)
5159
}

routers/api/v1/repo/file.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,23 @@ func archiveDownload(ctx *context.APIContext) {
307307
return
308308
}
309309

310+
downloadName := prepareDownload(ctx, aReq)
311+
312+
if setting.Repository.StreamArchives {
313+
streamDownload(ctx, downloadName, aReq)
314+
return
315+
}
316+
317+
archiver, err := aReq.Await(ctx)
318+
if err != nil {
319+
ctx.APIErrorInternal(err)
320+
return
321+
}
322+
323+
download(ctx, downloadName, archiver)
324+
}
325+
326+
func prepareDownload(ctx *context.APIContext, aReq *archiver_service.ArchiveRequest) (downloadName string) {
310327
// Add nix format link header so tarballs lock correctly:
311328
// https://github.com/nixos/nix/blob/56763ff918eb308db23080e560ed2ea3e00c80a7/doc/manual/src/protocols/tarball-fetcher.md
312329
ctx.Resp.Header().Add("Link", fmt.Sprintf(`<%s/archive/%s.%s?rev=%s>; rel="immutable"`,
@@ -316,26 +333,17 @@ func archiveDownload(ctx *context.APIContext) {
316333
aReq.CommitID,
317334
))
318335

319-
downloadName := ctx.Repo.Repository.Name + "-" + aReq.GetArchiveName()
320-
321-
if setting.Repository.StreamArchives {
322-
ctx.SetServeHeaders(&context.ServeHeaderOptions{
323-
Filename: downloadName,
324-
})
336+
return ctx.Repo.Repository.Name + "-" + aReq.GetArchiveName()
337+
}
325338

326-
if err := aReq.Stream(ctx, ctx.Repo.GitRepo, ctx.Resp); err != nil && !ctx.Written() {
327-
ctx.APIErrorInternal(err)
328-
}
329-
return
330-
}
339+
func streamDownload(ctx *context.APIContext, downloadName string, r *archiver_service.ArchiveRequest) {
340+
ctx.SetServeHeaders(&context.ServeHeaderOptions{
341+
Filename: downloadName,
342+
})
331343

332-
archiver, err := aReq.Await(ctx)
333-
if err != nil {
344+
if err := r.Stream(ctx, ctx.Repo.GitRepo, ctx.Resp); err != nil && !ctx.Written() {
334345
ctx.APIErrorInternal(err)
335-
return
336346
}
337-
338-
download(ctx, downloadName, archiver)
339347
}
340348

341349
func download(ctx *context.APIContext, downloadName string, archiver *repo_model.RepoArchiver) {

0 commit comments

Comments
 (0)