feat(19.3-03): storage.uploads.public_url for direct bucket or CDN file URLs

- OpenBucket validates public_url (absolute http/https, host, no user info, query
  or fragment; the error names the key) and records it next to public_path_prefix
- a set public_url logs one start-up line: the bucket behind it must hold only
  public files, since it bypasses the is_public check
- attach.PublicURLBase; PublicURL, File.URL and thumbnail URLs use the base when
  set and keep the public_path_prefix proxy URLs otherwise
- TestPublicURLSmoke; storage Public URL base section, attachments, configuration
  and lagoon README
This commit is contained in:
Jakub Zych
2026-10-15 18:13:00 +02:00
parent 2e22e9f9a6
commit 2e87efae54
7 changed files with 127 additions and 9 deletions

View File

@@ -76,13 +76,18 @@ func fileExt(diskName string) string {
return strings.ToLower(ext)
}
// PublicURL returns the public URL of a blob key: storage.uploads.
// public_path_prefix and the key joined by exactly one slash. With the
// WinterCMS layout (bucket rooted at storage/app/uploads/public, prefix
// /storage/app/uploads/public) it is Winter's File::getPath() path.
// PublicURL returns the public URL of a blob key. With
// storage.uploads.public_url set (PublicURLBase) it is that base and the key
// joined by exactly one slash. Otherwise it is
// storage.uploads.public_path_prefix and the key joined the same way; with
// the WinterCMS layout (bucket rooted at storage/app/uploads/public, prefix
// /storage/app/uploads/public) that is Winter's File::getPath() path.
func PublicURL(key string) string {
prefix := strings.TrimRight(PublicPathPrefix(), "/")
key = strings.TrimLeft(key, "/")
if base := PublicURLBase(); base != "" {
return strings.TrimRight(base, "/") + "/" + key
}
prefix := strings.TrimRight(PublicPathPrefix(), "/")
if prefix == "" {
return "/" + key
}