provider

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataDirectoryName = "/.fibr"
	MaxConcurrency        = 6
	MaxClientSideCaching  = 2000
)

Variables

View Source
var (
	ArchiveExtensions = map[string]bool{".zip": true, ".tar": true, ".gz": true, ".rar": true}
	AudioExtensions   = map[string]bool{".mp3": true}
	CodeExtensions    = map[string]bool{".html": true, ".css": true, ".js": true, ".jsx": true, ".json": true, ".yml": true, ".yaml": true, ".toml": true, ".md": true, ".go": true, ".py": true, ".java": true, ".xml": true}
	ExcelExtensions   = map[string]bool{".xls": true, ".xlsx": true, ".xlsm": true}
	ImageExtensions   = map[string]bool{".jpg": true, ".jpeg": true, ".png": true, ".gif": true, ".svg": true, ".tiff": true, ".webp": true, ".heic": true, ".dng": true}
	PdfExtensions     = map[string]bool{".pdf": true}
	VideoExtensions   = map[string]string{".mp4": "video/mp4", ".mov": "video/mp4", ".avi": "video/x-msvideo", ".ogg": "video/ogg", ".mkv": "video/x-matroska"}
	StreamExtensions  = map[string]bool{".ts": true}
	WordExtensions    = map[string]bool{".doc": true, ".docx": true, ".docm": true}

	// ThumbnailExtensions contains extensions of file eligible to thumbnail
	ThumbnailExtensions = map[string]bool{".jpg": true, ".jpeg": true, ".png": true, ".gif": true, ".tiff": true, ".webp": true, ".pdf": true, ".mp4": true, ".mov": true, ".avi": true, ".ogg": true, ".mkv": true}
)
View Source
var (
	BufferPool = sync.Pool{
		New: func() any {
			return bytes.NewBuffer(make([]byte, 4*1024))
		},
	}

	SlowClient = request.CreateClient(5*time.Minute, request.NoRedirection)
)
View Source
var WebhookKindValues = []string{"raw", "discord", "slack", "telegram"}

Functions

func Dirname added in v0.9.0

func Dirname(name string) string

func DoneWriter added in v0.13.0

func DoneWriter(ctx context.Context, isDone func() bool, w io.Writer, content string)

func EtagMatch added in v0.15.0

func EtagMatch(w http.ResponseWriter, r *http.Request, hash string) (etag string, match bool)

func GetPathname

func GetPathname(folder, name string, share Share) string

func Hash added in v0.26.0

func Hash(value string) string

func Identifier added in v0.26.0

func Identifier() string

func IgnoreNotExistsErr added in v0.26.0

func IgnoreNotExistsErr[K comparable](_ context.Context, _ K, err error) error

func Join added in v0.13.0

func Join(parts ...string) string

func KeepOnlyDir added in v0.26.0

func KeepOnlyDir(items []absto.Item) []absto.Item

func KeepOnlyFile added in v0.26.0

func KeepOnlyFile(items []absto.Item) []absto.Item

func LoadJSON added in v0.11.0

func LoadJSON[T any](ctx context.Context, storageService absto.Storage, filename string) (output T, err error)

func LogClose added in v0.15.0

func LogClose(ctx context.Context, closer io.Closer, fn, item string)

func MetadataDirectory added in v0.18.0

func MetadataDirectory(item absto.Item) string

func ParseDisplayPreferences added in v0.25.0

func ParseDisplayPreferences(value string) map[string]Display

func RawHash added in v0.26.0

func RawHash(content any) string

func RenameDirectory added in v0.18.0

func RenameDirectory(ctx context.Context, storageService absto.Storage, renamers []Renamer, old, new absto.Item)

func SafeWrite

func SafeWrite(ctx context.Context, w io.Writer, content string)

func SanitizeName

func SanitizeName(name string, removeSlash bool) (string, error)

func SaveJSON added in v0.10.0

func SaveJSON[T any](ctx context.Context, storageService absto.Storage, filename string, content T) error

func SendLargeFile added in v0.9.0

func SendLargeFile(ctx context.Context, storageService absto.Storage, item absto.Item, req request.Request) (*http.Response, error)

func SetPrefsCookie added in v0.4.1

func SetPrefsCookie(w http.ResponseWriter, request Request)

func URL added in v0.4.1

func URL(folder, name string, share Share) string

func WriteToStorage added in v0.14.0

func WriteToStorage(ctx context.Context, storageService absto.Storage, output string, size int64, reader io.Reader) error

Types

type Aggregate added in v0.7.0

type Aggregate struct {
	Start    time.Time `json:"start,omitempty"`
	End      time.Time `json:"end,omitempty"`
	Location string    `json:"location,omitempty"`
	Cover    string    `json:"cover,omitempty"`
}

type Auth added in v0.8.0

type Auth interface {
	IsAuthenticated(*http.Request) (ident.Provider, model.User, error)
	IsAuthorized(context.Context, string) bool
}

type ByHybridSort added in v0.9.0

type ByHybridSort []absto.Item

func (ByHybridSort) Len added in v0.9.0

func (a ByHybridSort) Len() int

func (ByHybridSort) Less added in v0.9.0

func (a ByHybridSort) Less(i, j int) bool

func (ByHybridSort) Swap added in v0.9.0

func (a ByHybridSort) Swap(i, j int)

type ByID added in v0.23.0

type ByID []absto.Item

func (ByID) Len added in v0.23.0

func (a ByID) Len() int

func (ByID) Less added in v0.23.0

func (a ByID) Less(i, j int) bool

func (ByID) Swap added in v0.23.0

func (a ByID) Swap(i, j int)

type Display added in v0.25.0

type Display string
var (
	GridDisplay  Display = "grid"
	ListDisplay  Display = "list"
	StoryDisplay Display = "story"

	DefaultDisplay = GridDisplay

	LayoutPathsCookieName = "layout_paths"
)

func ParseDisplay added in v0.25.0

func ParseDisplay(input string) Display

type DisplayPreferences added in v0.25.0

type DisplayPreferences map[string]Display

func (DisplayPreferences) String added in v0.25.0

func (dp DisplayPreferences) String() string

type Event added in v0.7.0

type Event struct {
	Time         time.Time         `json:"time"`
	New          *absto.Item       `json:"new,omitempty"`
	Metadata     map[string]string `json:"metadata,omitempty"`
	URL          string            `json:"url,omitempty"`
	ShareableURL string            `json:"shareable_url,omitempty"`
	TraceLink    trace.Link        `json:"-"`
	Item         absto.Item        `json:"item"`
	Type         EventType         `json:"type"`
}

func NewAccessEvent added in v0.8.0

func NewAccessEvent(ctx context.Context, item absto.Item, r *http.Request) Event

func NewDeleteEvent added in v0.7.0

func NewDeleteEvent(ctx context.Context, request Request, item absto.Item, rendererService *renderer.Service) Event

func NewDescriptionEvent added in v0.20.0

func NewDescriptionEvent(ctx context.Context, item absto.Item, shareableURL string, description string, rendererService *renderer.Service) Event

func NewRenameEvent added in v0.7.0

func NewRenameEvent(ctx context.Context, old, new absto.Item, shareableURL string, rendererService *renderer.Service) Event

func NewRestartEvent added in v0.16.0

func NewRestartEvent(ctx context.Context, item absto.Item, subset string) Event

func NewStartEvent added in v0.7.0

func NewStartEvent(ctx context.Context, item absto.Item) Event

func NewUploadEvent added in v0.7.0

func NewUploadEvent(ctx context.Context, request Request, item absto.Item, shareableURL string, rendererService *renderer.Service) Event

func (Event) BrowserURL added in v0.22.0

func (e Event) BrowserURL() string

func (Event) GetMetadata added in v0.14.0

func (e Event) GetMetadata(key string) string

func (Event) GetName added in v0.14.0

func (e Event) GetName() string

func (Event) GetTo added in v0.14.0

func (e Event) GetTo() string

func (Event) GetURL added in v0.13.0

func (e Event) GetURL() string

func (Event) IsForcedFor added in v0.18.0

func (e Event) IsForcedFor(key string) bool

func (Event) StoryURL added in v0.22.0

func (e Event) StoryURL(id string) string

type EventBus added in v0.7.0

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

func NewEventBus added in v0.7.0

func NewEventBus(size uint64, meterProvider metric.MeterProvider, tracerProvider trace.TracerProvider) (EventBus, error)

func (EventBus) Done added in v0.24.0

func (e EventBus) Done() <-chan struct{}

func (EventBus) Push added in v0.7.0

func (e EventBus) Push(ctx context.Context, event Event)

func (EventBus) Start added in v0.7.0

func (e EventBus) Start(ctx context.Context, storageService absto.Storage, renamers []Renamer, consumers ...EventConsumer)

type EventConsumer added in v0.7.0

type EventConsumer func(context.Context, Event)

type EventProducer added in v0.7.0

type EventProducer func(context.Context, Event)

type EventType added in v0.7.0

type EventType uint
const (
	UploadEvent EventType = iota
	CreateDir
	RenameEvent
	DeleteEvent
	StartEvent
	AccessEvent
	DescriptionEvent
)

func ParseEventType added in v0.8.0

func ParseEventType(value string) (EventType, error)

func (EventType) MarshalJSON added in v0.8.0

func (et EventType) MarshalJSON() ([]byte, error)

func (EventType) String added in v0.8.0

func (et EventType) String() string

func (*EventType) UnmarshalJSON added in v0.8.0

func (et *EventType) UnmarshalJSON(b []byte) error

type ExifResponse added in v0.10.0

type ExifResponse struct {
	Exif exas.Exif  `json:"exif"`
	Item absto.Item `json:"item"`
}

type Metadata added in v0.25.0

type Metadata struct {
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	exas.Exif
}

type MetadataAction added in v0.25.0

type MetadataAction func(Metadata) Metadata

func ReplaceDescription added in v0.25.0

func ReplaceDescription(description string) MetadataAction

func ReplaceExif added in v0.25.0

func ReplaceExif(exif exas.Exif) MetadataAction

func ReplaceTags added in v0.25.0

func ReplaceTags(tags []string) MetadataAction

type MetadataManager added in v0.25.0

type MetadataManager interface {
	ListDir(ctx context.Context, item absto.Item) ([]absto.Item, error)

	GetAggregateFor(ctx context.Context, item absto.Item) (Aggregate, error)
	GetAllAggregateFor(ctx context.Context, items ...absto.Item) (map[string]Aggregate, error)
	SaveAggregateFor(ctx context.Context, item absto.Item, aggregate Aggregate) error

	GetMetadataFor(ctx context.Context, item absto.Item) (Metadata, error)
	GetAllMetadataFor(ctx context.Context, items ...absto.Item) (map[string]Metadata, error)
	Update(ctx context.Context, item absto.Item, opts ...MetadataAction) (Metadata, error)
}

type Preferences

type Preferences struct {
	LayoutPaths DisplayPreferences
}

func ParsePreferences added in v0.16.0

func ParsePreferences(value string) Preferences

func (Preferences) AddLayout added in v0.16.0

func (p Preferences) AddLayout(path string, display Display) Preferences

func (Preferences) GetLayout added in v0.25.0

func (p Preferences) GetLayout(path string) Display

func (Preferences) RemoveLayout added in v0.16.0

func (p Preferences) RemoveLayout(path string) Preferences

func (Preferences) SetCookie added in v0.25.0

func (p Preferences) SetCookie(w http.ResponseWriter)

type Renamer added in v0.18.0

type Renamer func(context.Context, absto.Item, absto.Item) error

type RenderItem

type RenderItem struct {
	Aggregate Aggregate
	Tags      []string
	URL       string
	Path      string

	absto.Item
	HasThumbnail bool
	IsCover      bool
}

func StorageToRender added in v0.12.0

func StorageToRender(item absto.Item, request Request) RenderItem

func (RenderItem) IsImage added in v0.14.0

func (r RenderItem) IsImage() bool

func (RenderItem) IsVideo added in v0.14.0

func (r RenderItem) IsVideo() bool

func (RenderItem) IsZero added in v0.15.0

func (r RenderItem) IsZero() bool

func (RenderItem) Mime added in v0.13.0

func (r RenderItem) Mime() string

func (RenderItem) String added in v0.24.0

func (r RenderItem) String() string

type Request

type Request struct {
	Path        string
	Item        string
	Display     Display
	Preferences Preferences
	Share       Share
	CanEdit     bool
	CanShare    bool
	CanWebhook  bool
}

func (Request) AbsoluteURL added in v0.12.0

func (r Request) AbsoluteURL(name string) string

func (Request) DeletePreference added in v0.16.0

func (r Request) DeletePreference(path string) Request

func (Request) Description added in v0.4.1

func (r Request) Description() string

func (Request) Filepath added in v0.12.0

func (r Request) Filepath() string

func (Request) IsStory added in v0.18.1

func (r Request) IsStory() bool

func (Request) LayoutPath

func (r Request) LayoutPath(path string) Display

func (Request) RelativeURL added in v0.12.0

func (r Request) RelativeURL(item absto.Item) string

func (Request) String added in v0.24.0

func (r Request) String() string

func (Request) SubPath added in v0.12.0

func (r Request) SubPath(name string) string

func (Request) Title added in v0.4.1

func (r Request) Title() string

func (Request) UpdatePreferences added in v0.16.0

func (r Request) UpdatePreferences() Request
type Search struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Query string `json:"query"`
}

func (Search) IsZero added in v0.25.0

func (s Search) IsZero() bool

type Share

type Share struct {
	Creation time.Time     `json:"creation"`
	ID       string        `json:"id"`
	Path     string        `json:"path"`
	RootName string        `json:"rootName"`
	Password string        `json:"password"`
	Duration time.Duration `json:"duration"`
	Edit     bool          `json:"edit"`
	Story    bool          `json:"story"`
	File     bool          `json:"file"`
}

func (Share) CheckPassword

func (s Share) CheckPassword(ctx context.Context, authorizationHeader string, shareApp ShareManager) error

func (Share) IsExpired added in v0.4.0

func (s Share) IsExpired(now time.Time) bool

func (Share) IsZero added in v0.12.0

func (s Share) IsZero() bool

func (Share) String added in v0.24.0

func (s Share) String() string

type ShareManager added in v0.8.0

type ShareManager interface {
	List() []Share
	Get(string) Share
	Create(context.Context, string, bool, bool, string, bool, time.Duration) (string, error)
	UpdatePassword(context.Context, string, string) error
	Delete(context.Context, string) error
}

type StoryItem added in v0.16.0

type StoryItem struct {
	Exif Metadata
	RenderItem
}

func StorageToStory added in v0.16.0

func StorageToStory(item absto.Item, request Request, exif Metadata) StoryItem

func (StoryItem) String added in v0.24.0

func (s StoryItem) String() string

type Webhook added in v0.8.0

type Webhook struct {
	ID        string      `json:"id"`
	Pathname  string      `json:"pathname"`
	URL       string      `json:"url"`
	Types     []EventType `json:"types"`
	Kind      WebhookKind `json:"kind"`
	Recursive bool        `json:"recursive"`
}

func (Webhook) Match added in v0.8.0

func (w Webhook) Match(e Event) bool

type WebhookKind added in v0.12.0

type WebhookKind int
const (
	Raw WebhookKind = iota
	Discord
	Slack
	Telegram
)

func ParseWebhookKind added in v0.12.0

func ParseWebhookKind(value string) (WebhookKind, error)

func (WebhookKind) MarshalJSON added in v0.12.0

func (r WebhookKind) MarshalJSON() ([]byte, error)

func (WebhookKind) String added in v0.12.0

func (r WebhookKind) String() string

func (*WebhookKind) UnmarshalJSON added in v0.12.0

func (r *WebhookKind) UnmarshalJSON(b []byte) error

type WebhookManager added in v0.8.0

type WebhookManager interface {
	List() []Webhook
	Create(context.Context, string, bool, WebhookKind, string, []EventType) (string, error)
	Delete(context.Context, string) error
}

Jump to

Keyboard shortcuts

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