api

package
v0.0.0-...-2a2e411 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const ApiVersion string = "/v1"
View Source
const Bucket string = "uploads"

Variables

This section is empty.

Functions

func FileDelete

func FileDelete(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

func FileGet

func FileGet(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

func FilePut

func FilePut(c *fiber.Ctx, cfg *cfg.Config, db *Db) (string, error)

func IsExpired

func IsExpired(start time.Time, duration string) bool
Calculate   if  time   is   up  based   on   start  time.Time   and
duration. Returns  true if time  is expired. Start time  comes from
the database.

aka:

if(now - start) >= duration { time is up}

func Log

func Log(format string, values ...any)

vaious helbers

func NormalizeFilename

func NormalizeFilename(file string) string

func ProcessFormFiles

func ProcessFormFiles(cfg *cfg.Config, members []string, id string) (string, string, error)

generate return url. in case of multiple files, zip and remove them

func Runserver

func Runserver(cfg *cfg.Config, args []string) error

func SaveFormFiles

func SaveFormFiles(c *fiber.Ctx, cfg *cfg.Config, files []*multipart.FileHeader, id string) ([]string, error)

Extract form file[s] and store them on disk, returns a list of files

func SendResponse

func SendResponse(c *fiber.Ctx, msg string, err error) error

func Ts

func Ts() string

func Untaint

func Untaint(input string, wanted string) (string, error)

Untaint user input, that is: remove all non supported chars.

wanted is a regexp matching chars we shall leave. Everything else will be removed. Eg:

untainted := Untaint(input, `[^a-zA-Z0-9\-]`)

Returns a new string and an error if the input string has been modified. It's the callers choice to decide what to do about it. You may ignore the error and use the untainted string or bail out.

func ZipDir

func ZipDir(directory, zipfilename string) error

Create a zip archive from a directory FIXME: -e option, if any, goes here

Types

type Db

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

wrapper for bolt db

func NewDb

func NewDb(file string) (*Db, error)

func (*Db) Close

func (db *Db) Close()

func (*Db) Delete

func (db *Db) Delete(id string) error

func (*Db) Insert

func (db *Db) Insert(id string, entry *Upload) error

func (*Db) Iterate

func (db *Db) Iterate(iterator func(id string, upload Upload)) error

func (*Db) Lookup

func (db *Db) Lookup(id string) (Upload, error)

type Id

type Id struct {
	Id string `json:"name" xml:"name" form:"name"`
}

type Meta

type Meta struct {
	Expire string `json:"expire" form:"expire"`
}

Binding from JSON, data coming from user, not tainted

type Result

type Result struct {
	Success bool
	Message string
	Code    int
}

used to return to the api client

type Timestamp

type Timestamp struct {
	time.Time
	// contains filtered or unexported fields
}

Timestamp is like time.Time, but knows how to unmarshal from JSON Unix timestamp numbers or RFC3339 strings, and marshal back into the same JSON representation.

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) error

type Upload

type Upload struct {
	Id       string    `json:"id"`
	Expire   string    `json:"expire"`
	File     string    `json:"file"`    // final filename (visible to the downloader)
	Members  []string  `json:"members"` // contains multiple files, so File is an archive
	Uploaded Timestamp `json:"uploaded"`
}

stores 1 upload object, gets into db

Jump to

Keyboard shortcuts

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