diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index a1e1346b38c4b..5677c22b1843d 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -367,6 +367,34 @@ func acceptOrRejectRepoTransfer(ctx *context.Context, accept bool) error { return nil } +// RedirectDownload return a file from the latest of the repo releases: +func RedirectDownloadLatest(ctx *context.Context) { + var ( + fileName = ctx.Params("fileName") + ) + curRepo := ctx.Repo.Repository + release, err := repo_model.GetLatestReleaseByRepoID(curRepo.ID) + if err != nil { + if repo_model.IsErrAttachmentNotExist(err) { + ctx.Error(http.StatusNotFound) + return + } + ctx.ServerError("RedirectDownloadLatest", err) + return + } + + att, err := repo_model.GetAttachmentByReleaseIDFileName(ctx, release.ID, fileName) + if err != nil { + ctx.Error(http.StatusNotFound) + return + } + if att != nil { + ServeAttachment(ctx, att.UUID) + return + } + ctx.Error(http.StatusNotFound) +} + // RedirectDownload return a file based on the following infos: func RedirectDownload(ctx *context.Context) { var ( diff --git a/routers/web/web.go b/routers/web/web.go index 26ad2d54c3a32..acc701c66baef 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -870,6 +870,8 @@ func registerRoutes(m *web.Route) { // ***** Release Attachment Download without Signin m.Get("/{username}/{reponame}/releases/download/{vTag}/{fileName}", ignSignIn, context.RepoAssignment, repo.MustBeNotEmpty, repo.RedirectDownload) + // **** Latest release Attachment Download without Signin + m.Get("/{username}/{reponame}/releases/latest/{fileName}", ignSignIn, context.RepoAssignment, repo.MustBeNotEmpty, repo.RedirectDownloadLatest) m.Group("/{username}/{reponame}", func() { m.Group("/settings", func() {