mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-02 02:53:23 +09:00
fix: correct repo/attatchment absolute url and release layout (#39178)
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"path"
|
||||
|
||||
"gitea.dev/models/db"
|
||||
"gitea.dev/modules/httplib"
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/storage"
|
||||
@@ -62,12 +63,13 @@ func (a *Attachment) RelativePath() string {
|
||||
}
|
||||
|
||||
// DownloadURL returns the download url of the attached file
|
||||
func (a *Attachment) DownloadURL() string {
|
||||
func (a *Attachment) DownloadURL(optCtx ...context.Context) string {
|
||||
// mail template doesn't have context, so we need to use a default one
|
||||
ctx := util.OptionalArg(optCtx, context.TODO())
|
||||
if a.CustomDownloadURL != "" {
|
||||
return a.CustomDownloadURL
|
||||
}
|
||||
|
||||
return setting.AppURL + "attachments/" + url.PathEscape(a.UUID)
|
||||
return httplib.MakeAbsoluteURL(ctx, setting.AppSubURL+"/attachments/"+url.PathEscape(a.UUID))
|
||||
}
|
||||
|
||||
// ErrAttachmentNotExist represents a "AttachmentNotExist" kind of error.
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestAttachment_DownloadURL(t *testing.T) {
|
||||
UUID: "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11",
|
||||
ID: 1,
|
||||
}
|
||||
assert.Equal(t, "https://try.gitea.io/attachments/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach.DownloadURL())
|
||||
assert.Equal(t, "https://try.gitea.io/attachments/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach.DownloadURL(t.Context()))
|
||||
}
|
||||
|
||||
func TestUpdateAttachment(t *testing.T) {
|
||||
|
||||
@@ -433,7 +433,7 @@ func GetReleaseAttachments(ctx context.Context, rels ...*Release) (err error) {
|
||||
// If the names unique, use the URL with the Name instead of the UUID
|
||||
if !hasDuplicateName(release.Attachments) {
|
||||
for _, attachment := range release.Attachments {
|
||||
attachment.CustomDownloadURL = release.Repo.HTMLURL() + "/releases/download/" + url.PathEscape(release.TagName) + "/" + url.PathEscape(attachment.Name)
|
||||
attachment.CustomDownloadURL = release.Repo.HTMLURL(ctx) + "/releases/download/" + url.PathEscape(release.TagName) + "/" + url.PathEscape(attachment.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user