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.
37 lines
919 B
Go
37 lines
919 B
Go
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)
|
|
}
|
|
}
|