Documentation
¶
Index ¶
- Constants
- Variables
- func NewRevisionReaderWriter(db *gorm.DB) migrate.RevisionReadWriter
- type AccountStats
- type Accounts
- type AtlasSchemaRevision
- type CreateFileEntryInput
- type Database
- func (db *Database) AccountAmount() (count int64, err error)
- func (db *Database) AddTagToFile(fileName string, tagName string, accountID uint) (err error)
- func (db *Database) AllAccountStats() (stats map[uint]AccountStats, err error)
- func (db *Database) BumpFileViews(fileName string, ip string) (err error)
- func (db *Database) CleanupOrphanedTags() (deleted int64, err error)
- func (db *Database) CreateAccount(accountType string, invitedBy uint) (account Accounts, err error)
- func (db *Database) CreateFileEntry(input CreateFileEntryInput) error
- func (db *Database) CreateInviteCode(uses uint, accountType string, inviteCreatorID uint) (inviteCode InviteCodes, err error)
- func (db *Database) CreateInviteCodeWithCode(code string, uses uint, accountType string, inviteCreatorID uint) (inviteCode InviteCodes, err error)
- func (db *Database) CreateSessionToken(accountID uint) (sessionToken uuid.UUID, err error)
- func (db *Database) CreateUploadToken(accountID uint, nickname string) (uploadToken uuid.UUID, err error)
- func (db *Database) DeleteAccount(accountID uint) error
- func (db *Database) DeleteExpiredInviteCodes() (err error)
- func (db *Database) DeleteExpiredSessionTokens() (err error)
- func (db *Database) DeleteFileEntry(fileName string, accountID uint) (deleted bool, err error)
- func (db *Database) DeleteFilesFromAccount(accountID uint) (err error)
- func (db *Database) DeleteInviteCode(code string, accountID uint) (err error)
- func (db *Database) DeleteInviteCodesFromAccount(accountID uint) (err error)
- func (db *Database) DeleteSession(sessionToken uuid.UUID) (err error)
- func (db *Database) DeleteSessionsFromAccount(accountID uint) (err error)
- func (db *Database) DeleteUploadToken(accountID uint, uploadToken uuid.UUID) (err error)
- func (db *Database) DeleteUploadTokensFromAccount(accountID uint) (err error)
- func (db *Database) FileHasTag(fileName string, tagName string, accountID uint) (hasTag bool, err error)
- func (db *Database) FindAccountByGithubID(rawID string) (account Accounts, err error)
- func (db *Database) FindAccountByOIDCID(oidcID string) (account Accounts, err error)
- func (db *Database) FindExpiredFiles() (files []Files, err error)
- func (db *Database) GetAccountByID(accountID uint) (account Accounts, err error)
- func (db *Database) GetAccountBySessionToken(sessionToken uuid.UUID) (account Accounts, err error)
- func (db *Database) GetAccountByUploadToken(uploadToken uuid.UUID) (account Accounts, err error)
- func (db *Database) GetAccountTags(accountID uint) (tags []string, err error)
- func (db *Database) GetAccounts() (accounts []Accounts, err error)
- func (db *Database) GetAllFilesFromAccount(accountID uint) (files []Files, err error)
- func (db *Database) GetFileByName(fileName string) (file Files, err error)
- func (db *Database) GetFileStats(accountID uint) (totalFiles uint, totalStorage uint, err error)
- func (db *Database) GetFilesPaginatedFromAccount(accountID, skip, limit uint, sort string, desc bool, tag string, filter string) (files []Files, totalCount int64, err error)
- func (db *Database) GetSessionsCount(accountID uint) (count int64, err error)
- func (db *Database) GetUploadTokens(accountID uint) (uploadTokens []UiUploadToken, err error)
- func (db *Database) GetUploadTokensCount(accountID uint) (count int64, err error)
- func (db *Database) InviteCodeAmount() (count int64, err error)
- func (db *Database) InviteCodesByAccount(accountID uint) (inviteCodes []InviteCodes, err error)
- func (db *Database) LastAccountActivity(accountID uint) (time.Time, error)
- func (db *Database) LinkGithub(accountID uint, username string, rawGithubID string) (err error)
- func (db *Database) LinkOIDC(accountID uint, username string, oidcID string) (err error)
- func (db *Database) RegisterWithInviteCode(code string) (account Accounts, sessionToken uuid.UUID, err error)
- func (db *Database) RemoveTagFromFile(fileName string, tagName string, accountID uint) (err error)
- func (db *Database) ToggleFilePublic(fileName string, accountID uint) (newPublicStatus bool, err error)
- func (db *Database) UnlinkGithub(accountID uint) error
- func (db *Database) UnlinkOIDC(accountID uint) error
- func (db *Database) UpdateGithubUsername(accountID uint, username string) (err error)
- func (db *Database) UpdateOIDCUsername(accountID uint, username string) (err error)
- func (db *Database) UseCode(code string) (accountType string, invitedBy uint, err error)
- type FileViews
- type Files
- type GormRevisionReadWriter
- func (g *GormRevisionReadWriter) DeleteRevision(ctx context.Context, version string) (err error)
- func (g *GormRevisionReadWriter) Ident() *migrate.TableIdent
- func (g *GormRevisionReadWriter) ReadRevision(ctx context.Context, version string) (rev *migrate.Revision, err error)
- func (g *GormRevisionReadWriter) ReadRevisions(ctx context.Context) (revisions []*migrate.Revision, err error)
- func (g *GormRevisionReadWriter) WriteRevision(ctx context.Context, rev *migrate.Revision) (err error)
- type InviteCodes
- type SessionTokens
- type Tag
- type UiUploadToken
- type UploadTokens
Constants ¶
View Source
const ( TagMaxLength = 25 MaxTagsPerFile = 50 )
View Source
const SessionTokenDuration = 7 * 24 * time.Hour
Variables ¶
View Source
var ( ErrTagTooLong = errors.New("tag too long") ErrTooManyTags = errors.New("too many tags") )
View Source
var ErrInvalidAccountType = errors.New("invalid account type specified")
View Source
var ErrNotAuthenticated = errors.New("not authenticated")
View Source
var ErrProviderAlreadyLinked = errors.New("provider identity already linked to another account")
Functions ¶
func NewRevisionReaderWriter ¶
func NewRevisionReaderWriter(db *gorm.DB) migrate.RevisionReadWriter
Types ¶
type AccountStats ¶
type Accounts ¶
type Accounts struct {
ID uint `gorm:"primaryKey"` // Internal numeric account ID
CreatedAt time.Time
UpdatedAt time.Time
// GithubID is 0 when unlinked, otherwise the account's GitHub user id.
// Partial unique index prevents two accounts from linking the same GitHub identity.
GithubID uint `gorm:"uniqueIndex:idx_accounts_github_id,where:github_id <> 0"`
GithubUsername string
// OIDCID is empty when unlinked, same uniqueness guarantee as above.
OIDCID string `gorm:"column:oidc_id;uniqueIndex:idx_accounts_oidc_id,where:oidc_id <> ''"`
OIDCUsername string `gorm:"column:oidc_username"`
InvitedBy uint // Account ID of the user who invited this account
AccountType string // Either "USER" or "ADMIN"
}
type AtlasSchemaRevision ¶
type AtlasSchemaRevision struct {
Version string `gorm:"primaryKey;column:version"`
Description string `gorm:"column:description"`
Type uint `gorm:"column:type"`
Applied int `gorm:"column:applied"`
Total int `gorm:"column:total"`
ExecutedAt time.Time `gorm:"column:executed_at"`
ExecutionTime int64 `gorm:"column:execution_time"` // Duration in nanoseconds
Error string `gorm:"column:error"`
ErrorStmt string `gorm:"column:error_stmt"`
Hash string `gorm:"column:hash"`
PartialHashes string `gorm:"column:partial_hashes"` // JSON-encoded []string
OperatorVersion string `gorm:"column:operator_version"`
}
func (AtlasSchemaRevision) TableName ¶
func (AtlasSchemaRevision) TableName() string
type CreateFileEntryInput ¶
type Database ¶
func (*Database) AccountAmount ¶
func (db *Database) fileAdd Returns number of accounts in the database
func (*Database) AddTagToFile ¶
func (*Database) AllAccountStats ¶
func (db *Database) AllAccountStats() (stats map[uint]AccountStats, err error)
func (*Database) BumpFileViews ¶
func (*Database) CleanupOrphanedTags ¶
func (*Database) CreateAccount ¶
func (*Database) CreateFileEntry ¶
func (db *Database) CreateFileEntry(input CreateFileEntryInput) error
Creates file entry in database
func (*Database) CreateInviteCode ¶
func (*Database) CreateInviteCodeWithCode ¶
func (*Database) CreateSessionToken ¶
func (*Database) CreateUploadToken ¶
func (*Database) DeleteAccount ¶
func (*Database) DeleteExpiredInviteCodes ¶
func (*Database) DeleteExpiredSessionTokens ¶
func (*Database) DeleteFileEntry ¶
Deletes file entry from database
func (*Database) DeleteFilesFromAccount ¶
Only deletes database entry, actual file has to be deleted as well
func (*Database) DeleteInviteCode ¶
func (*Database) DeleteInviteCodesFromAccount ¶
func (*Database) DeleteSession ¶
func (*Database) DeleteSessionsFromAccount ¶
func (*Database) DeleteUploadToken ¶
func (*Database) DeleteUploadTokensFromAccount ¶
func (*Database) FileHasTag ¶
func (*Database) FindAccountByGithubID ¶
func (*Database) FindAccountByOIDCID ¶
func (*Database) FindExpiredFiles ¶
func (*Database) GetAccountByID ¶
func (*Database) GetAccountBySessionToken ¶
func (*Database) GetAccountByUploadToken ¶
func (*Database) GetAccountTags ¶
func (*Database) GetAccounts ¶
func (*Database) GetAllFilesFromAccount ¶
func (*Database) GetFileByName ¶
func (*Database) GetFileStats ¶
func (*Database) GetFilesPaginatedFromAccount ¶
func (*Database) GetSessionsCount ¶
func (*Database) GetUploadTokens ¶
func (db *Database) GetUploadTokens(accountID uint) (uploadTokens []UiUploadToken, err error)
func (*Database) GetUploadTokensCount ¶
func (*Database) InviteCodeAmount ¶
func (*Database) InviteCodesByAccount ¶
func (db *Database) InviteCodesByAccount(accountID uint) (inviteCodes []InviteCodes, err error)
func (*Database) LastAccountActivity ¶
Returns the latest time a session token or an upload token was used
func (*Database) LinkGithub ¶
func (*Database) RegisterWithInviteCode ¶
func (*Database) RemoveTagFromFile ¶
func (*Database) ToggleFilePublic ¶
func (*Database) UnlinkGithub ¶
func (*Database) UnlinkOIDC ¶
func (*Database) UpdateGithubUsername ¶
func (*Database) UpdateOIDCUsername ¶
type Files ¶
type Files struct {
ID uint `gorm:"primaryKey" json:"-"`
CreatedAt time.Time
UpdatedAt time.Time ` json:"-"`
FileName string `gorm:"uniqueIndex"` // Newly generated file name
OriginalFileName string // Original file name from upload
FileSize uint
MimeType string
Public bool // If false, only the uploader can see the file
Views []FileViews `gorm:"foreignKey:FilesID;constraint:OnDelete:CASCADE" json:"-"`
ViewsCount uint `gorm:"-"` // Used for export
ExpiryDate time.Time `gorm:"default:null"` // Time when the file will be deleted
UploaderID uint `json:"-" gorm:"index"`
Uploader Accounts `json:"-" gorm:"foreignKey:UploaderID;constraint:OnDelete:CASCADE"`
Tags []Tag `gorm:"many2many:file_tags;constraint:OnDelete:CASCADE"`
}
type GormRevisionReadWriter ¶
type GormRevisionReadWriter struct {
// contains filtered or unexported fields
}
func (*GormRevisionReadWriter) DeleteRevision ¶
func (g *GormRevisionReadWriter) DeleteRevision(ctx context.Context, version string) (err error)
func (*GormRevisionReadWriter) Ident ¶
func (g *GormRevisionReadWriter) Ident() *migrate.TableIdent
func (*GormRevisionReadWriter) ReadRevision ¶
func (*GormRevisionReadWriter) ReadRevisions ¶
func (*GormRevisionReadWriter) WriteRevision ¶
type InviteCodes ¶
type InviteCodes struct {
ID uint `gorm:"primaryKey"`
CreatedAt time.Time
UpdatedAt time.Time
Code string `gorm:"uniqueIndex"`
Uses uint // How many usages of this code is left
ExpiryDate time.Time
AccountType string // Either registers normal or admin users
InviteCreatorID uint `gorm:"default:null;index"`
InviteCreator Accounts `gorm:"foreignKey:InviteCreatorID;constraint:OnDelete:CASCADE"`
}
type SessionTokens ¶
type UiUploadToken ¶
Click to show internal directories.
Click to hide internal directories.