models

package
v0.0.0-...-823f4d2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DurationMap = map[string]time.Duration{
	"30m": 30 * time.Minute,
	"1h":  1 * time.Hour,
	"6h":  6 * time.Hour,
	"1d":  24 * time.Hour,
	"1w":  24 * time.Hour * 7,
}

DurationMap is a map linking the received string and a time.Duration

Functions

func Initialize

func Initialize() error

Initialize initializes the buckets and

func Migrate

func Migrate()

Migrate migrates the old data format to the new one

Types

type Resource

type Resource struct {
	Key          string    `json:"key" storm:"id,index"`
	Name         string    `json:"name"`
	Once         bool      `json:"once"`
	Size         int64     `json:"size"`
	DeleteAt     time.Time `json:"delete_at" storm:"index"`
	UnixDeleteAt int64     `json:"unix_delete_at" storm:"index"`
	Duration     string    `json:"-"`
}

Resource represents the data stored in the database

func NewResourceFromForm

func NewResourceFromForm(h *multipart.FileHeader, once bool, duration time.Duration) Resource

NewResourceFromForm returns a new Resource instance with some fields calculated

func (Resource) Delete

func (r Resource) Delete() error

Delete deletes a resource in database and on disk

func (*Resource) Get

func (r *Resource) Get(key string) error

Get retrives the Resource from the bucket

func (Resource) LogCreated

func (r Resource) LogCreated(c *gin.Context)

LogCreated logs when a file is created

func (Resource) LogDeleted

func (r Resource) LogDeleted(c *gin.Context)

LogDeleted logs when a file is deleted (due to a one-time view)

func (Resource) LogFetched

func (r Resource) LogFetched(c *gin.Context)

LogFetched logs when a file is fetched

func (Resource) NewStreamWriter

func (r Resource) NewStreamWriter(fd *os.File, key []byte) (*cipher.StreamWriter, error)

NewStreamWriter creates a new encrypted AES stream writer with the given key and the given file descriptor

func (Resource) OnCreated

func (r Resource) OnCreated(c *gin.Context)

OnCreated is the function called once the resource has been created and saved

func (Resource) Save

func (r Resource) Save() error

Save writes the Resource to the bucket

func (Resource) Write

func (r Resource) Write() error

Write isn't implemented yet

func (*Resource) WriteEncrypted

func (r *Resource) WriteEncrypted(fd multipart.File) (string, error)

WriteEncrypted is a method to write the file and encrypt it on the fly it returns the key that was used to encrypt the file so it can be sent back to the client.

type Statistics

type Statistics struct {
	TotalSize    uint64 `json:"total_size"`
	TotalFiles   uint64 `json:"total_files"`
	CurrentSize  uint64 `json:"current_size"`
	CurrentFiles uint64 `json:"current_files"`
}

Statistics is the struct representing the server statistics

var S Statistics

S is the exported main statistics structure

func (*Statistics) Add

func (s *Statistics) Add(r Resource) error

Add adds the given resource to the statistics and saves it to the database

func (*Statistics) Evaluate

func (s *Statistics) Evaluate() error

Evaluate recalculates the statistics from what's present in the database and save the statistics to the database

func (Statistics) Info

func (s Statistics) Info()

Info prints out the information about statistics in the logs

func (*Statistics) Load

func (s *Statistics) Load() error

Load loads the statistics from the database

func (*Statistics) Remove

func (s *Statistics) Remove(r Resource) error

Remove removes the given resource from the current statistics and saves it to the database

func (*Statistics) Save

func (s *Statistics) Save() error

Save saves the statistics to the database

Jump to

Keyboard shortcuts

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