models

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NotFoundError error from server
	NotFoundError string = "Not found"
	// ActionNotAllowed error from server
	ActionNotAllowed string = "Action not allowed"
	// WrongLength error from server
	WrongLength string = "Wrong length"
	// ServerError error from server
	ServerError string = "Server Error"
	// WrongInputFormatError wrong user input
	WrongInputFormatError string = "Wrong inputFormat!"
	// InvalidTokenError token is not valid
	InvalidTokenError string = "Token not valid"
	// InvalidCallbackURL token is not valid
	InvalidCallbackURL string = "Callback url is invalid"
	// BatchSizeTooLarge batch is too large
	BatchSizeTooLarge string = "BatchSize soo large!"
	// WrongIntegerFormat integer is probably no integer
	WrongIntegerFormat string = "Number is string"
	// MultipleSourceNameErr err name already exists
	MultipleSourceNameErr string = "You can't have multiple sources with the same name"
	// UserIsInvalidErr err if user is invalid
	UserIsInvalidErr string = "user is invalid"
)
View Source
const (
	// HeaderStatus headername for status in response
	HeaderStatus string = "X-Response-Status"

	// HeaderStatusMessage headername for status in response
	HeaderStatusMessage string = "X-Response-Message"

	// HeaderContentType contenttype of response
	HeaderContentType string = "Content-Type"

	// HeaderFileName filename header
	HeaderFileName string = "X-Filename"

	// HeaderFileID fileid header
	HeaderFileID string = "X-FileID"

	// HeaderEncryption encryption header
	HeaderEncryption string = "X-Encryption"

	// HeaderRequest request content
	HeaderRequest string = "Request"

	// HeaderContentLength request content length
	HeaderContentLength string = "ContentLength"

	// HeaderChecksum files checksum
	HeaderChecksum string = "Checksum"
)
View Source
const SessionTokenLength = 64

SessionTokenLength length of session token

Variables

View Source
var ErrorUserAlreadyExists = errors.New("user already exists")

ErrorUserAlreadyExists error if user exists

View Source
var PreviewMimes map[PreviewType][]string = map[PreviewType][]string{
	ImagePreviewType: {
		"image/*",
	},
	VideoPreviewType: {
		"video/*",
	},
	TextPreviewType: {
		"text/*",
	},
}

PreviewMimes mimes assigned to preview

Functions

func DirExists

func DirExists(path string) bool

DirExists return true if dir exists

func GetDefaultConfig

func GetDefaultConfig() string

GetDefaultConfig gets the default config path

func GroupArrToStringArr

func GroupArrToStringArr(groups []Group) []string

GroupArrToStringArr return string arr from group

func IsDefaultPreview

func IsDefaultPreview(pt PreviewType) bool

IsDefaultPreview return true if pt is default previewtype

func IsImagePreview

func IsImagePreview(pt PreviewType) bool

IsImagePreview return true if pt is image previewtype

func IsTextPreview

func IsTextPreview(pt PreviewType) bool

IsTextPreview return true if pt is text previewtype

func IsVideoPreview added in v1.1.0

func IsVideoPreview(pt PreviewType) bool

IsVideoPreview return true if pt is video previewtype

func ShredderFile

func ShredderFile(localFile string, size int64)

ShredderFile shreddres a file

func TagArrToStringArr

func TagArrToStringArr(tags []Tag) []string

TagArrToStringArr return string arr from tags

Types

type BulkPublishResponse

type BulkPublishResponse struct {
	Files []UploadResponse `json:"files"`
}

BulkPublishResponse response for publishing a file

type Config

type Config struct {
	Server    configServer
	Webserver webserverConf
}

Config config for the server

func InitConfig

func InitConfig(confFile string, createMode bool) (*Config, bool)

InitConfig inits the config Returns true if system should exit

func (*Config) Check

func (config *Config) Check() bool

Check check the config file of logical errors

func (Config) GetDefaultRole

func (config Config) GetDefaultRole() *Role

GetDefaultRole return the path and file for an uploaded file

func (Config) GetHTMLFile

func (config Config) GetHTMLFile(fileName string) string

GetHTMLFile return path of html file

func (Config) GetStaticFile

func (config Config) GetStaticFile(fileName string) string

GetStaticFile return path of html file

func (Config) GetStorageFile

func (config Config) GetStorageFile(fileName string) string

GetStorageFile return the path and file for an uploaded file

func (Config) GetTemplateFile

func (config Config) GetTemplateFile(fileName string) string

GetTemplateFile return path of html file

func (Config) IsRawUseragent

func (config Config) IsRawUseragent(agent string) bool

IsRawUseragent return true if file should be raw depending on useragent

type CountResponse

type CountResponse struct {
	Count uint32 `json:"count"`
}

CountResponse response containing a count of changed items

type CredentialsRequest

type CredentialsRequest struct {
	MachineID string `json:"mid,omitempty"`
	Username  string `json:"username"`
	Password  string `json:"pass"`
}

CredentialsRequest request containing credentials

type File

type File struct {
	gorm.Model
	Name           string `gorm:"not null"`
	LocalName      string `gorm:"not null"`
	User           *User  `gorm:"association_autoupdate:false;association_autocreate:false"`
	UserID         uint   `gorm:"column:uploader;index"`
	FileSize       int64
	FileType       string
	IsPublic       bool           `gorm:"default:false"`
	PublicFilename sql.NullString `gorm:"unique"`
	Groups         []Group        `gorm:"many2many:files_groups;association_autoupdate:false"`
	Tags           []Tag          `gorm:"many2many:files_tags;association_autoupdate:false"`
	Namespace      *Namespace     `gorm:"association_autoupdate:false;association_autocreate:false;"`
	NamespaceID    uint           `sql:"index" gorm:"not null"`
	Encryption     sql.NullInt32
	Checksum       string
}

File a file uploaded to the db

func FindFile

func FindFile(db *gorm.DB, fileID, userID uint) (*File, error)

FindFile finds a file

func FindFiles

func FindFiles(db *gorm.DB, file File) ([]File, error)

FindFiles finds file

func GetPublicFile

func GetPublicFile(db *gorm.DB, publicFilename string) (*File, bool, error)

GetPublicFile returns a file which is public

func (*File) AddGroups

func (file *File) AddGroups(db *gorm.DB, groupsToAdd []string, user *User) error

AddGroups adds groups to file

func (*File) AddTags

func (file *File) AddTags(db *gorm.DB, tagsToAdd []string, user *User) error

AddTags adds tags to file

func (*File) Delete

func (file *File) Delete(db *gorm.DB, config *Config) error

Delete deletes a file

func (File) GetAttributes

func (file File) GetAttributes() FileAttributes

GetAttributes get file attributes

func (File) GetCount

func (file File) GetCount(db *gorm.DB, fileID uint) (uint, error)

GetCount get count if file

func (File) GetNamespace

func (file File) GetNamespace() *Namespace

GetNamespace return namespace of file

func (*File) GetPublicNameWithExtension added in v1.1.0

func (file *File) GetPublicNameWithExtension() string

GetPublicNameWithExtension return the public name ending with the real file extension

func (File) HasGroup

func (file File) HasGroup(sGroup string) bool

HasGroup return true if file is in group

func (File) HasTag

func (file File) HasTag(sTag string) bool

HasTag return true if file is in group

func (*File) Insert

func (file *File) Insert(db *gorm.DB, user *User) error

Insert inserts file into DB

func (File) IsInGroupList

func (file File) IsInGroupList(groups []string) bool

IsInGroupList return true if file is in one of the specified groups

func (File) IsInTagList

func (file File) IsInTagList(tags []string) bool

IsInTagList return true if file has one of the specified tags

func (*File) Publish

func (file *File) Publish(db *gorm.DB, publicName string) (bool, error)

Publish publis a file

func (*File) RemoveGroups

func (file *File) RemoveGroups(db *gorm.DB, groupsToRemove []string) error

RemoveGroups remove groups from file

func (*File) RemoveTags

func (file *File) RemoveTags(db *gorm.DB, tagsToRemove []string) error

RemoveTags remove tags to file

func (*File) Rename

func (file *File) Rename(db *gorm.DB, newName string) error

Rename renames a file

func (*File) Save

func (file *File) Save(db *gorm.DB) error

Save saves a file in DB

func (*File) SetEncryption

func (file *File) SetEncryption(encription string) *File

SetEncryption set encryption

func (*File) SetUniqueFilename

func (file *File) SetUniqueFilename(db *gorm.DB) bool

SetUniqueFilename sets unique filename

func (*File) SetVilibility

func (file *File) SetVilibility(db *gorm.DB, newVisibility bool) error

SetVilibility sets public/private

func (*File) UpdateNamespace

func (file *File) UpdateNamespace(db *gorm.DB, newNamespace *Namespace, user *User) error

UpdateNamespace updates namespace for file

type FileAttributes

type FileAttributes struct {
	Tags      []string `json:"tags,omitempty"`
	Groups    []string `json:"groups,omitempty"`
	Namespace string   `json:"ns"`
}

FileAttributes attributes for a file

type FileListRequest

type FileListRequest struct {
	FileID         uint                     `json:"fid"`
	Name           string                   `json:"name"`
	AllNamespaces  bool                     `json:"allns"`
	OptionalParams OptionalRequetsParameter `json:"opt"`
	Attributes     FileAttributes           `json:"attributes"`
}

FileListRequest contains file info (and a file)

type FileRequest

type FileRequest struct {
	FileID     uint           `json:"fid"`
	Name       string         `json:"name,omitempty"`
	PublicName string         `json:"pubname,omitempty"`
	Updates    FileUpdateItem `json:"updates,omitempty"`
	All        bool           `json:"all"`
	Attributes FileAttributes `json:"attributes"`
}

FileRequest contains data to update a file

type FileResponseItem

type FileResponseItem struct {
	ID           uint           `json:"id"`
	Size         int64          `json:"size"`
	CreationDate time.Time      `json:"creation"`
	Name         string         `json:"name"`
	PublicName   string         `json:"pubname"`
	IsPublic     bool           `json:"isPub"`
	Attributes   FileAttributes `json:"attrib"`
	Encryption   string         `json:"e"`
	Checksum     string         `json:"checksum"`
}

FileResponseItem file item for file response

type FileUpdateItem

type FileUpdateItem struct {
	IsPublic     string   `json:"ispublic,omitempty"`
	NewName      string   `json:"name,omitempty"`
	NewNamespace string   `json:"namespace,omitempty"`
	RemoveTags   []string `json:"rem_tags,omitempty"`
	RemoveGroups []string `json:"rem_groups,omitempty"`
	AddTags      []string `json:"add_tags,omitempty"`
	AddGroups    []string `json:"add_groups,omitempty"`
}

FileUpdateItem lists changes to a file

type Group

type Group struct {
	gorm.Model
	Name        string     `gorm:"not null"`
	NamespaceID uint       `sql:"index" gorm:"not null"`
	Namespace   *Namespace `gorm:"association_autoupdate:false;association_autocreate:false"`
	UserID      uint       `sql:"index" gorm:"not null"`
	User        *User      `gorm:"association_autoupdate:false;association_autocreate:false"`
}

Group a group in DB

func FindGroup

func FindGroup(db *gorm.DB, name string, namespace *Namespace, user *User) (*Group, error)

FindGroup finds a group

func FindGroups

func FindGroups(db *gorm.DB, sGroups []string, namespace *Namespace) []Group

FindGroups find group in db

func GetGroup

func GetGroup(db *gorm.DB, name string, namespace *Namespace, user *User) *Group

GetGroup returns or creates a group

func GroupsFromStringArr

func GroupsFromStringArr(arr []string, namespace Namespace, user *User) []Group

GroupsFromStringArr return tag array from string array

func (Group) GetNamespace

func (group Group) GetNamespace() *Namespace

GetNamespace return namespace of group

func (*Group) Insert

func (group *Group) Insert(db *gorm.DB, user *User) error

Insert inserts group into DB

type IDsResponse added in v1.1.0

type IDsResponse struct {
	IDs []uint `json:"ids"`
}

IDsResponse response containing a list of ids

type ListFileResponse

type ListFileResponse struct {
	Files []FileResponseItem `json:"files"`
}

ListFileResponse response for list files

type LoginResponse

type LoginResponse struct {
	Token     string `json:"token"`
	Namespace string `json:"ns"`
}

LoginResponse response for login

type LoginSession

type LoginSession struct {
	gorm.Model
	User      *User `gorm:"association_autoupdate:false;association_autocreate:false"`
	UserID    uint
	Token     string
	Requests  int64
	MachineID string
}

LoginSession session for loggedin user

func NewSession

func NewSession(user *User, machineID string) *LoginSession

NewSession create new login session

type Namespace

type Namespace struct {
	gorm.Model
	Name   string `gorm:"not null"`
	UserID uint   `gorm:"column:creator;index"`
	User   *User  `gorm:"association_autoupdate:false;association_autocreate:false"`
}

Namespace a namespace for files

func FindNamespace

func FindNamespace(db *gorm.DB, ns string, user *User) *Namespace

FindNamespace find namespace in DB

func FindUserNamespaces

func FindUserNamespaces(db *gorm.DB, user *User) ([]Namespace, error)

FindUserNamespaces get all namespaces for user

func GetNamespaceFromString

func GetNamespaceFromString(ns string) *Namespace

GetNamespaceFromString return namespace from string

func (*Namespace) Create added in v1.1.0

func (namespace *Namespace) Create(db *gorm.DB) error

Create a namespace

func (*Namespace) IsOwnedBy

func (namespace *Namespace) IsOwnedBy(user *User) bool

IsOwnedBy returns true if namespace is users

func (*Namespace) IsValid

func (namespace *Namespace) IsValid() bool

IsValid return true if namespace is valid

type NamespaceRequest

type NamespaceRequest struct {
	Namespace string `json:"ns"`
	NewName   string `json:"newName,omitempty"`
}

NamespaceRequest namespace action request

type Namespaceinfo added in v1.1.0

type Namespaceinfo struct {
	Name   string   `json:"ns"`
	Groups []string `json:"groups"`
}

Namespaceinfo info for namespace

type OptionalRequetsParameter

type OptionalRequetsParameter struct {
	Verbose uint8 `json:"verb"`
}

OptionalRequetsParameter optional request parameter

type Permission

type Permission uint8

Permission permission for roles

const (
	NoPermission Permission = iota
	ReadPermission
	Writepermission
)

Permissions

type PingRequest

type PingRequest struct {
	Payload string
}

PingRequest ping request

type PreviewTemplate

type PreviewTemplate struct {
	Filename       string
	PublicFilename string
	PreviewType    PreviewType
	Host           string
	FileSizeStr    string
	Encrypted      bool
	MimeType       string
}

PreviewTemplate template struct for preview

type PreviewType

type PreviewType uint8

PreviewType type of preview

const (
	DefaultPreviewType PreviewType = iota
	ImagePreviewType
	VideoPreviewType
	TextPreviewType
)

Preview types

func PreviewTypeFromMime

func PreviewTypeFromMime(sMime string) PreviewType

PreviewTypeFromMime get Type to preview from mime

type PublishResponse

type PublishResponse struct {
	PublicFilename string `json:"pubName"`
}

PublishResponse response for publishing a file

type ResponseStatus

type ResponseStatus uint8

ResponseStatus the status of response

const (
	//ResponseError if there was an error
	ResponseError ResponseStatus = 0
	//ResponseSuccess if the response is successful
	ResponseSuccess ResponseStatus = 1
)

type Role

type Role struct {
	ID                     uint       `gorm:"pk"`
	RoleName               string     `gorm:"not null"`
	IsAdmin                bool       `gorm:"default:false"`
	AccesForeignNamespaces Permission `gorm:"type:smallint"`
	MaxURLcontentSize      int64
	MaxUploadFileSize      int64
	CreateNamespaces       bool
}

Role roles for user

type StringResponse

type StringResponse struct {
	String string `json:"content"`
}

StringResponse response containing only one string

type StringSliceResponse

type StringSliceResponse struct {
	Slice []string `json:"slice"`
}

StringSliceResponse response containing only one string slice

type Tag

type Tag struct {
	gorm.Model
	Name        string     `gorm:"not null"`
	NamespaceID uint       `sql:"index" gorm:"not null"`
	Namespace   *Namespace `gorm:"association_autoupdate:false;association_autocreate:false"`
	UserID      uint       `sql:"index" gorm:"not null"`
	User        *User      `gorm:"association_autoupdate:false;association_autocreate:false"`
}

Tag a filetag

func FindTag

func FindTag(db *gorm.DB, name string, namespace *Namespace, user *User) (*Tag, error)

FindTag finds a tag

func FindTags

func FindTags(db *gorm.DB, sTags []string, namespace *Namespace) []Tag

FindTags find namespace in DB

func GetTag

func GetTag(db *gorm.DB, name string, namespace *Namespace, user *User) *Tag

GetTag returns or creates a tag

func TagsFromStringArr

func TagsFromStringArr(arr []string, namespace Namespace, user *User) []Tag

TagsFromStringArr return tag array from string array

func (Tag) GetNamespace

func (tag Tag) GetNamespace() *Namespace

GetNamespace return namespace of tag

func (*Tag) Insert

func (tag *Tag) Insert(db *gorm.DB, user *User) error

Insert inserts tag into DB

type UpdateAttributeRequest

type UpdateAttributeRequest struct {
	Name      string `json:"name"`
	NewName   string `json:"newname"`
	Namespace string `json:"namespace"`
}

UpdateAttributeRequest contains data to update a tag

type UploadRequest

type UploadRequest struct {
	UploadType  UploadType     `json:"type"`
	URL         string         `json:"url,omitempty"`
	Name        string         `json:"name"`
	Public      bool           `json:"pb,omitempty"`
	PublicName  string         `json:"pbname,omitempty"`
	Attributes  FileAttributes `json:"attr,omitempty"`
	Encryption  string         `json:"e,omitempty"`
	ReplaceFile uint           `json:"r,omitempty"`
	Size        int64          `json:"s"`
}

UploadRequest contains file info (and a file)

type UploadResponse

type UploadResponse struct {
	FileID         uint   `json:"fileID"`
	Filename       string `json:"filename"`
	PublicFilename string `json:"publicFilename,omitempty"`
	Checksum       string `json:"checksum"`
	FileSize       int64  `json:"size"`
	Namespace      string `json:"ns"`
}

UploadResponse response for uploading file

type UploadType

type UploadType uint8

UploadType type of upload

const (
	FileUploadType UploadType = iota
	URLUploadType
)

Available upload types

type User

type User struct {
	gorm.Model
	Username string
	Password string
	RoleID   uint  `sql:"index"`
	Role     *Role `gorm:"association_autoupdate:false;association_autocreate:false"`
}

User user in db

func GetUserFromSession

func GetUserFromSession(db *gorm.DB, token string) (*User, error)

GetUserFromSession return user from session

func (User) AllowedToUploadURLs

func (user User) AllowedToUploadURLs() bool

AllowedToUploadURLs gets upload limit

func (User) CanCreateNamespaces added in v1.1.0

func (user User) CanCreateNamespaces() bool

CanCreateNamespaces return true if user can create user namespaces

func (User) CanReadForeignNamespace

func (user User) CanReadForeignNamespace() bool

CanReadForeignNamespace return true if user is allowed to read in foreign namespaces

func (User) CanUploadFiles

func (user User) CanUploadFiles() bool

CanUploadFiles return true if user can upload files

func (User) CanWriteForeignNamespace

func (user User) CanWriteForeignNamespace() bool

CanWriteForeignNamespace return true if user is allowed to write in foreign namespaces

func (*User) CreateDefaultNamespace

func (user *User) CreateDefaultNamespace(db *gorm.DB) (*Namespace, error)

CreateDefaultNamespace creates user namespace

func (*User) GetAllGroups added in v1.1.0

func (user *User) GetAllGroups(db *gorm.DB) ([]Group, error)

GetAllGroups gets all groups for an user

func (*User) GetDefaultNamespaceName

func (user *User) GetDefaultNamespaceName() string

GetDefaultNamespaceName return the name of the default namespace for a user

func (*User) GetNamespaceName added in v1.1.0

func (user *User) GetNamespaceName(namespace string) string

GetNamespaceName gets the namespace for an user

func (*User) GetUsername added in v1.1.0

func (user *User) GetUsername() string

GetUsername Gets username of user

func (*User) Has

func (user *User) Has(db *gorm.DB, checkPass bool) (bool, error)

Has return true if user exists

func (*User) HasAccess

func (user *User) HasAccess(namespace *Namespace) bool

HasAccess return true if user has access to the given namespace

func (User) HasUploadLimit

func (user User) HasUploadLimit() bool

HasUploadLimit gets upload limit

func (*User) Login

func (user *User) Login(db *gorm.DB, machineID string) (*LoginSession, error)

Login login user

func (User) Register

func (user User) Register(db *gorm.DB, config *Config) error

Register register user

type UserAttributeDataResponse added in v1.1.0

type UserAttributeDataResponse struct {
	Namespace []Namespaceinfo `json:"nsData"`
}

UserAttributeDataResponse response for userattribute data

type UserAttributesRequest added in v1.1.0

type UserAttributesRequest struct {
	Mode uint `json:"m"`
}

UserAttributesRequest request for getting namespaces and groups

Jump to

Keyboard shortcuts

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