provider

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetadataDirectoryName directory where metadata are stored
	MetadataDirectoryName = "/.fibr"
)

Variables

View Source
var (
	// ArchiveExtensions contains extensions of Archive
	ArchiveExtensions = map[string]bool{".zip": true, ".tar": true, ".gz": true, ".rar": true}
	// AudioExtensions contains extensions of Audio
	AudioExtensions = map[string]bool{".mp3": true}
	// CodeExtensions contains extensions of Code
	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 contains extensions of Excel
	ExcelExtensions = map[string]bool{".xls": true, ".xlsx": true, ".xlsm": true}
	// ImageExtensions contains extensions of Image
	ImageExtensions = map[string]bool{".jpg": true, ".jpeg": true, ".png": true, ".gif": true, ".svg": true, ".tiff": true}
	// PdfExtensions contains extensions of Pdf
	PdfExtensions = map[string]bool{".pdf": true}
	// VideoExtensions contains extensions of Video
	VideoExtensions = map[string]string{".mp4": "video/mp4", ".mov": "video/mp4", ".avi": "video/x-msvideo", ".ogg": "video/ogg"}
	// StreamExtensions contains extensions of streamable content
	StreamExtensions = map[string]bool{".ts": true}
	// WordExtensions contains extensions of Word
	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, ".pdf": true, ".mp4": true, ".mov": true, ".avi": true}
)
View Source
var (
	// GridDisplay format
	GridDisplay = "grid"
	// ListDisplay format
	ListDisplay = "list"
	// DefaultDisplay format
	DefaultDisplay = GridDisplay
)
View Source
var (

	// BufferPool for io.CopyBuffer
	BufferPool = sync.Pool{
		New: func() interface{} {
			return bytes.NewBuffer(make([]byte, 4*1024))
		},
	}

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

WebhookKindValues string values

Functions

func Dirname added in v0.9.0

func Dirname(name string) string

Dirname ensures given name is a dirname, with a trailing slash

func DoneWriter added in v0.13.0

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

DoneWriter writes content to writer with error handling and done checking

func FindIndex

func FindIndex(arr []string, value string) int

FindIndex finds index of given value into array, or -1 if not found

func GetIP added in v0.10.0

func GetIP(r *http.Request) string

GetIP retrieves request original IP

func GetPathname

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

GetPathname computes pathname for given params

func HandleClose added in v0.11.0

func HandleClose(closer io.Closer, err error) error

HandleClose closes given closer respecting given err

func Join added in v0.13.0

func Join(parts ...string) string

Join concatenates strings respecting terminal slashes

func LoadJSON added in v0.11.0

func LoadJSON(storageApp absto.Storage, filename string, content interface{}) (err error)

LoadJSON loads JSON content

func RemoveIndex

func RemoveIndex(arr []string, index int) []string

RemoveIndex removes element at given index, if valid

func SafeWrite

func SafeWrite(w io.Writer, content string)

SafeWrite writes content to writer with error handling

func SanitizeName

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

SanitizeName return sanitized name (remove diacritics)

func SaveJSON added in v0.10.0

func SaveJSON(storageApp absto.Storage, filename string, content interface{}) error

SaveJSON saves JSON content

func SendLargeFile added in v0.9.0

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

SendLargeFile in a request with buffered copy

func SetPrefsCookie added in v0.4.1

func SetPrefsCookie(w http.ResponseWriter, request Request)

SetPrefsCookie set preferences cookie for given request

func URL added in v0.4.1

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

URL computes URL for given params

func WriteToStorage added in v0.14.0

func WriteToStorage(storageApp absto.Storage, output string, reader io.Reader) error

WriteToStorage writes given content to storage

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"`
}

Aggregate contains aggregated data for a folder

type Auth added in v0.8.0

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

Auth manager user authentication/authorization

type ByHybridSort added in v0.9.0

type ByHybridSort []absto.Item

ByHybridSort implements Sorter by type, name then modification time

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 Crud added in v0.8.0

type Crud interface {
	Start(done <-chan struct{})
	Browser(http.ResponseWriter, Request, absto.Item, renderer.Message) (string, int, map[string]interface{}, error)
	List(Request, renderer.Message, absto.Item, []absto.Item) (string, int, map[string]interface{}, error)
	Get(http.ResponseWriter, *http.Request, Request) (string, int, map[string]interface{}, error)
	Post(http.ResponseWriter, *http.Request, Request)
	Create(http.ResponseWriter, *http.Request, Request)
	Upload(http.ResponseWriter, *http.Request, Request, map[string]string, *multipart.Part)
	Rename(http.ResponseWriter, *http.Request, Request)
	Delete(http.ResponseWriter, *http.Request, Request)
}

Crud for user to interfact with filesystem

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"`
	Item         absto.Item        `json:"item"`
	Type         EventType         `json:"type"`
}

Event describes an event on fibr

func NewAccessEvent added in v0.8.0

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

NewAccessEvent creates a new access event

func NewDeleteEvent added in v0.7.0

func NewDeleteEvent(request Request, item absto.Item, rendererApp renderer.App) Event

NewDeleteEvent creates a new delete event

func NewRenameEvent added in v0.7.0

func NewRenameEvent(old, new absto.Item, shareableURL string, rendererApp renderer.App) Event

NewRenameEvent creates a new rename event

func NewStartEvent added in v0.7.0

func NewStartEvent(item absto.Item) Event

NewStartEvent creates a new start event

func NewUploadEvent added in v0.7.0

func NewUploadEvent(request Request, item absto.Item, shareableURL string, rendererApp renderer.App) Event

NewUploadEvent creates a new upload event

func (Event) GetMetadata added in v0.14.0

func (e Event) GetMetadata(key string) string

GetMetadata extracts metadata content

func (Event) GetName added in v0.14.0

func (e Event) GetName() string

GetName returns the name of the item

func (Event) GetTo added in v0.14.0

func (e Event) GetTo() string

GetTo returns the appropriate to destination

func (Event) GetURL added in v0.13.0

func (e Event) GetURL() string

GetURL returns the appropriate URL for the event

type EventBus added in v0.7.0

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

EventBus describes a channel for exchanging Event

func NewEventBus added in v0.7.0

func NewEventBus(size uint, prometheusRegisterer prometheus.Registerer) (EventBus, error)

NewEventBus create an event exchange channel

func (EventBus) Push added in v0.7.0

func (e EventBus) Push(event Event) error

Push an event in the bus

func (EventBus) Start added in v0.7.0

func (e EventBus) Start(done <-chan struct{}, consumers ...EventConsumer)

Start the distibution of Event

type EventConsumer added in v0.7.0

type EventConsumer func(Event)

EventConsumer is a func that consume an event

type EventProducer added in v0.7.0

type EventProducer func(Event) error

EventProducer is a func that push an event

type EventType added in v0.7.0

type EventType uint

EventType is the enumeration of event that can happen

const (
	// UploadEvent occurs when someone upload a file
	UploadEvent EventType = iota
	// CreateDir occurs when a directory is created
	CreateDir
	// RenameEvent occurs when an item is renamed
	RenameEvent
	// DeleteEvent occurs when an item is deleted
	DeleteEvent
	// StartEvent occurs when fibr start
	StartEvent
	// AccessEvent occurs when content is accessed
	AccessEvent
)

func ParseEventType added in v0.8.0

func ParseEventType(value string) (EventType, error)

ParseEventType parse raw string into an EventType

func (EventType) MarshalJSON added in v0.8.0

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

MarshalJSON marshals the enum as a quoted json string

func (EventType) String added in v0.8.0

func (et EventType) String() string

String return string values

func (*EventType) UnmarshalJSON added in v0.8.0

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

UnmarshalJSON unmarshal JSON

type ExifResponse added in v0.10.0

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

ExifResponse from AMQP

type Preferences

type Preferences struct {
	ListLayoutPath []string
}

Preferences holds preferences of the user

type RenderItem

type RenderItem struct {
	Aggregate
	ID   string
	URL  string
	Path string
	absto.Item
}

RenderItem is a storage item with an id

func StorageToRender added in v0.12.0

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

StorageToRender converts Item to RenderItem

func (RenderItem) IsImage added in v0.14.0

func (r RenderItem) IsImage() bool

IsImage check if item is an image

func (RenderItem) IsVideo added in v0.14.0

func (r RenderItem) IsVideo() bool

IsVideo check if item is an image

func (RenderItem) Mime added in v0.13.0

func (r RenderItem) Mime() string

Mime gives Mime Type of item

type Request

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

Request from user

func (Request) AbsoluteURL added in v0.12.0

func (r Request) AbsoluteURL(name string) string

AbsoluteURL compute absolute URL for the given name

func (Request) Description added in v0.4.1

func (r Request) Description() string

Description returns description of the page

func (Request) Filepath added in v0.12.0

func (r Request) Filepath() string

Filepath returns the pathname of the request

func (Request) LayoutPath

func (r Request) LayoutPath(path string) string

LayoutPath returns layout of given path based on preferences

func (Request) RelativeURL added in v0.12.0

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

RelativeURL compute relative URL of item for that request

func (Request) SubPath added in v0.12.0

func (r Request) SubPath(name string) string

SubPath returns the pathname of given name

func (Request) Title added in v0.4.1

func (r Request) Title() string

Title returns title of the page

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"`
	File     bool          `json:"file"`
}

Share stores informations about shared paths

func (Share) CheckPassword

func (s Share) CheckPassword(authorizationHeader string) error

CheckPassword verifies that request has correct password for share

func (Share) IsExpired added in v0.4.0

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

IsExpired check if given share is expired

func (Share) IsZero added in v0.12.0

func (s Share) IsZero() bool

IsZero verifies that instance is hydrated

type ShareManager added in v0.8.0

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

ShareManager description

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"`
}

Webhook stores informations about webhook

func (Webhook) Match added in v0.8.0

func (w Webhook) Match(e Event) bool

Match determine if storage item match webhook

type WebhookKind added in v0.12.0

type WebhookKind int

WebhookKind defines constant for webhook kind

const (
	// Raw webhook
	Raw WebhookKind = iota
	// Discord webhook
	Discord
	// Slack webhook
	Slack
	// Telegram webhook
	Telegram
)

func ParseWebhookKind added in v0.12.0

func ParseWebhookKind(value string) (WebhookKind, error)

ParseWebhookKind parse raw string into a WebhookKind

func (WebhookKind) MarshalJSON added in v0.12.0

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

MarshalJSON marshals the enum as a quoted json string

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

UnmarshalJSON unmarshal JSON

type WebhookManager added in v0.8.0

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

WebhookManager description

Jump to

Keyboard shortcuts

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