From 1f3596a7fef0ad94f70557cbd653a133536a42f6 Mon Sep 17 00:00:00 2001 From: Kemal Zebari Date: Thu, 30 May 2024 11:41:30 -0700 Subject: [PATCH 1/3] Have repo API return the empty URL string when a repo has no avatar --- models/repo/avatar.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/models/repo/avatar.go b/models/repo/avatar.go index 8395b8c2b741..86e48bd5c4a6 100644 --- a/models/repo/avatar.go +++ b/models/repo/avatar.go @@ -84,7 +84,13 @@ func (repo *Repository) relAvatarLink(ctx context.Context) string { return setting.AppSubURL + "/repo-avatars/" + url.PathEscape(repo.Avatar) } -// AvatarLink returns the full avatar url with http host. TODO: refactor it to a relative URL, but it is still used in API response at the moment +// AvatarLink returns the full avatar url with http host or the empty string if the repo doesn't have an avatar. +// +// TODO: refactor it to a relative URL, but it is still used in API response at the moment func (repo *Repository) AvatarLink(ctx context.Context) string { - return httplib.MakeAbsoluteURL(ctx, repo.relAvatarLink(ctx)) + relLink := repo.relAvatarLink(ctx) + if len(relLink) > 0 { + return httplib.MakeAbsoluteURL(ctx, repo.relAvatarLink(ctx)) + } + return "" } From ead1d891c270ae0c863fb3f23030171037ca1698 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 31 May 2024 09:59:27 +0800 Subject: [PATCH 2/3] Update models/repo/avatar.go --- models/repo/avatar.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo/avatar.go b/models/repo/avatar.go index 86e48bd5c4a6..7400bf3ec886 100644 --- a/models/repo/avatar.go +++ b/models/repo/avatar.go @@ -89,7 +89,7 @@ func (repo *Repository) relAvatarLink(ctx context.Context) string { // TODO: refactor it to a relative URL, but it is still used in API response at the moment func (repo *Repository) AvatarLink(ctx context.Context) string { relLink := repo.relAvatarLink(ctx) - if len(relLink) > 0 { + if relLink != "" { return httplib.MakeAbsoluteURL(ctx, repo.relAvatarLink(ctx)) } return "" From 213b60794a537c17d6d7b309f83808d5bf28c614 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 31 May 2024 10:18:19 +0800 Subject: [PATCH 3/3] Update models/repo/avatar.go --- models/repo/avatar.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo/avatar.go b/models/repo/avatar.go index 7400bf3ec886..ccfac12cad1a 100644 --- a/models/repo/avatar.go +++ b/models/repo/avatar.go @@ -90,7 +90,7 @@ func (repo *Repository) relAvatarLink(ctx context.Context) string { func (repo *Repository) AvatarLink(ctx context.Context) string { relLink := repo.relAvatarLink(ctx) if relLink != "" { - return httplib.MakeAbsoluteURL(ctx, repo.relAvatarLink(ctx)) + return httplib.MakeAbsoluteURL(ctx, relLink) } return "" }