schedualer fix for files

This commit is contained in:
Enki 2025-05-11 23:06:28 -07:00
parent 3f15f1f78d
commit 48b6e22763

View File

@ -27,6 +27,7 @@ type MediaUploader interface {
UploadFile(filePath string, caption string, altText string) (string, string, error) UploadFile(filePath string, caption string, altText string) (string, string, error)
DeleteFile(fileHash string) error DeleteFile(fileHash string) error
WithCustomURL(customURL string) MediaUploader WithCustomURL(customURL string) MediaUploader
GetServerURL() string
} }
// PostPublisher defines the interface for publishing posts // PostPublisher defines the interface for publishing posts
@ -247,8 +248,30 @@ func (s *Scheduler) ScheduleBot(bot *models.Bot) error {
var uploader MediaUploader var uploader MediaUploader
if bot.MediaConfig.PrimaryService == "blossom" { if bot.MediaConfig.PrimaryService == "blossom" {
uploader = s.blossomUploader uploader = s.blossomUploader
// Use custom URL only if it's not empty
if bot.MediaConfig.BlossomServerURL != "" {
s.logger.Info("Using custom Blossom server URL",
zap.Int64("bot_id", bot.ID),
zap.String("url", bot.MediaConfig.BlossomServerURL))
uploader = uploader.WithCustomURL(bot.MediaConfig.BlossomServerURL)
} else {
s.logger.Info("Using default Blossom server URL",
zap.Int64("bot_id", bot.ID),
zap.String("url", s.blossomUploader.GetServerURL()))
}
} else { } else {
uploader = s.nip94Uploader uploader = s.nip94Uploader
// Use custom URL only if it's not empty
if bot.MediaConfig.Nip94ServerURL != "" {
s.logger.Info("Using custom NIP-94 server URL",
zap.Int64("bot_id", bot.ID),
zap.String("url", bot.MediaConfig.Nip94ServerURL))
uploader = uploader.WithCustomURL(bot.MediaConfig.Nip94ServerURL)
} else {
s.logger.Info("Using default NIP-94 server URL",
zap.Int64("bot_id", bot.ID),
zap.String("url", s.nip94Uploader.GetServerURL()))
}
} }
// Upload the file // Upload the file
@ -264,8 +287,30 @@ func (s *Scheduler) ScheduleBot(bot *models.Bot) error {
if bot.MediaConfig.FallbackService == "blossom" { if bot.MediaConfig.FallbackService == "blossom" {
uploader = s.blossomUploader uploader = s.blossomUploader
// Use custom URL only if it's not empty
if bot.MediaConfig.BlossomServerURL != "" {
s.logger.Info("Using custom Blossom server URL for fallback",
zap.Int64("bot_id", bot.ID),
zap.String("url", bot.MediaConfig.BlossomServerURL))
uploader = uploader.WithCustomURL(bot.MediaConfig.BlossomServerURL)
} else {
s.logger.Info("Using default Blossom server URL for fallback",
zap.Int64("bot_id", bot.ID),
zap.String("url", s.blossomUploader.GetServerURL()))
}
} else { } else {
uploader = s.nip94Uploader uploader = s.nip94Uploader
// Use custom URL only if it's not empty
if bot.MediaConfig.Nip94ServerURL != "" {
s.logger.Info("Using custom NIP-94 server URL for fallback",
zap.Int64("bot_id", bot.ID),
zap.String("url", bot.MediaConfig.Nip94ServerURL))
uploader = uploader.WithCustomURL(bot.MediaConfig.Nip94ServerURL)
} else {
s.logger.Info("Using default NIP-94 server URL for fallback",
zap.Int64("bot_id", bot.ID),
zap.String("url", s.nip94Uploader.GetServerURL()))
}
} }
mediaURL, mediaHash, err = uploader.UploadFile(contentPath, "", "") mediaURL, mediaHash, err = uploader.UploadFile(contentPath, "", "")