metadata

package
v0.0.0-...-e675dcb Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	Config *Config
	// contains filtered or unexported fields
}

Backend object

func NewBackend

func NewBackend(config *Config, log *logger.Logger) (b *Backend, err error)

NewBackend instantiate a new File Data Backend from configuration passed as argument

func (*Backend) Clean

func (b *Backend) Clean() (files int, tokens int, err error)

Clean metadata database

  • Remove orphan files and tokens

func (*Backend) CountUploadFiles

func (b *Backend) CountUploadFiles(uploadID string) (count int, err error)

CountUploadFiles count how many files have been added to an upload

func (*Backend) CountUserTokens

func (b *Backend) CountUserTokens(userID string) (count int, err error)

CountUserTokens count how many token a user has

func (*Backend) CountUsers

func (b *Backend) CountUsers() (count int, err error)

CountUsers count the number of user in the DB

func (*Backend) CreateFile

func (b *Backend) CreateFile(file *common.File) (err error)

CreateFile persist a new file to the database

func (*Backend) CreateSetting

func (b *Backend) CreateSetting(setting *common.Setting) (err error)

CreateSetting create a new setting in DB

func (*Backend) CreateToken

func (b *Backend) CreateToken(token *common.Token) (err error)

CreateToken create a new token in DB

func (*Backend) CreateUpload

func (b *Backend) CreateUpload(upload *common.Upload) (err error)

CreateUpload create a new upload in DB

func (*Backend) CreateUser

func (b *Backend) CreateUser(user *common.User) (err error)

CreateUser create a new user in DB

func (*Backend) DeleteRemovedUploads

func (b *Backend) DeleteRemovedUploads() (removed int, err error)

DeleteRemovedUploads delete upload and file metadata from the database once :

  • The upload has been removed (soft delete) either manually or because it expired
  • All the upload files have been deleted from the data backend (status Deleted)

func (*Backend) DeleteSetting

func (b *Backend) DeleteSetting(key string) (err error)

DeleteSetting delete a setting from DB

func (*Backend) DeleteToken

func (b *Backend) DeleteToken(tokenStr string) (deleted bool, err error)

DeleteToken remove a token from the DB

func (*Backend) DeleteUser

func (b *Backend) DeleteUser(userID string) (deleted bool, err error)

DeleteUser delete a user from the DB

func (*Backend) Export

func (b *Backend) Export(path string) (err error)

Export exports all metadata from the backend to a compressed binary file

func (*Backend) ForEachFile

func (b *Backend) ForEachFile(f func(file *common.File) error) (err error)

ForEachFile execute f for every file in the database

func (*Backend) ForEachRemovedFile

func (b *Backend) ForEachRemovedFile(f func(file *common.File) error) (err error)

ForEachRemovedFile execute f for each file with the status "removed"

func (*Backend) ForEachSetting

func (b *Backend) ForEachSetting(f func(setting *common.Setting) error) (err error)

ForEachSetting execute f for every setting in the database

func (*Backend) ForEachToken

func (b *Backend) ForEachToken(f func(token *common.Token) error) (err error)

ForEachToken execute f for every token in the database

func (*Backend) ForEachUpload

func (b *Backend) ForEachUpload(f func(upload *common.Upload) error) (err error)

ForEachUpload execute f for every upload in the database

func (*Backend) ForEachUploadFiles

func (b *Backend) ForEachUploadFiles(uploadID string, f func(file *common.File) error) (err error)

ForEachUploadFiles execute f for each file of the upload

func (*Backend) ForEachUploadUnscoped

func (b *Backend) ForEachUploadUnscoped(f func(upload *common.Upload) error) (err error)

ForEachUploadUnscoped execute f for every upload in the database even soft deleted ones

func (*Backend) ForEachUserUploads

func (b *Backend) ForEachUserUploads(userID string, tokenStr string, f func(upload *common.Upload) error) (err error)

ForEachUserUploads execute f for all upload matching the user and token filters

func (*Backend) ForEachUsers

func (b *Backend) ForEachUsers(f func(user *common.User) error) (err error)

ForEachUsers execute f for every user in the database

func (*Backend) GetFile

func (b *Backend) GetFile(fileID string) (file *common.File, err error)

GetFile return a file from the database ( nil and no error if not found )

func (*Backend) GetFiles

func (b *Backend) GetFiles(uploadID string) (files []*common.File, err error)

GetFiles return all files for the given upload ID

func (*Backend) GetMetricsCollectors

func (b *Backend) GetMetricsCollectors() []prometheus.Collector

GetMetricsCollectors return Gorm metrics

func (*Backend) GetServerStatistics

func (b *Backend) GetServerStatistics() (stats *common.ServerStats, err error)

GetServerStatistics return statistics about user all uploads

func (*Backend) GetSetting

func (b *Backend) GetSetting(key string) (setting *common.Setting, err error)

GetSetting get a setting from DB

func (*Backend) GetToken

func (b *Backend) GetToken(tokenStr string) (token *common.Token, err error)

GetToken return a token from the DB ( return nil and non error if not found )

func (*Backend) GetTokens

func (b *Backend) GetTokens(userID string, pagingQuery *common.PagingQuery) (tokens []*common.Token, cursor *paginator.Cursor, err error)

GetTokens return all tokens for a user

func (*Backend) GetUpload

func (b *Backend) GetUpload(ID string) (upload *common.Upload, err error)

GetUpload return an upload from the DB ( return nil and no error if not found )

func (*Backend) GetUploadStatistics

func (b *Backend) GetUploadStatistics(userID *string, tokenStr *string) (uploads int, files int, size int64, err error)

GetUploadStatistics return statistics about uploads for userID and tokenStr params : nil doesn't activate the filter, empty string enables the filter with an empty value to generate statistics about anonymous upload

func (*Backend) GetUploads

func (b *Backend) GetUploads(userID string, tokenStr string, withFiles bool, pagingQuery *common.PagingQuery) (uploads []*common.Upload, cursor *paginator.Cursor, err error)

GetUploads return uploads from DB userID and tokenStr are filters set withFiles to also fetch the files

func (*Backend) GetUploadsSortedBySize

func (b *Backend) GetUploadsSortedBySize(userID string, tokenStr string, withFiles bool, pagingQuery *common.PagingQuery) (uploads []*common.Upload, cursor *paginator.Cursor, err error)

GetUploadsSortedBySize return uploads from DB sorted by size userID and tokenStr are filters set withFiles to also fetch the files

func (*Backend) GetUser

func (b *Backend) GetUser(ID string) (user *common.User, err error)

GetUser return a user from DB ( return nil and no error if not found )

func (*Backend) GetUserStatistics

func (b *Backend) GetUserStatistics(userID string, tokenStr *string) (stats *common.UserStats, err error)

GetUserStatistics return statistics about user uploads for tokenStr params : nil doesn't activate the filter, empty string enables the filter with an empty value to generate statistics about upload without a token

func (*Backend) GetUsers

func (b *Backend) GetUsers(provider string, withTokens bool, pagingQuery *common.PagingQuery) (users []*common.User, cursor *paginator.Cursor, err error)

GetUsers return all users provider is an optional filter

func (*Backend) Import

func (b *Backend) Import(path string, options *ImportOptions) (err error)

Import imports metadata from a compressed binary file

func (*Backend) RemoveExpiredUploads

func (b *Backend) RemoveExpiredUploads() (removed int, err error)

RemoveExpiredUploads soft delete all expired uploads and remove all their files

func (*Backend) RemoveFile

func (b *Backend) RemoveFile(file *common.File) error

RemoveFile change the file status to removed The file will then be deleted from the data backend by the server and the status changed to deleted.

func (*Backend) RemoveUpload

func (b *Backend) RemoveUpload(uploadID string) (err error)

RemoveUpload soft delete upload ( just set upload.DeletedAt field ) and remove all files The upload metadata will still be present in the metadata database as well as all the files Until all the files are deleted from the data backend and

func (*Backend) RemoveUserUploads

func (b *Backend) RemoveUserUploads(userID string, tokenStr string) (removed int, err error)

RemoveUserUploads deletes all uploads matching the user and token filters

func (*Backend) Shutdown

func (b *Backend) Shutdown() (err error)

Shutdown the metadata backend, close all connections to the database.

func (*Backend) UpdateFile

func (b *Backend) UpdateFile(file *common.File, status string) error

UpdateFile update a file in DB. Status ensure the file status has not changed since loaded

func (*Backend) UpdateFileStatus

func (b *Backend) UpdateFileStatus(file *common.File, oldStatus string, newStatus string) error

UpdateFileStatus update a file status in DB. oldStatus ensure the file status has not changed since loaded

func (*Backend) UpdateSetting

func (b *Backend) UpdateSetting(key string, oldValue string, newValue string) (err error)

UpdateSetting update a setting in DB

func (*Backend) UpdateUploadExpirationDate

func (b *Backend) UpdateUploadExpirationDate(upload *common.Upload) (err error)

UpdateUploadExpirationDate updates an upload expiration date in DB

func (*Backend) UpdateUser

func (b *Backend) UpdateUser(user *common.User) (err error)

UpdateUser update user info in DB

type Config

type Config struct {
	Driver             string
	ConnectionString   string
	EraseFirst         bool
	MaxOpenConns       int
	MaxIdleConns       int
	Debug              bool
	SlowQueryThreshold string // Duration string
	// contains filtered or unexported fields
}

Config metadata backend configuration

func NewConfig

func NewConfig(params map[string]interface{}) (config *Config)

NewConfig instantiate a new default configuration and override it with configuration passed as argument

type GormLoggerAdapter

type GormLoggerAdapter struct {
	SlowQueryThreshold time.Duration
	// contains filtered or unexported fields
}

GormLoggerAdapter forward Gorm logs to a root-gg logger

func NewGormLoggerAdapter

func NewGormLoggerAdapter(log *logger.Logger) *GormLoggerAdapter

NewGormLoggerAdapter create a new GormLoggerAdapter for a root-gg logger

func (*GormLoggerAdapter) Error

func (l *GormLoggerAdapter) Error(ctx context.Context, msg string, data ...interface{})

Error print error messages

func (*GormLoggerAdapter) Info

func (l *GormLoggerAdapter) Info(ctx context.Context, msg string, data ...interface{})

Info print info

func (*GormLoggerAdapter) LogMode

LogMode is not relevant as log level is managed by the root-gg logger level

func (*GormLoggerAdapter) Trace

func (l *GormLoggerAdapter) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace print sql message

func (*GormLoggerAdapter) Warn

func (l *GormLoggerAdapter) Warn(ctx context.Context, msg string, data ...interface{})

Warn print warn messages

type ImportOptions

type ImportOptions struct {
	IgnoreErrors bool
}

ImportOptions for metadata imports

Jump to

Keyboard shortcuts

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