upload

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAttachmentPreviewSize = 350
)

Variables

View Source
var (
	ErrPlaceholderNotFound = errors.New("upload placeholder not found")
	ErrForbidden           = errors.New("upload forbidden")
	ErrAlreadyDone         = errors.New("upload already completed")
	ErrEmptyBody           = errors.New("upload body is empty")
	ErrSizeMismatch        = errors.New("upload size mismatch")
	ErrTooLarge            = errors.New("upload body exceeds declared size")
	ErrUnsupportedMedia    = errors.New("unsupported media type")
	ErrInvalidDimensions   = errors.New("image dimensions exceed limits")
	ErrQuotaExceeded       = errors.New("emoji quota exceeded")
	ErrUploadExpired       = errors.New("upload placeholder expired")
	ErrMediaProcess        = errors.New("media processing failed")
	ErrStorage             = errors.New("storage operation failed")
	ErrFinalize            = errors.New("finalize operation failed")
)

Functions

func AttachmentOriginalKey

func AttachmentOriginalKey(channelID, attachmentID int64) string

func AttachmentPreviewKey

func AttachmentPreviewKey(channelID, attachmentID int64) string

func AvatarKey

func AvatarKey(userID, avatarID int64) string

func DecodeImageDimensions

func DecodeImageDimensions(data []byte) (int64, int64, error)

func DetectAnimated

func DetectAnimated(data []byte) (bool, error)

func EmojiMasterKey

func EmojiMasterKey(emojiID int64) string

func EmojiSizedKey

func EmojiSizedKey(emojiID int64, size int) string

func EmojiVariantKey

func EmojiVariantKey(emojiID int64, variant string) string

func IconKey

func IconKey(guildID, iconID int64) string

func InferAttachmentKind

func InferAttachmentKind(contentType, name string) string

func PublicURL

func PublicURL(base, key string) string

func Retry

func Retry(ctx context.Context, attempts int, delay time.Duration, fn func(context.Context) error) error

Types

type AttachmentResult

type AttachmentResult struct {
	AlreadyDone bool
	Kind        string
	ContentType string
	URL         string
	PreviewURL  *string
	Width       *int64
	Height      *int64
	Size        int64
}

type AttachmentService

type AttachmentService struct {
	// contains filtered or unexported fields
}

func NewAttachmentService

func NewAttachmentService(repo attachmentrepo.Attachment, storage Storage, publicBase string, processor MediaProcessor) *AttachmentService

func (*AttachmentService) Upload

func (s *AttachmentService) Upload(ctx context.Context, actorID, channelID, attachmentID int64, body io.Reader) (_ *AttachmentResult, err error)

type AvatarResult

type AvatarResult struct {
	AlreadyDone bool
	URL         string
	ContentType string
	Width       int64
	Height      int64
	Size        int64
}

type AvatarService

type AvatarService struct {
	// contains filtered or unexported fields
}

func NewAvatarService

func NewAvatarService(repo avatarrepo.Avatar, storage Storage, publicBase string, processor MediaProcessor, maxDim int, maxFileSize int64) *AvatarService

func (*AvatarService) Upload

func (s *AvatarService) Upload(ctx context.Context, actorID, userID, avatarID int64, body io.Reader) (_ *AvatarResult, err error)

type BufferedBody

type BufferedBody struct {
	Data        []byte
	Size        int64
	ContentType string
}

func ReadBodyToMemory

func ReadBodyToMemory(reader io.Reader, expectedSize int64) (*BufferedBody, error)

type EmojiResult

type EmojiResult struct {
	AlreadyDone bool
	Name        string
	Animated    bool
}

type EmojiService

type EmojiService struct {
	// contains filtered or unexported fields
}

func NewEmojiService

func NewEmojiService(repo emojirepo.Emoji, storage Storage, publicBase string, processor *FFmpegProcessor) *EmojiService

func (*EmojiService) Upload

func (s *EmojiService) Upload(ctx context.Context, guildID, emojiID int64, body io.Reader) (_ *EmojiResult, err error)

type FFmpegProcessor

type FFmpegProcessor struct {
	// contains filtered or unexported fields
}

func NewFFmpegProcessor

func NewFFmpegProcessor() *FFmpegProcessor

func (*FFmpegProcessor) ConvertToWebP

func (p *FFmpegProcessor) ConvertToWebP(ctx context.Context, source io.Reader, maxDimension int, sizeLimit int64) ([]byte, error)

func (*FFmpegProcessor) CreateWebPPreview

func (p *FFmpegProcessor) CreateWebPPreview(ctx context.Context, source string, maxDimension int) ([]byte, error)

func (*FFmpegProcessor) ProbeDimensions

func (p *FFmpegProcessor) ProbeDimensions(ctx context.Context, source string) (int64, int64, error)

func (*FFmpegProcessor) ProcessEmoji

func (p *FFmpegProcessor) ProcessEmoji(ctx context.Context, source []byte, sourceWidth, sourceHeight int64, sizeLimit int64) (*ProcessedEmoji, error)

type IconResult

type IconResult struct {
	AlreadyDone bool
	URL         string
	ContentType string
	Width       int64
	Height      int64
	Size        int64
}

type IconService

type IconService struct {
	// contains filtered or unexported fields
}

func NewIconService

func NewIconService(repo iconrepo.Icon, storage Storage, publicBase string, processor MediaProcessor, maxDim int, maxFileSize int64) *IconService

func (*IconService) Upload

func (s *IconService) Upload(ctx context.Context, guildID, iconID int64, body io.Reader) (_ *IconResult, err error)

type MediaProcessor

type MediaProcessor interface {
	CreateWebPPreview(ctx context.Context, source string, maxDimension int) ([]byte, error)
	ConvertToWebP(ctx context.Context, source io.Reader, maxDimension int, sizeLimit int64) ([]byte, error)
	ProbeDimensions(ctx context.Context, source string) (int64, int64, error)
}

type PreparedBody

type PreparedBody struct {
	Reader      io.Reader
	Size        int64
	ContentType string
}

func PrepareBody

func PrepareBody(reader io.Reader, expectedSize int64) (*PreparedBody, error)

type ProcessedEmoji

type ProcessedEmoji struct {
	Master   []byte
	Size96   []byte
	Size44   []byte
	Animated bool
	Width    int64
	Height   int64
}

type Storage

type Storage interface {
	UploadObject(ctx context.Context, key string, body io.Reader, contentType string) error
	MakeDownloadURL(ctx context.Context, key string, ttl time.Duration) (string, error)
	RemoveAttachment(ctx context.Context, key string) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL