Documentation
¶
Index ¶
- Constants
- Variables
- func NewOwnerTypes(r *http.Request) (owners map[OwnerType]net.IP, err error)
- func ParseBytesize(s string) (size int64, err error)
- func ParseDuration(s string) (d time.Duration, err error)
- func PrettyBytesize(bs int64) string
- func PrettyDuration(d time.Duration) string
- func WebProtocol(r *http.Request) string
- type Item
- func (i Item) DeleteContent(directory string) error
- func (i Item) ReadEncryptedFile(directory string, secretKey [KeySize]byte) (io.ReadCloser, error)
- func (i Item) ReadFile(directory string) (io.ReadCloser, error)
- func (i Item) WriteEncryptedFile(file io.ReadCloser, secretKey [KeySize]byte, directory string) (uint64, [][NonceSize]byte, error)
- func (i Item) WriteFile(file io.ReadCloser, directory string) error
- type MimeMap
- type OwnerType
- type Server
- type Store
- func (s *Store) BadgerHold() *badgerhold.Store
- func (s *Store) Close() error
- func (s *Store) Delete(i Item) (err error)
- func (s *Store) DeleteExpired() error
- func (s *Store) Get(id string, delExpired bool) (i Item, err error)
- func (s *Store) GetDecrypted(id string, secretKey [KeySize]byte, delExpired bool) (i Item, err error)
- func (s *Store) GetFile(i Item, secretKey [KeySize]byte) (io.ReadCloser, error)
- func (s *Store) Put(i Item, file io.ReadCloser) (id string, secretKey [KeySize]byte, err error)
Constants ¶
const ( DirDatabase = "db" DirStorage = "data" )
const ( IDSize = 4 KeySize = 32 NonceSize = 24 )
const MimeDrop = "DROP"
Variables ¶
var ( ErrLifetimeToLong = errors.New("lifetime is greater than maximum lifetime") ErrFileToBig = errors.New("file size is greater than maximum filesize") )
var ErrDecryptionError = errors.New("decryption error")
ErrDecryptionError is returned by `Store.Get` if the decryption failed. This may be because the wrong key has been provided, or because the data has been tampered with.
var ErrMimeDrop = errors.New("MIME must be dropped")
var (
ErrNoMatch = errors.New("input does not match pattern")
)
var ErrNotFound = errors.New("no Item found for this ID")
ErrNotFound is returned by the `Store.Get` method if there is no Item for the requested ID.
Functions ¶
func NewOwnerTypes ¶
NewOwnerTypes creates a map of OwnerTypes to IP addresses based on a Request.
func ParseBytesize ¶
ParseBytesize parses a positive, human readable and whole byte amount in the binary prefix notation. Legit values might be "1B", "23KiB"/"23KB" etc.
func ParseDuration ¶
ParseDuration parses a (positive) duration string, similar to the `time.ParseDuration` method. A duration string is sequence of decimal numbers and a unit suffix. Valid time units are "s", "m", "h", "d", "w", "mo", "y".
func PrettyBytesize ¶
PrettyBytesize returns a human readable representation of a byte size.
func PrettyDuration ¶
PrettyDuration returns a human readable representation of a time.Duration.
func WebProtocol ¶
WebProtocol returns "http" or "https", based on the X-Forwarded-Proto header.
Types ¶
type Item ¶
type Item struct {
ID string `badgerhold:"key"`
BurnAfterReading bool
Filename string
FilenameNonce [NonceSize]byte
ContentType string
Chunks uint64
ChunkSize uint64
ChunkNonces [][NonceSize]byte
Created time.Time
Expires time.Time `badgerholdIndex:"Expires"`
Owner map[OwnerType]net.IP
}
Item describes an uploaded file.
func NewItem ¶
func NewItem(r *http.Request, maxSize int64, maxLifetime time.Duration, chunkSize uint64) (item Item, file io.ReadCloser, err error)
NewItem creates a new Item based on a Request. The ID will be left empty. Furthermore, if no error has occurred, a file is returned from which the file content should be read. This file must be closed afterwards.
func (Item) DeleteContent ¶
DeleteContent removes the content of an Item from the given directory.
func (Item) ReadEncryptedFile ¶
ReadEncryptedFile takes the chunks written by WriteEncryptedFile, decrypts and verifies each chunk and reassembles the original file in memory (the decrypted contents are never written to disk).
func (Item) ReadFile ¶
func (i Item) ReadFile(directory string) (io.ReadCloser, error)
ReadFile deserializes the file of an Item from the given directory into a ReadCloser.
func (Item) WriteEncryptedFile ¶
func (i Item) WriteEncryptedFile(file io.ReadCloser, secretKey [KeySize]byte, directory string) (uint64, [][NonceSize]byte, error)
WriteEncryptedFile splits the file into chunks of size ChunkSize and encrypts each chunk using nacl secretbox. Files will be put into a folder named with the Item ID
type MimeMap ¶
MimeMap replaces predefined MIME types with others or requires them to be dropped.
# An example MimeMap could look like this, comment included: text/html text/plain text/javascript text/plain text/mp4 DROP
func NewMimeMap ¶
NewMimeMap creates a new MimeMap based on the Reader's data.
type OwnerType ¶
type OwnerType string
OwnerType describes a possible type of an owner, as an IP address. This can be the remote address as well as some header field.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements a http.Handler for up- and download.
func NewServer ¶
func NewServer(storeDirectory string, maxSize int64, maxLifetime time.Duration, contactMail string, mimeMap MimeMap, chunkSize uint64) (s *Server, err error)
NewServer creates a new Server with a given database directory, and configuration values. The Server must be started as a http.Handler.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store stores an index of all Items as well as the pure files.
func NewStore ¶
NewStore opens or initializes a Store in the given directory. A background task for continuous cleaning can be activated.
func (*Store) BadgerHold ¶
func (s *Store) BadgerHold() *badgerhold.Store
BadgerHold returns a reference to the underlying BadgerHold instance.
func (*Store) DeleteExpired ¶
DeleteExpired checks the Store for expired Items and deletes them.
func (*Store) GetDecrypted ¶
func (s *Store) GetDecrypted(id string, secretKey [KeySize]byte, delExpired bool) (i Item, err error)
GetDecrypted gets an Item by its ID and decrypts the filename. The Item's content can be accessed with GetFile.