db

package
v0.0.0-...-c62f299 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

implementation of the DB logic

defines the models stored in the DB

Index

Constants

This section is empty.

Variables

View Source
var ErrNoStorage = errors.New("no storage set on event")

Functions

func ExtractEventStorage

func ExtractEventStorage(evt *Event, googleOauthConfig *oauth2.Config) error

Sets the events Storage interface value to the non-nil storage configuration stored against the event

Types

type DB

type DB interface {
	CreateEvent(context.Context, *Event) (uint, error)
	GetEvents(context.Context, uint) ([]*Event, error)
	GetEvent(context.Context, uint64) (*Event, error)
	GetEventBySlug(context.Context, string) (*Event, error)
	GetActiveEvent(context.Context) (*Event, error)
	SetActiveEvent(context.Context, uint64) error
	AddFileInfo(context.Context, *FileInfo) error
	GetFileInfo(context.Context, string) (*FileInfo, error)
	AddThumbnailInfo(context.Context, *ThumbnailInfo) error
	GetThumbnails(ctx context.Context, eventId uint, limit int, offset int) ([]*ThumbnailInfo, error)
	GetThumbnailInfo(context.Context, string) (*ThumbnailInfo, error)
	SetEventLive(context.Context, uint64, bool) (*Event, error)
	DeleteEvent(context.Context, uint64) error
	CreateUser(context.Context, string, string) error
	GetUser(context.Context, string) (*User, error)
	UserAuthorizedForEvent(context.Context, uint, uint) (bool, error)
	StoreGoogleToken(ctx context.Context, userId uint, token []byte) error
	GetGoogleToken(ctx context.Context, uideId uint) ([]byte, error)
	DeleteGoogleToken(ctx context.Context, userId uint) error
}

func NewDb

func NewDb(cfg *config.Database, logger *zap.Logger, googleOauthConfig *oauth2.Config) (DB, func(), error)

type Event

type Event struct {
	gorm.Model
	Name string
	Slug string `gorm:"uniqueIndex"`
	Live bool
	// whether or not to cache media stored in the event
	Cache          bool
	FileInfos      []FileInfo
	ThumbnailInfos []ThumbnailInfo
	UserID         uint
	User           User
	Active         bool
	Password       *gormcrypto.EncryptedValue

	storage.Storage `gorm:"-"`
	// All available storage options for the event
	// Only one should be set, the rest must be null
	FileSystemStorage  *FileSystemStorage
	S3Storage          *S3Storage
	GoogleDriveStorage *GoogleDriveStorage
	FtpStorage         *FtpStorage
}

type FileInfo

type FileInfo struct {
	gorm.Model
	ID      string
	EventID uint
	Event   Event
	Name    string
	Video   bool
}

type FileSystemStorage

type FileSystemStorage struct {
	gorm.Model
	Directory string
	EventID   uint
}

type FtpStorage

type FtpStorage struct {
	gorm.Model
	Address   string
	Directory string
	Username  gormcrypto.EncryptedValue
	Password  gormcrypto.EncryptedValue
	EventID   uint
}

type GoogleDriveStorage

type GoogleDriveStorage struct {
	gorm.Model
	DirectoryID string
	EventID     uint
}

type GoogleDriveToken

type GoogleDriveToken struct {
	gorm.Model
	Token  gormcrypto.EncryptedValue
	UserID uint
}

type S3Storage

type S3Storage struct {
	gorm.Model
	Region    string
	AccessKey gormcrypto.EncryptedValue
	SecretKey gormcrypto.EncryptedValue
	Bucket    string
	Endpoint  string
	EventID   uint
	Insecure  bool
}

type ThumbnailInfo

type ThumbnailInfo struct {
	gorm.Model
	ID         string
	Name       string
	EventID    uint
	Event      Event
	FileInfoID string
	FileInfo   FileInfo
}

type User

type User struct {
	gorm.Model
	Username         string
	Password         string
	Admin            bool
	Events           []Event
	GoogleDriveToken *GoogleDriveToken
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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