fix: the avatar and logo URL fallback follows the configured public path

When the thumbnail fails, AvatarURL and OrganisationLogoURL answered
"/" + the blob key, which skips storage.uploads.public_path_prefix and
public_url (a 404 with the WinterCMS layout). They now answer the
original's attach.File.URL.
This commit is contained in:
2026-10-23 21:11:04 +02:00
parent b929ba9f33
commit 9730110d55
5 changed files with 37 additions and 11 deletions

View File

@@ -18,8 +18,9 @@ import (
// AvatarURL returns the display picture URL of user at size pixels, the
// rule the user API payload follows: the thumbnail (size by size, mode
// auto) of the user's avatar attachment when there is one and a file
// bucket is published, the attachment's file path when the thumbnail
// fails (logged), and otherwise the gravatar URL
// bucket is published, the original file's public URL (attach.File.URL,
// following storage.uploads.public_path_prefix and public_url) when the
// thumbnail fails (logged), and otherwise the gravatar URL
// //www.gravatar.com/avatar/{md5 of the email}?s={size}&d=mm. The URL may
// be protocol-relative or relative; a caller that needs an absolute URL
// resolves it. Only a failing database lookup is an error.
@@ -52,7 +53,7 @@ func AvatarURL(ctx context.Context, app *backpack.App, user *models.User, size i
url, err := f.Thumb(ctx, bucket, size, size, "auto")
if err != nil {
pluginLog.Error("golem15.user: avatar thumb", "err", err)
return "/" + attach.BlobKey(f.DiskName), nil
return f.URL(), nil
}
return url, nil
}

View File

@@ -40,8 +40,9 @@ func organisationLogo(ctx context.Context, app *backpack.App, org *models.Organi
// OrganisationLogoURL returns the URL of the organisation's logo at size
// pixels, the way AvatarURL serves a user's picture: the thumbnail (size by
// size, mode auto) of the logo attachment, or the attachment's file path
// when the thumbnail fails (logged). It answers false when the organisation
// size, mode auto) of the logo attachment, or the original file's public
// URL (attach.File.URL, which follows storage.uploads.public_path_prefix and
// public_url) when the thumbnail fails (logged). It answers false when the organisation
// has no logo or no file bucket is published. The URL may be relative; a
// caller that needs an absolute URL resolves it. Only a failing database
// lookup is an error.
@@ -57,7 +58,7 @@ func OrganisationLogoURL(ctx context.Context, app *backpack.App, org *models.Org
url, err := f.Thumb(ctx, bucket, size, size, "auto")
if err != nil {
pluginLog.Error("golem15.user: organisation logo thumb", "err", err)
return "/" + attach.BlobKey(f.DiskName), true, nil
return f.URL(), true, nil
}
return url, true, nil
}