services

package
v0.0.0-...-bd23c5e Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: GPL-3.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiQueryKey = "api-key"
	Header      = "Authorization"
	Scheme      = "Bearer"
)
View Source
const (
	SummarySize = 100
)

Variables

View Source
var (
	ErrMissingOrMalformedAPIKey = errors.New("missing or malformed API key")
	ErrEmailNotVerified         = errors.New("email not verified")
	ErrCouldNotLinkUser         = errors.New("could not link user")
)
View Source
var (
	ErrProviderNotSupported = errors.New("provider not supported")
	ErrContentAlreadyExists = errors.New("content already exists")
	ErrContentNotFound      = errors.New("content not found")
	ErrUnknownMessageType   = errors.New("unknown message type")
	ErrWrongState           = errors.New("message not allowed in current state")
	ErrQueueFull            = errors.New("queue is full")
)
View Source
var (
	ErrPageNotFound       = errors.New("page not found")
	ErrExistingPagesFound = errors.New("some pages already exists")
	ErrFailedToSortCheck  = errors.New("error during sort checks")

	DefaultPageSort = 9999
)
View Source
var (
	DefaultLanguage = utils.OrElse(os.Getenv("LANGUAGE"), "en")

	ErrLanguageNotFound = errors.New("language not found")
	ErrKeyNotFound      = errors.New("key not found")
)
View Source
var ErrNoMatch = errors.New("zip file does not the wanted content")

Functions

func GetIssuerFromToken

func GetIssuerFromToken(tokenString string) (string, error)

func RegisterSignalREndPoint

func RegisterSignalREndPoint(service SignalRService, app *fiber.App) error

func ValidatorProvider

func ValidatorProvider() *validator.Validate

Types

type ArchiveService

type ArchiveService interface {
	GetComicInfo(archive string) (*comicinfo.ComicInfo, error)
	GetCover(archive string) ([]byte, error)
}

func ArchiveServiceProvider

func ArchiveServiceProvider(log zerolog.Logger, fs afero.Afero) ArchiveService

type AuthService

type AuthService interface {
	// IsAuthenticated checks the current request for authentication. This should be handled by the middleware
	IsAuthenticated(ctx *fiber.Ctx) (bool, error)

	// Login logs the current user in.
	Login(loginRequest payload.LoginRequest) (*payload.LoginResponse, error)

	Middleware(ctx *fiber.Ctx) error
}

func ApiKeyAuthServiceProvider

func ApiKeyAuthServiceProvider(params apiKeyAuthServiceParams) AuthService

func JwtAuthServiceProvider

func JwtAuthServiceProvider(service SettingsService, users models.Users, cfg *config.Config, log zerolog.Logger) (AuthService, error)

type CacheService

type CacheService interface {
	fiber.Storage
	Type() config.CacheType
}

func CacheServiceProvider

func CacheServiceProvider(log zerolog.Logger, service SettingsService) (CacheService, error)

type Client

type Client interface {
	// Download starts the download of the Content associated with the id. The returned error
	// might be because of the Content already have been added, or because of an error with the data
	// provider to create the Content
	Download(payload.DownloadRequest) error
	// RemoveDownload stops the download of the Content associated with the id. Will start cleanup,
	// should only return an error if the id has no associated Content
	RemoveDownload(payload.StopRequest) error
	// Content returns the Content associated with the passed id. If none is found, returns nil
	Content(string) Content
}

type Content

type Content interface {
	// Id returns a string that uniquely identifies this Content
	Id() string
	// Title returns the title of the Content, depending on how much info has been loaded, this may be equal to Id
	Title() string
	// Provider returns the provider this Content uses
	Provider() models.Provider
	// GetInfo returns the information to be displayed in the UI
	GetInfo() payload.InfoStat
	// State returns the payload.ContentState this Content currently is in
	State() payload.ContentState
	// SetState updates the state, and propagates to SignalR
	SetState(state payload.ContentState)
	// Message passes any payload.Message to the Content, and returns its response
	// The logic of what happens with the message may depend on the underlying Content
	Message(payload.Message) (payload.Message, error)
	// Request returns the original request made to start this content
	Request() payload.DownloadRequest
}

type ContentService

type ContentService interface {
	Search(payload.SearchRequest) ([]payload.Info, error)
	Download(payload.DownloadRequest) error
	DownloadSubscription(*models.Subscription, ...bool) error
	Stop(payload.StopRequest) error
	RegisterProvider(models.Provider, ProviderAdapter)
	DownloadMetadata(models.Provider) (payload.DownloadMetadata, error)
	Message(payload.Message) (payload.Message, error)
}

func ContentServiceProvider

func ContentServiceProvider(log zerolog.Logger) ContentService

type CronService

type CronService interface {
	NewJob(gocron.JobDefinition, gocron.Task, ...gocron.JobOption) (gocron.Job, error)
	RemoveJob(uuid.UUID) error
	Update(uuid.UUID, gocron.JobDefinition, gocron.Task, ...gocron.JobOption) (gocron.Job, error)
}

func CronServiceProvider

func CronServiceProvider(log zerolog.Logger) (CronService, error)

type DirectoryService

type DirectoryService interface {
	// ZipToCbz calls ZipFolder(folderPath, folderPath+".cbz")
	ZipToCbz(folderPath string) error
	ZipFolder(folderPath string, zipFileName string) error

	MoveDirectoryContent(src, dest string) error
}

func DirectoryServiceProvider

func DirectoryServiceProvider(log zerolog.Logger, fs afero.Afero) DirectoryService

type FileService

type FileService interface{}

func FileServiceProvider

func FileServiceProvider(log zerolog.Logger, fs afero.Fs) FileService

type ImageService

type ImageService interface {
	// Better check if candidateImg is similar to defaultImg with MSE. If the similarityThreshold (default 0.85)
	// is reached, returns the highest resolution one. Otherwise defaultImg
	Better(defaultImg, candidateImg []byte, similarityThresholds ...float64) ([]byte, bool, error)
	Similar(img1, img2 image.Image) float64
	MeanSquareError(img1, img2 image.Image) float64
	IsCover(data []byte) bool
	ToImage(data []byte) (image.Image, error)
	ConvertToWebp(data []byte) ([]byte, bool)
}

func ImageServiceProvider

func ImageServiceProvider(log zerolog.Logger, pref models.Preferences) ImageService

type MarkdownService

type MarkdownService interface {
	MdToSafeHtml(string) string
	SanitizeHtml(string) string
}

func MarkdownServiceProvider

func MarkdownServiceProvider(log zerolog.Logger) MarkdownService

type MetadataService

type MetadataService interface {
	Get() (payload.Metadata, error)
	Update(payload.Metadata) error
}

func MetadataServiceProvider

func MetadataServiceProvider(db models.Metadata, log zerolog.Logger) MetadataService

type MpClaims

type MpClaims struct {
	User models.User `json:"user,omitempty"`
	jwt.RegisteredClaims
}

type NotificationService

type NotificationService interface {
	Notify(models.Notification)
	// NotifyHelper constructs the struct, and calls Notify
	NotifyHelper(title, summary, body string, colour models.NotificationColour, group models.NotificationGroup)

	// NotifyContent calls NotifyHelper with GroupContent, default colour is blue(info)
	NotifyContent(title, summary, body string, colours ...models.NotificationColour)
	// NotifyContentQ calls NotifyContent with summary being the first 40 characters of body
	NotifyContentQ(title, body string, colours ...models.NotificationColour)

	// NotifySecurity calls NotifyHelper with GroupSecurity, default colour is orange(warn)
	NotifySecurity(title, summary, body string, colours ...models.NotificationColour)
	// NotifySecurityQ calls NotifySecurity with summary being the first 40 characters of body
	NotifySecurityQ(title, body string, colours ...models.NotificationColour)

	// NotifyGeneral calls NotifyHelper with GroupGeneral, default colour is white(secondary)
	NotifyGeneral(title, summary, body string, colours ...models.NotificationColour)
	// NotifyGeneralQ calls NotifyGeneral with summary being the first 40 characters of body
	NotifyGeneralQ(title, body string, colours ...models.NotificationColour)

	// MarkRead marks the notification with id as read, and sends the NotificationRead event through SignalR
	MarkRead(id uint) error
	// MarkReadMany marks all the notifications as read, and sends the NotificationRead event through SignalR
	MarkReadMany([]uint) error
	// MarkUnRead marks the notification with id as unread, and sends the Notification event through SignalR
	MarkUnRead(id uint) error
}

func NotificationServiceProvider

func NotificationServiceProvider(log zerolog.Logger, db *db.Database, signalR SignalRService) NotificationService

type Notifier

type Notifier interface {
	Notify(models.Notification)
}

type PageService

type PageService interface {
	UpdateOrCreate(page *models.Page) error
	OrderPages([]uint) error
	LoadDefaultPages() error
}

func PageServiceProvider

func PageServiceProvider(db *db.Database, log zerolog.Logger) PageService

type PreferencesService

type PreferencesService interface {
	Update(preference payload.PreferencesDto) error
	GetDto() (payload.PreferencesDto, error)
}

func PreferenceServiceProvider

func PreferenceServiceProvider(subscriptionService SubscriptionService, pref models.Preferences, log zerolog.Logger) PreferencesService

type ProviderAdapter

type ProviderAdapter interface {
	Search(payload.SearchRequest) ([]payload.Info, error)
	DownloadMetadata() payload.DownloadMetadata
	Client() Client
}

type SettingsService

type SettingsService interface {
	GetSettingsDto() (payload.Settings, error)
	UpdateSettingsDto(settings payload.Settings) error
}

func SettingsServiceProvider

func SettingsServiceProvider(settings models.Settings, log zerolog.Logger) SettingsService

type SignalRParams

type SignalRParams struct {
	dig.In
	Log  zerolog.Logger
	Auth AuthService `name:"jwt-auth"`
}

type SignalRService

type SignalRService interface {
	signalr.HubInterface

	Broadcast(eventType payload.EventType, data interface{})

	SizeUpdate(id string, size string)
	ProgressUpdate(data payload.ContentProgressUpdate)
	StateUpdate(id string, state payload.ContentState)

	AddContent(data payload.InfoStat)
	UpdateContentInfo(data payload.InfoStat)
	DeleteContent(id string)

	// Notify may be used directly by anyone to send a quick toast to the frontend.
	// Use NotificationService for notification that must persist
	Notify(notification models.Notification)
}

func SignalRServiceProvider

func SignalRServiceProvider(params SignalRParams) SignalRService

type SubscriptionService

type SubscriptionService interface {
	// Get the subscription with ID
	Get(uint) (*models.Subscription, error)
	// All returns all active subscriptions
	All() ([]models.Subscription, error)
	// Add a new subscription, saved to DB and starts the cron job
	// Subscription is normalized in the process
	Add(models.Subscription) (*models.Subscription, error)
	// Update an existing subscription, updates DB. Subscription is normalized in the process
	Update(models.Subscription) error
	// Delete the subscription with ID
	Delete(uint) error

	// UpdateTask recreates the underlying cronjob. Generally only called when the hour to run susbcriptions changes
	UpdateTask(hour ...int) error
}

func SubscriptionServiceProvider

func SubscriptionServiceProvider(db *db.Database, provider ContentService,
	log zerolog.Logger, cronService CronService, notifier NotificationService,
	transloco TranslocoService,
) (SubscriptionService, error)

type TranslocoService

type TranslocoService interface {
	// GetTranslation calls GetTranslationLang with lang = DefaultLanguage
	GetTranslation(key string, params ...any) string
	// GetTranslationLang returns the formatted string if found, otherwise the key
	GetTranslationLang(lang, key string, params ...any) string
	// TryTranslationLang returns the formatted string if found, otherwise an appropriate error
	TryTranslationLang(lang, key string, params ...any) (string, error)

	// GetLanguages returns a list of all loaded languages
	GetLanguages() []string
}

func TranslocoServiceProvider

func TranslocoServiceProvider(log zerolog.Logger, fs afero.Afero) (TranslocoService, error)

type ValidationService

type ValidationService interface {
	Validate(out any) error
	ValidateCtx(ctx *fiber.Ctx, out any) error
}

func ValidationServiceProvider

func ValidationServiceProvider(val *validator.Validate, log zerolog.Logger) ValidationService

Jump to

Keyboard shortcuts

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