fetcher

package
v1.0.77 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyBinder = Binder{}

EmptyBinder singleton

View Source
var EmptyBookBinder = BookBinder{}

EmptyBookBinder singleton

View Source
var EmptyMetadataBinder = MetadataBinder{}

EmptyMetadataBinder singleton

Functions

func PatchMetadata

func PatchMetadata(metadata *models.Metadata)

PatchMetadata ensures that the nickname and username fields are not blank

func PatchSheet

func PatchSheet(sheet *character.Sheet, metadata *models.Metadata)

PatchSheet ensures that the sheet is consistent with the metadata

Types

type BaseURL

type BaseURL struct {
	Domain string
	Path   string
}

BaseURL represents a base URL of a fetcher

type Binder

type Binder struct {
	MetadataBinder
	BookBinder
}

Binder is a container for all the data fetched from a single source

type BookBinder

type BookBinder struct {
	Responses  []JsonResponse
	UpdateTime timestamp.Nano
}

BookBinder is a container for all the book data fetched from a single source

type Builder

type Builder interface {
	Build(client *reqx.Client) Fetcher
}

Builder builds a Fetcher

type ErrCode

type ErrCode byte

ErrCode Error codes for fetcher

const (
	InvalidCredentialsErr ErrCode = iota
	FetchMetadataErr
	MalformedMetadataErr
	FetchCardDataErr
	MalformedCardDataErr
	FetchBookDataErr
	MalformedBookDataErr
	FetchAvatarErr
	DecodeErr
	MissingCookieProviderErr
	None
)

Error codes

func GetErrCode

func GetErrCode(err error) ErrCode

GetErrCode returns the error code from the given error

func (ErrCode) String

func (e ErrCode) String() string

String returns the error message

type Error

type Error = *trace.CodedErr[ErrCode]

Error Custom error type for fetcher

func NewError

func NewError(cause error, code ErrCode) Error

NewError creates a new error with the given code

type Fetcher

type Fetcher interface {
	// Extends allows a fetcher to extend another fetcher
	Extends(top Fetcher)
	// SourceID returns the source ID of the fetcher
	SourceID() source.ID

	// SourceURL returns the source URL of the fetcher
	SourceURL() string
	// MainURL returns the main URL of the fetcher
	MainURL() string
	// BaseURLs returns the base URLs of the fetcher
	BaseURLs() []BaseURL
	// CharacterID returns the character ID from a URL
	CharacterID(rawCharacterID string) string
	// DirectURL returns the direct URL for a character
	DirectURL(characterID string) string
	// NormalizeURL returns the normalized URL for a character
	NormalizeURL(characterID string) string

	// FetchMetadataResponse fetches the metadata response from the source for the given characterID
	FetchMetadataResponse(characterID string) (*req.Response, error)
	// CreateBinder creates a MetadataBinder from the metadata response
	CreateBinder(characterID string, response string) (*MetadataBinder, error)
	// FetchCardInfo fetches the card info from the source
	FetchCardInfo(metadataBinder *MetadataBinder) (*models.CardInfo, error)
	// FetchCreatorInfo fetches the creator info from the source
	FetchCreatorInfo(metadataBinder *MetadataBinder) (*models.CreatorInfo, error)
	// FetchBookResponses fetches the book responses from the source
	FetchBookResponses(metadataBinder *MetadataBinder) (*BookBinder, error)
	// FetchCharacterCard fetches the character card from the source
	FetchCharacterCard(binder *Binder) (*png.CharacterCard, error)
	// Close closes the fetcher
	Close()

	// IsSourceUp checks if the source is up
	IsSourceUp() error
}

Fetcher interface for all fetchers

type JsonResponse

type JsonResponse = *sonicx.Wrap

JsonResponse type alias for *sonicx.Wrap

type JsonString

type JsonString string

JsonString is a generic JSON response

type MetadataBinder

type MetadataBinder struct {
	CharacterID   string
	NormalizedURL string
	DirectURL     string
	Document      *goquery.Document
	JsonResponse
}

MetadataBinder is a container for all the metadata fetched from a single source

Jump to

Keyboard shortcuts

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