media

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: AGPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedEmojiMIMETypes = []string{
	mimeImageGif,
	mimeImagePng,
	mimeImageWebp,
}
View Source
var SupportedMIMETypes = []string{
	mimeImageJpeg,
	mimeImageGif,
	mimeImagePng,
	mimeImageWebp,
	mimeVideoMp4,
}

Functions

This section is empty.

Types

type AdditionalEmojiInfo added in v0.2.0

type AdditionalEmojiInfo struct {
	// Time that this emoji was created; defaults to time.Now().
	CreatedAt *time.Time
	// 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 added in v0.2.0

type AdditionalMediaInfo struct {
	// Time that this media was created; defaults to time.Now().
	CreatedAt *time.Time
	// 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 an attachment when processing a piece of media.

type DataFunc added in v0.2.0

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

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

type DereferenceMedia added in v0.7.0

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

type Manager added in v0.2.0

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

func NewManager added in v0.2.0

func NewManager(state *state.State) *Manager

NewManager returns a media manager with given state.

func (*Manager) PreProcessEmoji added in v0.7.0

func (m *Manager) PreProcessEmoji(
	ctx context.Context,
	data DataFunc,
	shortcode string,
	emojiID string,
	uri string,
	ai *AdditionalEmojiInfo,
	refresh bool,
) (*ProcessingEmoji, error)

PreProcessEmoji begins the process of decoding and storing the given data as an emoji. It will return a pointer to a ProcessingEmoji struct upon which further actions can be performed, such as getting the finished media, thumbnail, attachment, etc.

  • data: function that the media manager can call to return a reader containing the emoji data.
  • shortcode: the emoji shortcode without the ':'s around it.
  • emojiID: database ID that should be used to store the emoji.
  • uri: ActivityPub URI/ID of the emoji.
  • ai: optional and can be nil. Any additional information about the emoji provided will be put in the database.
  • refresh: refetch/refresh the emoji.

Note: unlike ProcessEmoji, this will NOT queue the emoji to be asynchronously processed.

func (*Manager) PreProcessEmojiRecache added in v0.11.0

func (m *Manager) PreProcessEmojiRecache(
	ctx context.Context,
	data DataFunc,
	emojiID string,
) (*ProcessingEmoji, error)

PreProcessEmojiRecache refetches, reprocesses, and recaches an existing emoji that has been uncached via cleaner pruning.

Note: unlike ProcessEmoji, this will NOT queue the emoji to be asychronously processed.

func (*Manager) PreProcessMedia added in v0.7.0

func (m *Manager) PreProcessMedia(
	data DataFunc,
	accountID string,
	ai *AdditionalMediaInfo,
) *ProcessingMedia

PreProcessMedia begins the process of decoding and storing the given data as an attachment. It will return a pointer to a ProcessingMedia struct upon which further actions can be performed, such as getting the finished media, thumbnail, attachment, etc.

  • data: a function that the media manager can call to return a reader containing the media data.
  • accountID: the account that the media belongs to.
  • ai: optional and can be nil. Any additional information about the attachment provided will be put in the database.

Note: unlike ProcessMedia, this will NOT queue the media to be asynchronously processed.

func (*Manager) PreProcessMediaRecache added in v0.7.0

func (m *Manager) PreProcessMediaRecache(
	ctx context.Context,
	data DataFunc,
	attachmentID string,
) (*ProcessingMedia, error)

PreProcessMediaRecache refetches, reprocesses, and recaches an existing attachment that has been uncached via cleaner pruning.

Note: unlike ProcessMedia, this will NOT queue the media to be asychronously processed.

func (*Manager) ProcessEmoji added in v0.2.0

func (m *Manager) ProcessEmoji(
	ctx context.Context,
	data DataFunc,
	shortcode string,
	id string,
	uri string,
	ai *AdditionalEmojiInfo,
	refresh bool,
) (*ProcessingEmoji, error)

ProcessEmoji will call PreProcessEmoji, followed by queuing the emoji in the emoji worker queue.

func (*Manager) RefetchEmojis added in v0.7.0

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.

type ProcessingEmoji added in v0.2.0

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) EmojiID added in v0.2.0

func (p *ProcessingEmoji) EmojiID() string

EmojiID returns the ID of the underlying emoji without blocking processing.

func (*ProcessingEmoji) LoadEmoji added in v0.2.0

func (p *ProcessingEmoji) LoadEmoji(ctx context.Context) (*gtsmodel.Emoji, error)

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

func (*ProcessingEmoji) Process added in v0.7.0

func (p *ProcessingEmoji) Process(ctx context.Context)

Process allows the receiving object to fit the runners.WorkerFunc signature. It performs a (blocking) load and logs on error.

type ProcessingMedia added in v0.2.0

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) AttachmentID added in v0.2.0

func (p *ProcessingMedia) AttachmentID() string

AttachmentID returns the ID of the underlying media attachment without blocking processing.

func (*ProcessingMedia) LoadAttachment added in v0.2.0

func (p *ProcessingMedia) LoadAttachment(ctx context.Context) (*gtsmodel.MediaAttachment, error)

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.

func (*ProcessingMedia) Process added in v0.7.0

func (p *ProcessingMedia) Process(ctx context.Context)

Process allows the receiving object to fit the runners.WorkerFunc signature. It performs a (blocking) load and logs on error.

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
)

Jump to

Keyboard shortcuts

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