models

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ApiPermView is the permission for viewing metadata of all uploaded files
	ApiPermView = 1 << iota
	// ApiPermUpload is the permission for creating new files
	ApiPermUpload
	// ApiPermDelete is the permission for deleting files
	ApiPermDelete
	// ApiPermApiMod is the permission for adding / removing API key permissions
	ApiPermApiMod
	// ApiPermEdit is the permission for editing parameters of uploaded files
	ApiPermEdit
)
View Source
const ApiPermAll = 31

ApiPermAll means all permission granted

View Source
const ApiPermAllNoApiMod = ApiPermAll - ApiPermApiMod

ApiPermAllNoApiMod means all permission granted, except ApiPermApiMod This is the default for new API keys that are created from the UI

View Source
const ApiPermNone = 0

ApiPermNone means no permission granted

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiKey

type ApiKey struct {
	Id           string `json:"Id" redis:"Id"`
	FriendlyName string `json:"FriendlyName" redis:"FriendlyName"`
	LastUsed     int64  `json:"LastUsed" redis:"LastUsed"`
	Permissions  uint8  `json:"Permissions" redis:"Permissions"`
	Expiry       int64  `json:"Expiry" redis:"Expiry"` // Does not expire if 0
	IsSystemKey  bool   `json:"IsSystemKey" redis:"IsSystemKey"`
}

ApiKey contains data of a single api key

func (*ApiKey) GetReadableDate added in v1.9.0

func (key *ApiKey) GetReadableDate() string

func (*ApiKey) HasPermission added in v1.8.0

func (key *ApiKey) HasPermission(permission uint8) bool

HasPermission returns true if the key has the permission(s)

func (*ApiKey) HasPermissionApiMod added in v1.8.0

func (key *ApiKey) HasPermissionApiMod() bool

HasPermissionApiMod returns true if ApiPermApiMod is granted

func (*ApiKey) HasPermissionDelete added in v1.8.0

func (key *ApiKey) HasPermissionDelete() bool

HasPermissionDelete returns true if ApiPermDelete is granted

func (*ApiKey) HasPermissionEdit added in v1.8.0

func (key *ApiKey) HasPermissionEdit() bool

HasPermissionEdit returns true if ApiPermEdit is granted

func (*ApiKey) HasPermissionUpload added in v1.8.0

func (key *ApiKey) HasPermissionUpload() bool

HasPermissionUpload returns true if ApiPermUpload is granted

func (*ApiKey) HasPermissionView added in v1.8.0

func (key *ApiKey) HasPermissionView() bool

HasPermissionView returns true if ApiPermView is granted

func (*ApiKey) RemovePermission added in v1.8.0

func (key *ApiKey) RemovePermission(permission uint8)

RemovePermission revokes one or more permissions

func (*ApiKey) SetPermission added in v1.8.0

func (key *ApiKey) SetPermission(permission uint8)

SetPermission grants one or more permissions

type ApiKeyOutput added in v1.8.1

type ApiKeyOutput struct {
	Result string
	Id     string
}

ApiKeyOutput is the output that is used after a new key is created

type AuthenticationConfig

type AuthenticationConfig struct {
	Method               int      `json:"Method"`
	SaltAdmin            string   `json:"SaltAdmin"`
	SaltFiles            string   `json:"SaltFiles"`
	Username             string   `json:"Username"`
	Password             string   `json:"Password"`
	HeaderKey            string   `json:"HeaderKey"`
	OAuthProvider        string   `json:"OauthProvider"`
	OAuthClientId        string   `json:"OAuthClientId"`
	OAuthClientSecret    string   `json:"OAuthClientSecret"`
	OAuthUserScope       string   `json:"OauthUserScope"`
	OAuthGroupScope      string   `json:"OauthGroupScope"`
	OAuthRecheckInterval int      `json:"OAuthRecheckInterval"`
	HeaderUsers          []string `json:"HeaderUsers"`
	OAuthGroups          []string `json:"OAuthGroups"`
	OAuthUsers           []string `json:"OauthUsers"`
}

AuthenticationConfig holds configuration on how to authenticate to Gokapi admin menu

type AwsConfig

type AwsConfig struct {
	Bucket        string `yaml:"Bucket"`
	Region        string `yaml:"Region"`
	KeyId         string `yaml:"KeyId"`
	KeySecret     string `yaml:"KeySecret"`
	Endpoint      string `yaml:"Endpoint"`
	ProxyDownload bool   `yaml:"ProxyDownload"`
}

AwsConfig contains all configuration values / credentials for AWS cloud storage

func (*AwsConfig) IsAllProvided

func (c *AwsConfig) IsAllProvided() bool

IsAllProvided returns true if all required variables have been set for using AWS S3 / Backblaze

type Configuration

type Configuration struct {
	Authentication      AuthenticationConfig `json:"Authentication"`
	Port                string               `json:"Port"`
	ServerUrl           string               `json:"ServerUrl"`
	RedirectUrl         string               `json:"RedirectUrl"`
	PublicName          string               `json:"PublicName"`
	DataDir             string               `json:"DataDir"`
	DatabaseUrl         string               `json:"DatabaseUrl"`
	ConfigVersion       int                  `json:"ConfigVersion"`
	LengthId            int                  `json:"LengthId"`
	MaxFileSizeMB       int                  `json:"MaxFileSizeMB"`
	MaxMemory           int                  `json:"MaxMemory"`
	ChunkSize           int                  `json:"ChunkSize"`
	MaxParallelUploads  int                  `json:"MaxParallelUploads"`
	Encryption          Encryption           `json:"Encryption"`
	UseSsl              bool                 `json:"UseSsl"`
	PicturesAlwaysLocal bool                 `json:"PicturesAlwaysLocal"`
	SaveIp              bool                 `json:"SaveIp"`
	IncludeFilename     bool                 `json:"IncludeFilename"`
}

Configuration is a struct that contains the global configuration

func (Configuration) ToJson

func (c Configuration) ToJson() []byte

ToJson returns an idented JSon representation

func (Configuration) ToString

func (c Configuration) ToString() string

ToString returns the object as an unidented Json string used for test units

type DbConnection added in v1.9.0

type DbConnection struct {
	HostUrl     string
	RedisPrefix string
	Username    string
	Password    string
	RedisUseSsl bool
	Type        int
}

DbConnection is a struct that contains the database configuration for connecting

type DownloadStatus

type DownloadStatus struct {
	Id       string
	FileId   string
	ExpireAt int64
}

DownloadStatus contains current downloads, so they do not get removed during cleanup

type E2EFile added in v1.6.0

type E2EFile struct {
	Uuid     string `json:"uuid"`
	Id       string `json:"id"`
	Filename string `json:"filename"`
	Cipher   []byte `json:"cipher"`
}

E2EFile contains information about a stored e2e file

type E2EHashContent added in v1.6.0

type E2EHashContent struct {
	Filename string `json:"f"`
	Cipher   string `json:"c"`
}

E2EHashContent contains the info that is added after the hash for an e2e link

type E2EInfoEncrypted added in v1.6.0

type E2EInfoEncrypted struct {
	// Version of the E2E used, must be at least 1
	Version int `json:"version" redis:"version"`
	// Nonce used for encryption
	Nonce []byte `json:"nonce" redis:"nonce"`
	// Content that is encrypted
	Content []byte `json:"content" redis:"content"`
	// AvailableFiles contains a list of all files on the webserver and will be populated
	// when reading from the database, but will not be saved to the database
	AvailableFiles []string `json:"availablefiles" redis:"-"`
}

E2EInfoEncrypted is the struct that is stored on the server and decrypted locally

func (*E2EInfoEncrypted) HasBeenSetUp added in v1.6.0

func (e *E2EInfoEncrypted) HasBeenSetUp() bool

HasBeenSetUp returns true if E2E setup has been run

type E2EInfoPlainText added in v1.6.0

type E2EInfoPlainText struct {
	Files []E2EFile `json:"files"`
}

E2EInfoPlainText is stored locally and will be encrypted before storing on server

type Encryption

type Encryption struct {
	Level        int
	Cipher       []byte
	Salt         string
	Checksum     string
	ChecksumSalt string
}

Encryption hold information about the encryption used on this file

type EncryptionInfo

type EncryptionInfo struct {
	IsEncrypted         bool   `json:"IsEncrypted"`
	IsEndToEndEncrypted bool   `json:"IsEndToEndEncrypted"`
	DecryptionKey       []byte `json:"DecryptionKey"`
	Nonce               []byte `json:"Nonce"`
}

EncryptionInfo holds information about the encryption used on the file

type File

type File struct {
	Id                 string         `json:"Id"`                 // The internal ID of the file
	Name               string         `json:"Name"`               // The filename. Will be 'Encrypted file' for end-to-end encrypted files
	Size               string         `json:"Size"`               // Filesize in a human-readable format
	SHA1               string         `json:"SHA1"`               // The hash of the file, used for deduplication
	PasswordHash       string         `json:"PasswordHash"`       // The hash of the password (if the file is password protected)
	HotlinkId          string         `json:"HotlinkId"`          // If file is a picture file and can be hotlinked, this is the ID for the hotlink
	ContentType        string         `json:"ContentType"`        // The MIME type for the file
	AwsBucket          string         `json:"AwsBucket"`          // If the file is stored in the cloud, this is the bucket that is being used
	ExpireAtString     string         `json:"ExpireAtString"`     // Time expiry in a human-readable format in local time
	ExpireAt           int64          `json:"ExpireAt"`           // "UTC timestamp of file expiry
	SizeBytes          int64          `json:"SizeBytes"`          // Filesize in bytes
	DownloadsRemaining int            `json:"DownloadsRemaining"` // The remaining downloads for this file
	DownloadCount      int            `json:"DownloadCount"`      // The amount of times the file has been downloaded
	Encryption         EncryptionInfo `json:"Encryption"`         // If the file is encrypted, this stores all info for decrypting
	UnlimitedDownloads bool           `json:"UnlimitedDownloads"` // True if the uploader did not limit the downloads
	UnlimitedTime      bool           `json:"UnlimitedTime"`      // True if the uploader did not limit the time
}

File is a struct used for saving information about an uploaded file

func (*File) IsLocalStorage added in v1.6.0

func (f *File) IsLocalStorage() bool

IsLocalStorage returns true if the file is not stored on a remote storage

func (*File) RequiresClientDecryption added in v1.7.0

func (f *File) RequiresClientDecryption() bool

RequiresClientDecryption checks if the file needs to be decrypted by the client (if remote storage or end-to-end encryption)

func (*File) ToFileApiOutput added in v1.6.0

func (f *File) ToFileApiOutput(serverUrl string, useFilenameInUrl bool) (FileApiOutput, error)

ToFileApiOutput returns a json object without sensitive information

func (*File) ToJsonResult

func (f *File) ToJsonResult(serverUrl string, includeFilename bool) string

ToJsonResult converts the file info to a json String used for returning a result for an upload

type FileApiOutput added in v1.6.0

type FileApiOutput struct {
	Id                           string `json:"Id"`                           // The internal ID of the file
	Name                         string `json:"Name"`                         // The filename. Will be 'Encrypted file' for end-to-end encrypted files
	Size                         string `json:"Size"`                         // Filesize in a human-readable format
	HotlinkId                    string `json:"HotlinkId"`                    // If file is a picture file and can be hotlinked, this is the ID for the hotlink
	ContentType                  string `json:"ContentType"`                  // The MIME type for the file
	ExpireAtString               string `json:"ExpireAtString"`               // Time expiry in a human-readable format in local time
	UrlDownload                  string `json:"UrlDownload"`                  // The public download URL for the file
	UrlHotlink                   string `json:"UrlHotlink"`                   // The public hotlink URL for the file
	ExpireAt                     int64  `json:"ExpireAt"`                     // "UTC timestamp of file expiry
	SizeBytes                    int64  `json:"SizeBytes"`                    // Filesize in bytes
	DownloadsRemaining           int    `json:"DownloadsRemaining"`           // The remaining downloads for this file
	DownloadCount                int    `json:"DownloadCount"`                // The amount of times the file has been downloaded
	UnlimitedDownloads           bool   `json:"UnlimitedDownloads"`           // True if the uploader did not limit the downloads
	UnlimitedTime                bool   `json:"UnlimitedTime"`                // True if the uploader did not limit the time
	RequiresClientSideDecryption bool   `json:"RequiresClientSideDecryption"` // True if the file has to be decrypted client-side
	IsEncrypted                  bool   `json:"IsEncrypted"`                  // True if the file is encrypted
	IsPasswordProtected          bool   `json:"IsPasswordProtected"`          // True if a password has to be entered before downloading the file
	IsSavedOnLocalStorage        bool   `json:"IsSavedOnLocalStorage"`        // True if the file does not use cloud storage
}

FileApiOutput will be displayed for public outputs from the ID, hiding sensitive information

type Result

type Result struct {
	Result          string        `json:"Result"`
	FileInfo        FileApiOutput `json:"FileInfo"`
	IncludeFilename bool          `json:"IncludeFilename"`
}

Result is the struct used for the result after an upload swagger:model UploadResult

type Session

type Session struct {
	RenewAt    int64 `redis:"renew_at"`
	ValidUntil int64 `redis:"valid_until"`
}

Session contains cookie parameter

type UploadRequest

type UploadRequest struct {
	AllowedDownloads    int
	Expiry              int
	ExpiryTimestamp     int64
	Password            string
	ExternalUrl         string
	MaxMemory           int
	UnlimitedDownload   bool
	UnlimitedTime       bool
	IsEndToEndEncrypted bool
	RealSize            int64
}

UploadRequest is used to set an upload request

type UploadStatus added in v1.7.0

type UploadStatus struct {
	// ChunkId is the identifier for the chunk
	ChunkId string `json:"chunkid"`
	// CurrentStatus indicates if the chunk is currently being processed (e.g. encrypting or
	// hashing) or being moved/uploaded to the file storage
	// See processingstatus for definition
	CurrentStatus int `json:"currentstatus"`
}

UploadStatus contains information about the current status of a file upload

func (*UploadStatus) ToJson added in v1.7.0

func (u *UploadStatus) ToJson() ([]byte, error)

ToJson returns the struct as a Json byte array

Jump to

Keyboard shortcuts

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