entitysource

package
v4.0.0-...-c6eef43 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoContentLength is returned by Seek when the initial http response did not include a Content-Length header
	ErrNoContentLength = errors.New("Content-Length was not set")
)

Functions

This section is empty.

Types

type EntitySource

type EntitySource interface {
	io.ReadSeekCloser
	io.ReaderAt

	// Url generates a download url for the entity.
	Url(ctx context.Context, opts ...EntitySourceOption) (*EntityUrl, error)
	// Serve serves the entity to the client, with supports on Range header and If- cache control.
	Serve(w http.ResponseWriter, r *http.Request, opts ...EntitySourceOption)
	// Entity returns the entity of the source.
	Entity() fs.Entity
	// IsLocal returns true if the source is in local machine.
	IsLocal() bool
	// LocalPath returns the local path of the source file.
	LocalPath(ctx context.Context) string
	// Apply applies the options to the source.
	Apply(opts ...EntitySourceOption)
	// CloneToLocalSrc clones the source to a local file source.
	CloneToLocalSrc(t types.EntityType, src string) (EntitySource, error)
	// ShouldInternalProxy returns true if the source will/should be proxied by internal proxy.
	ShouldInternalProxy(opts ...EntitySourceOption) bool
}

func NewEntitySource

func NewEntitySource(
	e fs.Entity,
	handler driver.Handler,
	policy *ent.StoragePolicy,
	generalAuth auth.Auth,
	settings setting.Provider,
	hasher hashid.Encoder,
	c request.Client,
	l logging.Logger,
	config conf.ConfigProvider,
	mime mime.MimeDetector,
	opts ...EntitySourceOption,
) EntitySource

NewEntitySource creates a new EntitySource.

type EntitySourceOption

type EntitySourceOption interface {
	Apply(any)
}

func WithContext

func WithContext(ctx context.Context) EntitySourceOption

WithContext set context for file source

func WithDisplayName

func WithDisplayName(name string) EntitySourceOption

WithDisplayName set display name for file source

func WithDownload

func WithDownload(isDownload bool) EntitySourceOption

WithDownload set file URL as download

func WithExpire

func WithExpire(expire *time.Time) EntitySourceOption

WithExpire set expire time for file source

func WithNoInternalProxy

func WithNoInternalProxy() EntitySourceOption

WithNoInternalProxy overwrite policy's internal proxy setting

func WithSpeedLimit

func WithSpeedLimit(limit int64) EntitySourceOption

WithSpeedLimit set speed limit for file source (if supported)

func WithThumb

func WithThumb(isThumb bool) EntitySourceOption

WithThumb set entity source as thumb. This will result in entity source URL generated with thumbnail processing parameters. For sidecar thumb files, this option will be ignored.

type EntitySourceOptionFunc

type EntitySourceOptionFunc func(any)

func (EntitySourceOptionFunc) Apply

func (f EntitySourceOptionFunc) Apply(option any)

type EntitySourceOptions

type EntitySourceOptions struct {
	SpeedLimit         int64
	Expire             *time.Time
	IsDownload         bool
	NoInternalProxy    bool
	DisplayName        string
	OneTimeDownloadKey string
	Ctx                context.Context
	IsThumb            bool
}

type EntityUrl

type EntityUrl struct {
	Url      string
	ExpireAt *time.Time
}

Jump to

Keyboard shortcuts

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