media

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: AGPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedEmojiMIMETypes = []string{
	"image/jpeg",
	"image/gif",
	"image/webp",

	"image/png",
	"image/apng",
}
View Source
var SupportedMIMETypes = []string{
	"image/jpeg",
	"image/gif",
	"image/webp",
	"image/avif",

	"audio/mp2",
	"audio/mp3",
	"audio/mpeg",

	"video/x-msvideo",

	"audio/flac",
	"audio/x-flac",

	"image/png",
	"image/apng",

	"audio/ogg",
	"video/ogg",

	"audio/mp4",
	"video/mp4",
	"video/quicktime",

	"audio/x-ms-wma",
	"video/x-ms-wmv",

	"video/webm",
	"audio/x-matroska",
	"video/x-matroska",
}

Functions

This section is empty.

Types

type AdditionalEmojiInfo

type AdditionalEmojiInfo struct {

	// ActivityPub URI of
	// this remote emoji.
	URI *string

	// Domain the emoji originated from. Blank
	// for this instance's domain. Defaults to "".
	Domain *string

	// URL of this emoji on a
	// remote instance; defaults to "".
	ImageRemoteURL *string

	// URL of the static version of this emoji
	// on a remote instance; defaults to "".
	ImageStaticRemoteURL *string

	// Whether this emoji should be disabled (not
	// shown) on this instance; defaults to false.
	Disabled *bool

	// Whether this emoji should be visible in
	// the instance's emoji picker; defaults to true.
	VisibleInPicker *bool

	// ID of the category this emoji
	// should be placed in; defaults to "".
	CategoryID *string
}

AdditionalEmojiInfo represents additional information that should be taken into account when processing an emoji.

type AdditionalMediaInfo

type AdditionalMediaInfo struct {

	// ID of the status to which this
	// media is attached; defaults to "".
	StatusID *string

	// URL of the media on a
	// remote instance; defaults to "".
	RemoteURL *string

	// Image description of
	// this media; defaults to "".
	Description *string

	// Blurhash of this
	// media; defaults to "".
	Blurhash *string

	// ID of the scheduled status to which
	// this media is attached; defaults to "".
	ScheduledStatusID *string

	// Mark this media as in-use
	// as an avatar; defaults to false.
	Avatar *bool

	// Mark this media as in-use
	// as a header; defaults to false.
	Header *bool

	// X focus coordinate for
	// this media; defaults to 0.
	FocusX *float32

	// Y focus coordinate for
	// this media; defaults to 0.
	FocusY *float32
}

AdditionalMediaInfo represents additional information that should be added to attachment when processing a piece of media.

type DataFunc

type DataFunc func(ctx context.Context) (reader io.ReadCloser, err error)

DataFunc represents a function used to retrieve the raw bytes of a piece of media.

type DereferenceMedia

type DereferenceMedia func(ctx context.Context, iri *url.URL, maxsz int64) (io.ReadCloser, error)

type Manager

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

func NewManager

func NewManager(state *state.State) *Manager

NewManager returns a media manager with given state.

func (*Manager) CacheEmoji

func (m *Manager) CacheEmoji(
	ctx context.Context,
	emoji *gtsmodel.Emoji,
	data DataFunc,
) (
	*ProcessingEmoji,
	error,
)

CacheEmoji wraps an emoji model (assumed already inserted in the database!) with given data function to perform a blocking dereference / decode operation from the data stream returned.

func (*Manager) CacheMedia

func (m *Manager) CacheMedia(
	media *gtsmodel.MediaAttachment,
	data DataFunc,
) *ProcessingMedia

CacheMedia wraps a media model (assumed already inserted in the database!) with given data function to perform a blocking dereference / decode operation from the data stream returned.

func (*Manager) CreateEmoji

func (m *Manager) CreateEmoji(
	ctx context.Context,
	shortcode string,
	domain string,
	data DataFunc,
	info AdditionalEmojiInfo,
) (
	*ProcessingEmoji,
	error,
)

CreateEmoji creates a new emoji entry in the database for given shortcode, domain and extra information, and prepares a new processing emoji entry to dereference it using the given data function, decode the media and finish filling out remaining fields (e.g. type, path, etc).

func (*Manager) CreateMedia

func (m *Manager) CreateMedia(
	ctx context.Context,
	accountID string,
	data DataFunc,
	info AdditionalMediaInfo,
) (
	*ProcessingMedia,
	error,
)

CreateMedia creates a new media attachment entry in the database for given owning account ID and extra information, and prepares a new processing media entry to dereference it using the given data function, decode the media and finish filling out remaining media fields (e.g. type, path, etc).

func (*Manager) RefetchEmojis

func (m *Manager) RefetchEmojis(ctx context.Context, domain string, dereferenceMedia DereferenceMedia) (int, error)

RefetchEmojis iterates through remote emojis (for the given domain, or all if domain is empty string).

For each emoji, the manager will check whether both the full size and static images are present in storage. If not, the manager will refetch and reprocess full size and static images for the emoji.

The provided DereferenceMedia function will be used when it's necessary to refetch something this way.

func (*Manager) UpdateEmoji

func (m *Manager) UpdateEmoji(
	ctx context.Context,
	emoji *gtsmodel.Emoji,
	data DataFunc,
	info AdditionalEmojiInfo,
) (
	*ProcessingEmoji,
	error,
)

UpdateEmoji prepares an update operation for the given emoji, which is assumed to already exist in the database.

Calling load on the returned *ProcessingEmoji will update the db entry with provided extra information, ensure emoji images are cached, and use new storage paths for the dereferenced media files to skirt around browser caching of the old files.

type ProcessingEmoji

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

ProcessingEmoji represents an emoji currently processing. It exposes various functions for retrieving data from the process.

func (*ProcessingEmoji) ID

func (p *ProcessingEmoji) ID() string

ID returns the ID of the underlying emoji.

func (*ProcessingEmoji) Load

LoadEmoji blocks until the static and fullsize image has been processed, and then returns the completed emoji.

type ProcessingMedia

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

ProcessingMedia represents a piece of media currently being processed. It exposes functions for retrieving data from the process.

func (*ProcessingMedia) ID

func (p *ProcessingMedia) ID() string

ID returns the ID of the underlying media.

func (*ProcessingMedia) Load

LoadAttachment blocks until the thumbnail and fullsize content has been processed, and then returns the attachment.

If processing could not be completed fully then an error will be returned. The attachment will still be returned in that case, but it will only be partially complete and should be treated as a placeholder.

type Size

type Size string
const (
	SizeSmall    Size = "small"    // SizeSmall is the key for small/thumbnail versions of media
	SizeOriginal Size = "original" // SizeOriginal is the key for original/fullsize versions of media and emoji
	SizeStatic   Size = "static"   // SizeStatic is the key for static (non-animated) versions of emoji
)

type Type

type Type string
const (
	TypeAttachment Type = "attachment" // TypeAttachment is the key for media attachments
	TypeHeader     Type = "header"     // TypeHeader is the key for profile header requests
	TypeAvatar     Type = "avatar"     // TypeAvatar is the key for profile avatar requests
	TypeEmoji      Type = "emoji"      // TypeEmoji is the key for emoji type requests
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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