Skip to content

Commit a7d9a70

Browse files
merlleuwxiaoguang
andauthored
allow "latest" to be used in release vTag when downloading file (#26748)
Hello, In the discord I saw [someone](https://discord.com/channels/322538954119184384/1069795723178160168/1145061200644800514) complaining that you can't use the "latest" keyword as release tag to download a specific file: In his example: https://www.uberwald.me/gitea/public/fvtt-ecryme/releases/latest/system.json However the latest keyword works for the release page, so I think it's a good thing to implement this on the release attachment download url too. --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 9b0743a commit a7d9a70

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

routers/web/repo/repo.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,6 @@ func RedirectDownload(ctx *context.Context) {
378378
curRepo := ctx.Repo.Repository
379379
releases, err := repo_model.GetReleasesByRepoIDAndNames(ctx, curRepo.ID, tagNames)
380380
if err != nil {
381-
if repo_model.IsErrAttachmentNotExist(err) {
382-
ctx.Error(http.StatusNotFound)
383-
return
384-
}
385381
ctx.ServerError("RedirectDownload", err)
386382
return
387383
}
@@ -396,6 +392,23 @@ func RedirectDownload(ctx *context.Context) {
396392
ServeAttachment(ctx, att.UUID)
397393
return
398394
}
395+
} else if len(releases) == 0 && vTag == "latest" {
396+
// GitHub supports the alias "latest" for the latest release
397+
// We only fetch the latest release if the tag is "latest" and no release with the tag "latest" exists
398+
release, err := repo_model.GetLatestReleaseByRepoID(ctx.Repo.Repository.ID)
399+
if err != nil {
400+
ctx.Error(http.StatusNotFound)
401+
return
402+
}
403+
att, err := repo_model.GetAttachmentByReleaseIDFileName(ctx, release.ID, fileName)
404+
if err != nil {
405+
ctx.Error(http.StatusNotFound)
406+
return
407+
}
408+
if att != nil {
409+
ServeAttachment(ctx, att.UUID)
410+
return
411+
}
399412
}
400413
ctx.Error(http.StatusNotFound)
401414
}

0 commit comments

Comments
 (0)