feat: add headCoverArt helper for CAA HEAD requests

This commit is contained in:
deluan
2026-03-20 18:41:29 -04:00
parent 84d0c4e310
commit 0b728493c6
2 changed files with 77 additions and 0 deletions
+24
View File
@@ -12,6 +12,30 @@ import (
// Configuration key for uguu.se image hosting
const uguuEnabledKey = "uguuenabled"
const caaEnabledKey = "caaenabled"
// headCoverArt sends a HEAD request to the given CAA URL without following redirects.
// Returns the Location header value on 307 (image exists), or "" otherwise.
func headCoverArt(url string) string {
resp, err := host.HTTPSend(host.HTTPRequest{
Method: "HEAD",
URL: url,
NoFollowRedirects: true,
})
if err != nil {
pdk.Log(pdk.LogDebug, fmt.Sprintf("CAA HEAD request failed for %s: %v", url, err))
return ""
}
if resp.StatusCode != 307 {
return ""
}
location := resp.Headers["Location"]
if location == "" {
pdk.Log(pdk.LogWarn, fmt.Sprintf("CAA returned 307 but no Location header for %s", url))
}
return location
}
// uguu.se API response
type uguuResponse struct {
Success bool `json:"success"`