Documentation ¶
Index ¶
Constants ¶
const UnusedLocalAttachmentCacheDays = 3
UnusedLocalAttachmentCacheDays is the amount of days to keep local media in storage if it is not attached to a status, or was never attached to a status.
Variables ¶
var SupportedEmojiMIMETypes = []string{
mimeImageGif,
mimeImagePng,
}
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
DataFunc represents a function used to retrieve the raw bytes of a piece of media.
type DereferenceMedia ¶ added in v0.7.0
type Manager ¶ added in v0.2.0
type Manager interface { // Stop stops the underlying worker pool of the manager. It should be called // when closing GoToSocial in order to cleanly finish any in-progress jobs. // It will block until workers are finished processing. Stop() error // ProcessMedia 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 should be a function that the media manager can call to return a reader containing the media data. // // postData will be called after data has been called; it can be used to clean up any remaining resources. // The provided function can be nil, in which case it will not be executed. // // accountID should be the account that the media belongs to. // // ai is optional and can be nil. Any additional information about the attachment provided will be put in the database. ProcessMedia(ctx context.Context, data DataFunc, postData PostDataCallbackFunc, accountID string, ai *AdditionalMediaInfo) (*ProcessingMedia, error) // ProcessEmoji 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 should be a function that the media manager can call to return a reader containing the emoji data. // // postData will be called after data has been called; it can be used to clean up any remaining resources. // The provided function can be nil, in which case it will not be executed. // // shortcode should be the emoji shortcode without the ':'s around it. // // id is the database ID that should be used to store the emoji. // // uri is the ActivityPub URI/ID of the emoji. // // ai is optional and can be nil. Any additional information about the emoji provided will be put in the database. // // If refresh is true, this indicates that the emoji image has changed and should be updated. ProcessEmoji(ctx context.Context, data DataFunc, postData PostDataCallbackFunc, shortcode string, id string, uri string, ai *AdditionalEmojiInfo, refresh bool) (*ProcessingEmoji, error) // RecacheMedia refetches, reprocesses, and recaches an existing attachment that has been uncached via pruneRemote. RecacheMedia(ctx context.Context, data DataFunc, postData PostDataCallbackFunc, attachmentID string) (*ProcessingMedia, error) // PruneAllRemote prunes all remote media attachments cached on this instance which are older than the given amount of days. // 'Pruning' in this context means removing the locally stored data of the attachment (both thumbnail and full size), // and setting 'cached' to false on the associated attachment. // // The returned int is the amount of media that was pruned by this function. PruneAllRemote(ctx context.Context, olderThanDays int) (int, error) // PruneAllMeta prunes unused/out of date headers and avatars cached on this instance. // // The returned int is the amount of media that was pruned by this function. PruneAllMeta(ctx context.Context) (int, error) // PruneUnusedLocalAttachments prunes unused media attachments that were uploaded by // a user on this instance, but never actually attached to a status, or attached but // later detached. // // The returned int is the amount of media that was pruned by this function. PruneUnusedLocalAttachments(ctx context.Context) (int, error) // PruneOrphaned prunes files that exist in storage but which do not have a corresponding // entry in the database. // // If dry is true, then nothing will be changed, only the amount that *would* be removed // is returned to the caller. PruneOrphaned(ctx context.Context, dry bool) (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. RefetchEmojis(ctx context.Context, domain string, dereferenceMedia DereferenceMedia) (int, error) }
Manager provides an interface for managing media: parsing, storing, and retrieving media objects like photos, videos, and gifs.
func NewManager ¶ added in v0.2.0
NewManager returns a media manager with the given db and underlying storage.
A worker pool will also be initialized for the manager, to ensure that only a limited number of media will be processed in parallel. The numbers of workers is determined from the $GOMAXPROCS environment variable (usually no. CPU cores). See internal/concurrency.NewWorkerPool() documentation for further information.
type PNGAncillaryChunkStripper ¶ added in v0.3.1
type PNGAncillaryChunkStripper struct { // Reader is the wrapped io.Reader. Reader io.Reader // contains filtered or unexported fields }
PNGAncillaryChunkStripper wraps another io.Reader to strip ancillary chunks, if the data is in the PNG file format. If the data isn't PNG, it is passed through unmodified.
type PostDataCallbackFunc ¶ added in v0.2.1
PostDataCallbackFunc represents a function executed after the DataFunc has been executed, and the returned reader has been read. It can be used to clean up any remaining resources.
This can be set to nil, and will then not be executed.
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.
type ProcessingMedia ¶ added in v0.2.0
type ProcessingMedia struct {
// contains filtered or unexported fields
}
ProcessingMedia represents a piece of media that is currently being processed. It exposes various 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 completed attachment.
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 )
func ParseMediaSize ¶
ParseMediaSize converts s to a recognized MediaSize, or returns an error if unrecognized
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 )
func ParseMediaType ¶
ParseMediaType converts s to a recognized MediaType, or returns an error if unrecognized