Config: Update CSP header to allow loading content from a CDN #3454

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2023-06-07 09:22:10 +02:00
parent dda00ba239
commit 59bf7cb9bd
2 changed files with 25 additions and 0 deletions

View file

@ -429,6 +429,17 @@ func (c *Config) CdnUrl(res string) string {
return strings.TrimRight(c.options.CdnUrl, "/") + res
}
// CdnDomain returns the content delivery network domain name if specified.
func (c *Config) CdnDomain() string {
if c.options.CdnUrl == "" {
return ""
} else if u, err := url.Parse(c.options.CdnUrl); err != nil {
return ""
} else {
return u.Hostname()
}
}
// CdnVideo checks if videos should be streamed using the configured CDN.
func (c *Config) CdnVideo() bool {
if c.options.CdnUrl == "" {

View file

@ -440,6 +440,20 @@ func TestConfig_CdnUrl(t *testing.T) {
assert.Equal(t, "http://foo:2342/foo/", c.CdnUrl("/"))
}
func TestConfig_CdnDomain(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, "", c.CdnDomain())
c.options.CdnUrl = "http://superhost:2342/"
assert.Equal(t, "superhost", c.CdnDomain())
c.options.CdnUrl = "https://foo.bar.com:2342/foo/"
assert.Equal(t, "foo.bar.com", c.CdnDomain())
c.options.CdnUrl = "http:/invalid:2342/foo/"
assert.Equal(t, "", c.CdnDomain())
c.options.CdnUrl = ""
assert.Equal(t, "", c.CdnDomain())
}
func TestConfig_CdnVideo(t *testing.T) {
c := NewConfig(CliTestContext())