diff options
author | gdeverlant <e.bekrek@yandex.com> | 2019-01-06 23:37:30 +0100 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2019-01-06 17:37:30 -0500 |
commit | d3dc07f282936849897f861346777b47c8c388d3 (patch) | |
tree | 2da810fc1d6671bf8659f9bf868e184698f0fc7c /routers | |
parent | dd006db5a719b33aef7887faab48718e4b0f2786 (diff) | |
download | gitea-d3dc07f282936849897f861346777b47c8c388d3.tar.gz gitea-d3dc07f282936849897f861346777b47c8c388d3.zip |
Added URL mapping for Release attachments like on github.com (#1707)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/repo.go | 32 | ||||
-rw-r--r-- | routers/routes/routes.go | 3 |
2 files changed, 35 insertions, 0 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 236d66bd1f..6071b7a54a 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -310,6 +310,38 @@ func Action(ctx *context.Context) { ctx.RedirectToFirst(ctx.Query("redirect_to"), ctx.Repo.RepoLink) } +// RedirectDownload return a file based on the following infos: +func RedirectDownload(ctx *context.Context) { + var ( + vTag = ctx.Params("vTag") + fileName = ctx.Params("fileName") + ) + tagNames := []string{vTag} + curRepo := ctx.Repo.Repository + releases, err := models.GetReleasesByRepoIDAndNames(curRepo.ID, tagNames) + if err != nil { + if models.IsErrAttachmentNotExist(err) { + ctx.Error(404) + return + } + ctx.ServerError("RedirectDownload", err) + return + } + if len(releases) == 1 { + release := releases[0] + att, err := models.GetAttachmentByReleaseIDFileName(release.ID, fileName) + if err != nil { + ctx.Error(404) + return + } + if att != nil { + ctx.Redirect(setting.AppSubURL + "/attachments/" + att.UUID) + return + } + } + ctx.Error(404) +} + // Download download an archive of a repository func Download(ctx *context.Context) { var ( diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 5d9a6b31f0..b776d0c201 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -475,6 +475,9 @@ func RegisterRoutes(m *macaron.Macaron) { }, context.RepoIDAssignment(), context.UnitTypes(), reqRepoCodeReader) }, reqSignIn) + // ***** Release Attachment Download without Signin + m.Get("/:username/:reponame/releases/download/:vTag/:fileName", ignSignIn, context.RepoAssignment(), repo.MustBeNotBare, repo.RedirectDownload) + m.Group("/:username/:reponame", func() { m.Group("/settings", func() { m.Combo("").Get(repo.Settings). |