Added a MediaUploadService option to the configuration loader and documented it in the README so operators can pick the attachment backend (defaulting to Litterbox) straight from .env.
Refactored the Discord bridge to build a media service during initialization, route attachment uploads through it, and dynamically label the status embeds and error diagnostics based on the selected provider while preserving the existing progress messaging flow. Introduced a new media package that defines the uploader interface and ships a Litterbox implementation responsible for fetching Discord attachments and posting them to Catbox while reporting HTTP status codes back to the bridge.
This commit is contained in:
36
media/service.go
Normal file
36
media/service.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package media
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
const DefaultService = "litterbox"
|
||||
|
||||
// Service defines a pluggable uploader for Discord attachments.
|
||||
type Service interface {
|
||||
Name() string
|
||||
Upload(ctx context.Context, attachment *discordgo.MessageAttachment) (url string, statusCode int, err error)
|
||||
}
|
||||
|
||||
// NewService returns the configured media upload backend. Currently only
|
||||
// Litterbox is supported but the hook point allows future expansion.
|
||||
func NewService(name string, httpClient *http.Client) (Service, error) {
|
||||
if httpClient == nil {
|
||||
httpClient = &http.Client{}
|
||||
}
|
||||
normalized := strings.ToLower(strings.TrimSpace(name))
|
||||
if normalized == "" {
|
||||
normalized = DefaultService
|
||||
}
|
||||
switch normalized {
|
||||
case DefaultService:
|
||||
return &LitterboxService{client: httpClient}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown media upload service: %s", name)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user