Fix image signed URLs ignoring updated public base URL.
CI / docker (push) Failing after 10s

Resolve public_base_url at SignURL time so admin settings apply without restart.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
renjue
2026-06-24 14:34:22 +08:00
parent e761074fb9
commit 2665ac1dee
4 changed files with 45 additions and 15 deletions
+15 -8
View File
@@ -17,15 +17,22 @@ import (
)
type Store struct {
db *gorm.DB
baseDir string
signKey string
publicURL string
ttl time.Duration
db *gorm.DB
baseDir string
signKey string
publicURL func() string
ttl time.Duration
}
func New(db *gorm.DB, baseDir, publicURL, signKey string, ttl time.Duration) *Store {
return &Store{db: db, baseDir: baseDir, publicURL: strings.TrimRight(publicURL, "/"), signKey: signKey, ttl: ttl}
func New(db *gorm.DB, baseDir string, publicURL func() string, signKey string, ttl time.Duration) *Store {
return &Store{db: db, baseDir: baseDir, publicURL: publicURL, signKey: signKey, ttl: ttl}
}
func (s *Store) baseURL() string {
if s.publicURL == nil {
return ""
}
return strings.TrimRight(s.publicURL(), "/")
}
func (s *Store) EnsureDir() error {
@@ -76,7 +83,7 @@ func (s *Store) ListByPrediction(predictionID string) ([]model.StoredImage, erro
func (s *Store) SignURL(imageID string) string {
exp := time.Now().Add(s.ttl).Unix()
sig := s.sign(imageID, exp)
return fmt.Sprintf("%s/files/%s?exp=%d&sig=%s", s.publicURL, imageID, exp, sig)
return fmt.Sprintf("%s/files/%s?exp=%d&sig=%s", s.baseURL(), imageID, exp, sig)
}
func (s *Store) Verify(imageID string, exp int64, sig string) bool {