db

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Title       SortBy = "title"
	TitleNative        = "native"
	UpdatedAt          = "updated"
	Progress           = "progress"
)

Variables

This section is empty.

Functions

func ArchivePathFound

func ArchivePathFound(archivePath string) []model.Gallery

ArchivePathFound returns true if the given archive path is already in the database.

func CountAllImages added in v0.7.0

func CountAllImages(skipWithPageThumbnails bool) (int, int, error)

func DeleteGallery

func DeleteGallery(galleryUUID string) bool

DeleteGallery removes a gallery from the database (never actually deletes the archive file).

func DeleteSession

func DeleteSession(id string, userUUID string) error

DeleteSession removes a session based on the session ID and user UUID.

func DeleteUser

func DeleteUser(userUUID string) error

DeleteUser removes user. Super admin users cannot be deleted.

func EnsureLatestVersion

func EnsureLatestVersion()

EnsureLatestVersion ensures that the database is at the latest version by running all migrations.

func GetCategories

func GetCategories() ([]string, error)

GetCategories returns all public categories.

func GetFavoriteGroups

func GetFavoriteGroups(userUUID string) ([]string, error)

GetFavoriteGroups returns user's favorite groups.

func GetGalleryCount added in v0.4.2

func GetGalleryCount(filters Filters, hidden bool, userUUID *string) (int64, error)

GetGalleryCount returns the number of galleries that match the given filters.

func GetOnlyLibraries

func GetOnlyLibraries() ([]model.Library, error)

func GetReference added in v0.3.0

func GetReference(galleryUUID string) (model.Reference, error)

func GetSeries

func GetSeries() ([]string, error)

GetSeries returns all series.

func GetSessions

func GetSessions(userUUID string) ([]model.Session, error)

GetSessions returns all sessions of a user.

func GetUser

func GetUser(name string) ([]model.User, error)

GetUser returns a user from the database.

func GetUsers

func GetUsers() ([]model.User, error)

GetUsers returns users from the database.

func InitDB added in v0.5.0

func InitDB()

InitDB initializes the database

func Login

func Login(username string, password string, role Role) (*string, *int32, error)

Login logs the user in and returns the UUID of the user.

func Logout

func Logout(sessionUUID string, userUUID string) error

Logout logs out a user by removing a session.

func MetaPathFound

func MetaPathFound(metaPath string, libraryPath string) bool

MetaPathFound returns true if a gallery with the given meta path exists.

func MigratePassword added in v0.7.2

func MigratePassword(username string, password string) error

MigratePassword migrates password from bcrypt to argon2id with salt.

func NeedsUpdate

func NeedsUpdate(archivePath string, updatedAt time.Time) (bool, string)

NeedsUpdate returns true if the gallery needs to be updated. Currently only the timestamp is checked.

func NewGallery

func NewGallery(archivePath string, libraryID int32, title string, series string, size int64, imageCount int64) (string, error)

NewGallery creates a new gallery

func NewGalleryPref

func NewGalleryPref(galleryUUID string, userUUID string) error

NewGalleryPref creates initializes user preferences for a gallery.

func NewSession

func NewSession(userUUID string, expiresIn *int64, sessionName *string) (string, error)

NewSession creates a new session for a user.

func NewTags

func NewTags(tags []model.Tag) ([]int32, error)

NewTags creates tags from the given list.

func PruneExpiredSessions added in v0.4.3

func PruneExpiredSessions()

PruneExpiredSessions removes all expired sessions.

func Register

func Register(username string, password string, role Role) error

Register registers a new user.

func SanitizeString added in v0.3.0

func SanitizeString(content *string) *string

SanitizeString returns the pointer of the string with all leading and trailing white space removed. If the string is empty, it returns nil.

func SetFavoriteGroup

func SetFavoriteGroup(favoriteGroup string, galleryUUID string, userUUID string) error

SetFavoriteGroup sets a favorite group for a gallery.

func SetPageThumbnails added in v0.7.0

func SetPageThumbnails(uuid string, pageThumbnails int32) error

func SetThumbnail

func SetThumbnail(uuid string, thumbnail string) error

SetThumbnail saves the filename of the thumbnail for the gallery.

func StorePaths

func StorePaths(givenLibraries []config.Library) error

func UpdateGallery

func UpdateGallery(gallery model.Gallery, tags []model.Tag, reference model.Reference, internalScan bool) error

UpdateGallery updates a gallery. It also adds tags and references if any. If internalScan is true, the gallery is matched by its archive path, not UUID.

func UpdateProgress

func UpdateProgress(progress int32, galleryUUID string, userUUID string) error

UpdateProgress sets the reading progress of a gallery for a user.

func UpdateUser

func UpdateUser(userUUID string, userForm *UserForm) error

UpdateUser can be used to update role, password or username of users.

func ValidateGallery added in v0.3.0

func ValidateGallery(gallery model.Gallery, newGallery model.Gallery) model.Gallery

ValidateGallery returns updated and sanitized gallery model.

func ValidateReference added in v0.3.0

func ValidateReference(reference model.Reference, newReference model.Reference) model.Reference

ValidateReference returns updated and sanitized gallery reference.

func VerifySession

func VerifySession(id string, userUUID string) bool

VerifySession verifies a session by checking if it exists based on the session ID and user UUID.

Types

type Categories

type Categories struct {
	Data []string `json:"Data"`
}

type CombinedLibrary

type CombinedLibrary struct {
	model.Library
	Galleries []model.Gallery
}

func GetLibraries

func GetLibraries() ([]CombinedLibrary, error)

type CombinedMetadata

type CombinedMetadata struct {
	model.Gallery

	Tags []model.Tag

	Reference struct {
		ExhToken *string
		ExhGid   *int32
		Urls     *string
	} `alias:"reference.*"`

	GalleryPref *struct {
		FavoriteGroup *string
		Progress      int32
		UpdatedAt     string
	} `alias:"gallery_pref.*"`

	Library model.Library `json:"-"`
}

func GetGalleries

func GetGalleries(filters Filters, hidden bool, userUUID *string, count bool) ([]CombinedMetadata, error)

GetGalleries returns galleries based on the given filters.

func GetGallery

func GetGallery(galleryUUID *string, userUUID *string) (CombinedMetadata, error)

GetGallery returns a gallery based on the given UUID. If no UUID is given, a random gallery is returned.

type FavoriteGroups

type FavoriteGroups struct {
	Data []string `json:"Data"`
}

type Filters

type Filters struct {
	Order         Order
	SortBy        SortBy
	Limit         int64
	Offset        int64
	SearchTerm    string
	Series        string
	Category      string
	FavoriteGroup string
	NSFW          string
	Tags          []model.Tag
	Grouped       string
	Seed          int64
}

type MappedTags

type MappedTags struct {
	Data  map[string][]string `json:"Data"`
	Count int
}

func GetTags

func GetTags(galleryUUID string, mapped bool) (MappedTags, []model.Tag, error)

GetTags returns all tags.

type Order

type Order string
const (
	Desc Order = "desc"
	Asc        = "asc"
)

type Role

type Role uint8
const (
	SuperAdmin Role = 110
	Admin      Role = 100
	Member     Role = 20
	Viewer     Role = 10
	NoRole     Role = 0
)

type SortBy

type SortBy string

type UserForm

type UserForm struct {
	Password *string `json:"password"`
	Username *string `json:"username"`
	Role     *string `json:"role"`
}

Jump to

Keyboard shortcuts

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