models

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ListenerRegistry []Listener

ListenerRegistry is a registry of listeners interested in notifications

Functions

func AddListener

func AddListener(listener Listener)

AddListener adds a listener to the registry

func BanUser added in v1.0.7

func BanUser(username string) error

BanUser bans a user by setting the Banned field to true.

func ChapterExists

func ChapterExists(chapterSlug, mangaSlug string) (bool, error)

ChapterExists checks if a chapter already exists

func Close

func Close() error

Close closes the database connection

func CountUsers

func CountUsers() (int64, error)

CountUsers returns the total number of users.

func CreateAccessToken

func CreateAccessToken(userName string) (string, error)

CreateAccessToken generates a new access token with a 15-minute expiry

func CreateChapter

func CreateChapter(chapter Chapter) error

CreateChapter adds a new chapter if it does not already exist

func CreateLibrary

func CreateLibrary(library Library) error

CreateLibrary adds a new Library to the database

func CreateManga

func CreateManga(manga Manga) error

CreateManga adds a new Manga to the database

func CreateRefreshToken

func CreateRefreshToken(userName string, version int) (string, error)

CreateRefreshToken generates a new refresh token with a 7-day expiry

func CreateUser

func CreateUser(username, password string) error

CreateUser creates a new user with hashed password and default role.

func DeleteChapter

func DeleteChapter(mangaSlug, chapterSlug string) error

DeleteChapter removes a specific chapter

func DeleteChaptersByMangaSlug added in v1.0.1

func DeleteChaptersByMangaSlug(mangaSlug string) error

DeleteChaptersByMangaSlug removes all chapters for a specific manga

func DeleteLibrary

func DeleteLibrary(slug string) error

DeleteLibrary removes a Library and its associated mangas

func DeleteManga

func DeleteManga(slug string) error

DeleteManga removes a Manga and its associated chapters

func DeleteMangasByLibrarySlug

func DeleteMangasByLibrarySlug(librarySlug string) error

DeleteMangasByLibrarySlug removes all mangas associated with a specific library

func DemoteUser added in v1.0.7

func DemoteUser(username string) error

DemoteUser demotes a user to the previous role in the hierarchy.

func GenerateNewRefreshToken

func GenerateNewRefreshToken(userName string) (string, error)

GenerateNewRefreshToken creates a new refresh token and updates the user's version

func GenerateRandomKey

func GenerateRandomKey(length int) (string, error)

GenerateRandomKey creates a new random key of the specified length

func GetAdjacentChapters

func GetAdjacentChapters(chapterSlug, mangaSlug string) (prevSlug, nextSlug string, err error)

GetAdjacentChapters finds the previous and next chapters based on the current chapter slug

func GetKey

func GetKey() (string, error)

GetKey retrieves the JWT key from the database

func IncrementRefreshTokenVersion

func IncrementRefreshTokenVersion(username string) error

IncrementRefreshTokenVersion increments the refresh token version for a user.

func Initialize

func Initialize(cacheDirectory string) error

Initialize connects to the BoltDB database and creates necessary buckets

func LibraryExists

func LibraryExists(slug string) (bool, error)

LibraryExists checks if a Library exists by slug

func MangaCount

func MangaCount(filterBy, filter string) (int, error)

MangaCount counts the number of mangas based on filter criteria

func MangaExists

func MangaExists(slug string) (bool, error)

MangaExists checks if a Manga exists by slug

func NotifyListeners

func NotifyListeners(notification Notification)

NotifyListeners notifies all registered listeners with a given notification

func PromoteUser added in v1.0.7

func PromoteUser(username string) error

PromoteUser promotes a user to the next role in the hierarchy.

func RefreshAccessToken

func RefreshAccessToken(refreshToken string) (string, string, error)

RefreshAccessToken generates a new access token from a valid refresh token

func StoreKey

func StoreKey(key string) error

StoreKey saves the JWT key to the database

func UnbanUser added in v1.0.7

func UnbanUser(username string) error

UnbanUser unbans a user by setting the Banned field to false.

func UpdateChapter

func UpdateChapter(chapter *Chapter) error

UpdateChapter modifies an existing chapter

func UpdateLibrary

func UpdateLibrary(library *Library) error

UpdateLibrary modifies an existing Library

func UpdateManga

func UpdateManga(manga *Manga) error

UpdateManga modifies an existing Manga

func UpdateUserRole

func UpdateUserRole(username, newRole string) error

UpdateUserRole updates the role of a user.

func ValidateToken

func ValidateToken(tokenString string) (jwt.MapClaims, error)

ValidateToken validates a token and returns its claims

Types

type Chapter

type Chapter struct {
	Slug            string `json:"slug"`
	Name            string `json:"name"`
	Type            string `json:"type"`
	File            string `json:"file"`
	ChapterCoverURL string `json:"chapter_cover_url"`
	MangaSlug       string `json:"manga_slug"`
}

func GetChapter

func GetChapter(mangaSlug, chapterSlug string) (*Chapter, error)

GetChapter retrieves a specific chapter by its slug

func GetChapters

func GetChapters(mangaSlug string) ([]Chapter, error)

GetChapters retrieves all chapters for a specific manga, sorted by name

type JWTKey

type JWTKey struct {
	Key string `json:"key"`
}

type Library

type Library struct {
	Slug        string   `json:"slug"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Cron        string   `json:"cron"`
	Folders     []string `json:"folders"`
	CreatedAt   int64    `json:"created_at"` // Unix timestamp
	UpdatedAt   int64    `json:"updated_at"` // Unix timestamp
}

func GetLibraries

func GetLibraries() ([]Library, error)

GetLibraries retrieves all Libraries from the database

func GetLibrary

func GetLibrary(slug string) (*Library, error)

GetLibrary retrieves a single Library by slug

func SearchLibraries

func SearchLibraries(keyword string, page, pageSize int, sortBy, sortOrder string) ([]Library, int64, error)

SearchLibraries finds Libraries matching the keyword and applies pagination and sorting

func (*Library) GetFolderNames

func (l *Library) GetFolderNames() string

GetFolderNames returns a comma-separated string of folder names

func (*Library) Validate

func (l *Library) Validate() error

Validate checks if the Library has valid values

type ListMangaResponse

type ListMangaResponse struct {
	Result   string        `json:"result"`
	Response string        `json:"response"`
	Data     []MangaDetail `json:"data"`
	Limit    int           `json:"limit,omitempty"`
	Offset   int           `json:"offset,omitempty"`
	Total    int           `json:"total,omitempty"`
}

ListMangaResponse represents the JSON response for a list of mangas

func GetMangadexMangas

func GetMangadexMangas(title string) (*ListMangaResponse, error)

GetMangadexMangas searches for mangas based on the title and returns a list of matches

type Listener

type Listener interface {
	Notify(notification Notification)
}

Listener defines the interface for objects that want to listen to notifications

type Manga

type Manga struct {
	Slug             string    `json:"slug"`
	Name             string    `json:"name"`
	Author           string    `json:"author"`
	Description      string    `json:"description"`
	Year             int       `json:"year"`
	OriginalLanguage string    `json:"original_language"`
	Status           string    `json:"status"`
	ContentRating    string    `json:"content_rating"`
	LibrarySlug      string    `json:"library_slug"`
	CoverArtURL      string    `json:"cover_art_url"`
	Path             string    `json:"path"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

func GetManga

func GetManga(slug string) (*Manga, error)

GetManga retrieves a single Manga by slug

func SearchMangas

func SearchMangas(filter string, page, pageSize int, sortBy, sortOrder, filterBy, librarySlug string) ([]Manga, int64, error)

SearchMangas filters, sorts, and paginates mangas based on provided criteria

type MangaAttributes

type MangaAttributes struct {
	Title                          map[string]string   `json:"title"`
	AltTitles                      []map[string]string `json:"altTitles"`
	Description                    map[string]string   `json:"description"`
	IsLocked                       bool                `json:"isLocked"`
	Links                          map[string]string   `json:"links"`
	OriginalLanguage               string              `json:"originalLanguage"`
	LastVolume                     string              `json:"lastVolume"`
	LastChapter                    string              `json:"lastChapter"`
	PublicationDemographic         interface{}         `json:"publicationDemographic"`
	Status                         string              `json:"status"`
	Year                           int                 `json:"year"`
	ContentRating                  string              `json:"contentRating"`
	Tags                           []Tag               `json:"tags"`
	State                          string              `json:"state"`
	ChapterNumbersResetOnNewVolume bool                `json:"chapterNumbersResetOnNewVolume"`
	CreatedAt                      time.Time           `json:"createdAt"`
	UpdatedAt                      time.Time           `json:"updatedAt"`
	Version                        int                 `json:"version"`
	AvailableTranslatedLanguages   []string            `json:"availableTranslatedLanguages"`
	LatestUploadedChapter          string              `json:"latestUploadedChapter"`
}

MangaAttributes represents the attributes of a manga in MangaDetail

type MangaDetail

type MangaDetail struct {
	ID            string          `json:"id"`
	Type          string          `json:"type"`
	Attributes    MangaAttributes `json:"attributes"`
	Relationships []Relationship  `json:"relationships"`
}

MangaDetail represents details of a manga item in the "data" array of MangaResponse

func GetBestMatchMangadexManga

func GetBestMatchMangadexManga(title string) (*MangaDetail, error)

GetBestMatchMangadexManga returns the best match manga based on the title

func GetMangadexManga

func GetMangadexManga(id string) (*MangaDetail, error)

GetMangadexManga fetches manga details by ID from the MangaDex API

type Notification

type Notification struct {
	Type    string      // Type of notification (e.g., "library_created", "library_updated", etc.)
	Payload interface{} // Data associated with the notification
}

Notification represents a notification object

type Relationship

type Relationship struct {
	ID         string      `json:"id"`
	Type       string      `json:"type"`
	Attributes interface{} `json:"attributes"` // General type for flexibility
}

Relationship represents the relationship details in MangaDetail

type SingleMangaResponse

type SingleMangaResponse struct {
	Result   string      `json:"result"`
	Response string      `json:"response"`
	Data     MangaDetail `json:"data"`
}

SingleMangaResponse represents the JSON response for a single manga

type Tag added in v1.0.2

type Tag struct {
	ID         string `json:"id"`
	Type       string `json:"type"`
	Attributes struct {
		Name        map[string]string `json:"name"`
		Description map[string]string `json:"description"`
		Group       string            `json:"group"`
		Version     int               `json:"version"`
	} `json:"attributes"`
	Relationships []interface{} `json:"relationships"`
}

Tag represents a tag in MangaAttributes

type User

type User struct {
	Username            string `json:"username"`
	Password            string `json:"password"`
	RefreshTokenVersion int    `json:"refresh_token_version"`
	Role                string `json:"role"`
	Banned              bool   `json:"banned"`
}

func FindUserByUsername

func FindUserByUsername(username string) (*User, error)

FindUserByUsername retrieves a user by their username.

func GetUsers added in v1.0.7

func GetUsers() ([]User, error)

GetUsers retrieves all Users from the database

Jump to

Keyboard shortcuts

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