api

package
v0.0.0-...-9921cdc Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrInvalidJSON = "Invalid JSON"
)
View Source
const MimeTypeOctetStream = "application/octet-stream"

Variables

This section is empty.

Functions

func ExtensionFromMime

func ExtensionFromMime(mimeType string) string

func Map

func Map[T interface{}, O interface{}](arr []T, fn func(T) O) []O

func Or

func Or[T interface{}](val *T, fallback T) T

func RandomString

func RandomString(length int) string

func RatelimitMiddleware

func RatelimitMiddleware(maxFails int, resetInterval time.Duration) func(next http.Handler) http.Handler

RatelimitMiddleware limits new requests when encountering too many 404 errors to prevent enumeration attacks

Types

type API

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

func New

func New(cfg Config) *API

func (*API) Run

func (a *API) Run() error

func (*API) ToAccount

func (a *API) ToAccount(acc *database.Account) Account

type Account

type Account struct {
	ID                 uint   `json:"id"`
	Username           string `json:"username"`
	APIKey             string `json:"apiKey"`
	DefaultDomainID    uint   `json:"defaultDomainId"`
	DefaultExpiryHours int    `json:"defaultExpiryHours"`
}

type Config

type Config struct {
	DB        *database.Database
	Filestore filestore.Filestore
	Log       logrus.FieldLogger
	Config    *config.Config
}

type ContextKey

type ContextKey int
const (
	ContextKeyAccount ContextKey = iota + 1
)

type Domain

type Domain struct {
	ID               uint                  `json:"id"`
	Owner            *Account              `json:"owner"`
	Domain           string                `json:"domain"`
	AccessRequired   bool                  `json:"accessRequired"`
	AllowedMimeTypes []string              `json:"allowedMimeTypes"`
	Status           database.DomainStatus `json:"status"`
}

func ToDomain

func ToDomain(d *database.Domain) *Domain

type PaginatedResponse

type PaginatedResponse struct {
	Total int         `json:"total"`
	Data  interface{} `json:"data"`
}

type Upload

type Upload struct {
	ID           uint      `json:"id"`
	Owner        *Account  `json:"owner"`
	Filename     string    `json:"filename"`
	MimeType     string    `json:"mimeType"`
	SizeBytes    uint      `json:"sizeBytes"`
	Domain       Domain    `json:"domain"`
	TTLSeconds   *uint     `json:"ttlSeconds"`
	LastViewedAt time.Time `json:"lastViewedAt"`
	Views        uint      `json:"views"`
}

func ToUpload

func ToUpload(d *database.Upload) *Upload

Jump to

Keyboard shortcuts

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