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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user