mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-03 03:23:25 +09:00
fix: correct repo/attatchment absolute url and release layout (#39178)
This commit is contained in:
@@ -4,30 +4,32 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
repo_model "gitea.dev/models/repo"
|
||||
api "gitea.dev/modules/structs"
|
||||
)
|
||||
|
||||
func WebAssetDownloadURL(repo *repo_model.Repository, attach *repo_model.Attachment) string {
|
||||
return attach.DownloadURL()
|
||||
func WebAssetDownloadURL(ctx context.Context, repo *repo_model.Repository, attach *repo_model.Attachment) string {
|
||||
return attach.DownloadURL(ctx)
|
||||
}
|
||||
|
||||
func APIAssetDownloadURL(repo *repo_model.Repository, attach *repo_model.Attachment) string {
|
||||
return attach.DownloadURL()
|
||||
func APIAssetDownloadURL(ctx context.Context, repo *repo_model.Repository, attach *repo_model.Attachment) string {
|
||||
return attach.DownloadURL(ctx)
|
||||
}
|
||||
|
||||
// ToAttachment converts models.Attachment to api.Attachment for API usage
|
||||
func ToAttachment(repo *repo_model.Repository, a *repo_model.Attachment) *api.Attachment {
|
||||
return toAttachment(repo, a, WebAssetDownloadURL)
|
||||
func ToAttachment(ctx context.Context, repo *repo_model.Repository, a *repo_model.Attachment) *api.Attachment {
|
||||
return toAttachment(ctx, repo, a, WebAssetDownloadURL)
|
||||
}
|
||||
|
||||
// ToAPIAttachment converts models.Attachment to api.Attachment for API usage
|
||||
func ToAPIAttachment(repo *repo_model.Repository, a *repo_model.Attachment) *api.Attachment {
|
||||
return toAttachment(repo, a, APIAssetDownloadURL)
|
||||
func ToAPIAttachment(ctx context.Context, repo *repo_model.Repository, a *repo_model.Attachment) *api.Attachment {
|
||||
return toAttachment(ctx, repo, a, APIAssetDownloadURL)
|
||||
}
|
||||
|
||||
// toAttachment converts models.Attachment to api.Attachment for API usage
|
||||
func toAttachment(repo *repo_model.Repository, a *repo_model.Attachment, getDownloadURL func(repo *repo_model.Repository, attach *repo_model.Attachment) string) *api.Attachment {
|
||||
func toAttachment(ctx context.Context, repo *repo_model.Repository, a *repo_model.Attachment, getDownloadURL func(ctx context.Context, repo *repo_model.Repository, attach *repo_model.Attachment) string) *api.Attachment {
|
||||
return &api.Attachment{
|
||||
ID: a.ID,
|
||||
Name: a.Name,
|
||||
@@ -35,18 +37,18 @@ func toAttachment(repo *repo_model.Repository, a *repo_model.Attachment, getDown
|
||||
DownloadCount: a.DownloadCount,
|
||||
Size: a.Size,
|
||||
UUID: a.UUID,
|
||||
DownloadURL: getDownloadURL(repo, a), // for web request json and api request json, return different download urls
|
||||
DownloadURL: getDownloadURL(ctx, repo, a), // for web/api requests, return different download URLs
|
||||
}
|
||||
}
|
||||
|
||||
func ToAPIAttachments(repo *repo_model.Repository, attachments []*repo_model.Attachment) []*api.Attachment {
|
||||
return toAttachments(repo, attachments, APIAssetDownloadURL)
|
||||
func ToAPIAttachments(ctx context.Context, repo *repo_model.Repository, attachments []*repo_model.Attachment) []*api.Attachment {
|
||||
return toAttachments(ctx, repo, attachments, APIAssetDownloadURL)
|
||||
}
|
||||
|
||||
func toAttachments(repo *repo_model.Repository, attachments []*repo_model.Attachment, getDownloadURL func(repo *repo_model.Repository, attach *repo_model.Attachment) string) []*api.Attachment {
|
||||
func toAttachments(ctx context.Context, repo *repo_model.Repository, attachments []*repo_model.Attachment, getDownloadURL func(ctx context.Context, repo *repo_model.Repository, attach *repo_model.Attachment) string) []*api.Attachment {
|
||||
converted := make([]*api.Attachment, 0, len(attachments))
|
||||
for _, attachment := range attachments {
|
||||
converted = append(converted, toAttachment(repo, attachment, getDownloadURL))
|
||||
converted = append(converted, toAttachment(ctx, repo, attachment, getDownloadURL))
|
||||
}
|
||||
return converted
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func ToAPIIssue(ctx context.Context, doer *user_model.User, issue *issues_model.
|
||||
return toIssue(ctx, doer, issue, APIAssetDownloadURL)
|
||||
}
|
||||
|
||||
func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, getDownloadURL func(repo *repo_model.Repository, attach *repo_model.Attachment) string) *api.Issue {
|
||||
func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, getDownloadURL func(ctx context.Context, repo *repo_model.Repository, attach *repo_model.Attachment) string) *api.Issue {
|
||||
if err := issue.LoadPoster(ctx); err != nil {
|
||||
return &api.Issue{}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Iss
|
||||
Poster: ToUser(ctx, issue.Poster, doer),
|
||||
Title: issue.Title,
|
||||
Body: issue.Content,
|
||||
Attachments: toAttachments(issue.Repo, issue.Attachments, getDownloadURL),
|
||||
Attachments: toAttachments(ctx, issue.Repo, issue.Attachments, getDownloadURL),
|
||||
Ref: issue.Ref,
|
||||
State: issue.State(),
|
||||
IsLocked: issue.IsLocked,
|
||||
|
||||
@@ -23,7 +23,7 @@ func ToAPIComment(ctx context.Context, repo *repo_model.Repository, c *issues_mo
|
||||
IssueURL: c.IssueURL(ctx),
|
||||
PRURL: c.PRURL(ctx),
|
||||
Body: c.Content,
|
||||
Attachments: ToAPIAttachments(repo, c.Attachments),
|
||||
Attachments: ToAPIAttachments(ctx, repo, c.Attachments),
|
||||
Created: c.CreatedUnix.AsTime(),
|
||||
Updated: c.UpdatedUnix.AsTime(),
|
||||
}
|
||||
|
||||
@@ -29,6 +29,6 @@ func ToAPIRelease(ctx context.Context, repo *repo_model.Repository, r *repo_mode
|
||||
CreatedAt: r.CreatedUnix.AsTime(),
|
||||
PublishedAt: util.Iif(r.IsDraft, nil, r.PublishedUnix.AsTimePtr()),
|
||||
Publisher: ToUser(ctx, r.Publisher, nil),
|
||||
Attachments: ToAPIAttachments(repo, r.Attachments),
|
||||
Attachments: ToAPIAttachments(ctx, repo, r.Attachments),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user