@@ -15,9 +15,7 @@ import (
15
15
"time"
16
16
17
17
git_model "code.gitea.io/gitea/models/git"
18
- repo_model "code.gitea.io/gitea/models/repo"
19
18
"code.gitea.io/gitea/modules/git"
20
- "code.gitea.io/gitea/modules/gitrepo"
21
19
"code.gitea.io/gitea/modules/httpcache"
22
20
"code.gitea.io/gitea/modules/json"
23
21
"code.gitea.io/gitea/modules/lfs"
@@ -31,7 +29,6 @@ import (
31
29
"code.gitea.io/gitea/routers/common"
32
30
"code.gitea.io/gitea/services/context"
33
31
pull_service "code.gitea.io/gitea/services/pull"
34
- archiver_service "code.gitea.io/gitea/services/repository/archiver"
35
32
files_service "code.gitea.io/gitea/services/repository/files"
36
33
)
37
34
@@ -282,74 +279,7 @@ func GetArchive(ctx *context.APIContext) {
282
279
// "404":
283
280
// "$ref": "#/responses/notFound"
284
281
285
- if ctx .Repo .GitRepo == nil {
286
- var err error
287
- ctx .Repo .GitRepo , err = gitrepo .RepositoryFromRequestContextOrOpen (ctx , ctx .Repo .Repository )
288
- if err != nil {
289
- ctx .APIErrorInternal (err )
290
- return
291
- }
292
- }
293
-
294
- archiveDownload (ctx )
295
- }
296
-
297
- func archiveDownload (ctx * context.APIContext ) {
298
- aReq , err := archiver_service .NewRequest (ctx .Repo .Repository .ID , ctx .Repo .GitRepo , ctx .PathParam ("*" ))
299
- if err != nil {
300
- if errors .Is (err , archiver_service.ErrUnknownArchiveFormat {}) {
301
- ctx .APIError (http .StatusBadRequest , err )
302
- } else if errors .Is (err , archiver_service.RepoRefNotFoundError {}) {
303
- ctx .APIError (http .StatusNotFound , err )
304
- } else {
305
- ctx .APIErrorInternal (err )
306
- }
307
- return
308
- }
309
-
310
- archiver , err := aReq .Await (ctx )
311
- if err != nil {
312
- ctx .APIErrorInternal (err )
313
- return
314
- }
315
-
316
- download (ctx , aReq .GetArchiveName (), archiver )
317
- }
318
-
319
- func download (ctx * context.APIContext , archiveName string , archiver * repo_model.RepoArchiver ) {
320
- downloadName := ctx .Repo .Repository .Name + "-" + archiveName
321
-
322
- // Add nix format link header so tarballs lock correctly:
323
- // https://github.com/nixos/nix/blob/56763ff918eb308db23080e560ed2ea3e00c80a7/doc/manual/src/protocols/tarball-fetcher.md
324
- ctx .Resp .Header ().Add ("Link" , fmt .Sprintf (`<%s/archive/%s.%s?rev=%s>; rel="immutable"` ,
325
- ctx .Repo .Repository .APIURL (),
326
- archiver .CommitID ,
327
- archiver .Type .String (),
328
- archiver .CommitID ,
329
- ))
330
-
331
- rPath := archiver .RelativePath ()
332
- if setting .RepoArchive .Storage .ServeDirect () {
333
- // If we have a signed url (S3, object storage), redirect to this directly.
334
- u , err := storage .RepoArchives .URL (rPath , downloadName , ctx .Req .Method , nil )
335
- if u != nil && err == nil {
336
- ctx .Redirect (u .String ())
337
- return
338
- }
339
- }
340
-
341
- // If we have matched and access to release or issue
342
- fr , err := storage .RepoArchives .Open (rPath )
343
- if err != nil {
344
- ctx .APIErrorInternal (err )
345
- return
346
- }
347
- defer fr .Close ()
348
-
349
- ctx .ServeContent (fr , & context.ServeHeaderOptions {
350
- Filename : downloadName ,
351
- LastModified : archiver .CreatedUnix .AsLocalTime (),
352
- })
282
+ serveRepoArchive (ctx , ctx .PathParam ("*" ))
353
283
}
354
284
355
285
// GetEditorconfig get editor config of a repository
0 commit comments