models

package
v2.0.26 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotASeed                          = errors.New("item is not a seed")
	ErrFailedAtPreprocessor              = errors.New("item failed at preprocessor")
	ErrFailedAtArchiver                  = errors.New("item failed at archiver")
	ErrFailedAtPostprocessor             = errors.New("item failed at postprocessor")
	ErrItemNil                           = errors.New("item is nil")
	ErrItemURLNil                        = errors.New("url is nil")
	ErrItemIDEmpty                       = errors.New("id is empty")
	ErrItemChildHasSeedVia               = errors.New("item is a child but has a seedVia")
	ErrItemFreshHasChildren              = errors.New("item is fresh but has children")
	ErrItemFreshParentInvalid            = errors.New("item is not a seed and fresh but parent is not ItemGotChildren or ItemGotRedirected")
	ErrItemRedirectedHasMultipleChildren = errors.New("item has more than one child but is ItemGotRedirected")
	ErrItemChildrenStateInvalid          = errors.New("item has children but is not ItemGotChildren, ItemGotRedirected, ItemCompleted or ItemFailed")
)

Errors definition

Functions

func URLToString

func URLToString(URL *url.URL) string

URLToString exists to apply some custom stuff, in opposition of simply using the u.parsed.String() method

Types

type Item

type Item struct {
	// contains filtered or unexported fields
}

Item represents a URL, it's children (e.g. discovered assets) and it's state in the pipeline The children follow a tree structure where the seed is the root and the children are the leaves, this is to keep track of the hops and the origin of the children

func NewItem

func NewItem(URL *URL, seedVia string) *Item

func NewItemWithID

func NewItemWithID(ID string, URL *URL, seedVia string) *Item

NewItem creates a new item with the given ID, URL and seedVia

func (*Item) AddChild

func (i *Item) AddChild(child *Item, from ItemState) error

AddChild adds a child to the item The from parameter is used to set the status of the parent (either ItemGotRedirected or ItemGotChildren)

func (*Item) CheckConsistency

func (i *Item) CheckConsistency() error

CheckConsistency checks if the item is consistent with the constraints of the model Developers should add more constraints as needed Ideally this function should be called after every mutation of an item object to ensure consistency and throw a panic if consistency is broken

func (*Item) Close

func (i *Item) Close()

func (*Item) CompleteAndCheck

func (i *Item) CompleteAndCheck() bool

CompleteAndCheck traverse the seed's tree to complete the items and returns true if the seed is completed

func (*Item) DedupeItems

func (i *Item) DedupeItems() error

DedupeItems dedupes items from any level, keeping in priority a Completed item

func (*Item) DrawTree

func (i *Item) DrawTree() string

DrawTree generates the ASCII representation of the tree

func (*Item) DrawTreeWithStatus

func (i *Item) DrawTreeWithStatus() string

DrawTree generates the ASCII representation of the tree

func (*Item) GetChildren

func (i *Item) GetChildren() []*Item

GetChildren returns the children of the item

func (*Item) GetDepth

func (i *Item) GetDepth() int64

GetDepth returns the depth of the item

func (*Item) GetDepthWithoutRedirections

func (i *Item) GetDepthWithoutRedirections() int64

func (*Item) GetError

func (i *Item) GetError() error

GetError returns the error of the item

func (*Item) GetID

func (i *Item) GetID() string

GetID returns the ID of the item

func (*Item) GetMaxDepth

func (i *Item) GetMaxDepth() int64

GetMaxDepth returns the maxDepth of the item by traversing the tree

func (*Item) GetNodesAtLevel

func (i *Item) GetNodesAtLevel(targetLevel int64) ([]*Item, error)

GetNodesAtLevel returns all the nodes at a given level in the seed

Can be paired with item.GetMaxDepth() to get all the items at the max depth (i.e.: all the items that potentially need work)

Returns ErrNotASeed as error if the item is not a seed

func (*Item) GetParent

func (i *Item) GetParent() *Item

GetParent returns the parent of the item

func (*Item) GetSeed

func (i *Item) GetSeed() *Item

GetSeed returns the seed (topmost parent) of any given item

func (*Item) GetSeedVia

func (i *Item) GetSeedVia() string

GetSeedVia returns the seedVia of the item

func (*Item) GetShortID

func (i *Item) GetShortID() string

GetShortID returns the short ID of the item

func (*Item) GetSource

func (i *Item) GetSource() ItemSource

GetSource returns the source of the item

func (*Item) GetStatus

func (i *Item) GetStatus() ItemState

GetStatus returns the status of the item

func (*Item) GetURL

func (i *Item) GetURL() *URL

GetURL returns the URL of the item

func (*Item) HasChildren

func (i *Item) HasChildren() bool

HasChildren returns true if the item has children

func (*Item) HasRedirection

func (i *Item) HasRedirection() bool

HasRedirection returns true if the item has a redirection

func (*Item) HasWork

func (i *Item) HasWork() bool

HasWork returns true if the item has work to do

func (*Item) IsChild

func (i *Item) IsChild() bool

IsChild returns true if the item is a child

func (*Item) IsRedirection

func (i *Item) IsRedirection() bool

IsRedirection returns true if the item is from a redirection

func (*Item) IsSeed

func (i *Item) IsSeed() bool

IsSeed returns the seed flag of the item

func (*Item) RemoveChild

func (parent *Item) RemoveChild(child *Item)

RemoveChild removes a child from the item

func (*Item) SetError

func (i *Item) SetError(err error)

SetError sets the error of the item

func (*Item) SetSource

func (i *Item) SetSource(source ItemSource) error

SetSource sets the source of the item

func (*Item) SetStatus

func (i *Item) SetStatus(status ItemState)

SetStatus sets the status of the item

func (*Item) Traverse

func (i *Item) Traverse(fn func(*Item))

Traverse traverses the tree from the seed to the children

type ItemSource

type ItemSource int64

ItemSource qualifies the source of a item in the pipeline

const (
	// ItemSourceInsert is for items which source is not defined when inserted on reactor
	ItemSourceInsert ItemSource = iota
	// ItemSourceQueue is for items that are from the Queue
	ItemSourceQueue
	// ItemSourceHQ is for items that are from the HQ
	ItemSourceHQ
	// ItemSourcePostprocess is for items generated from redirections
	ItemSourcePostprocess
	// ItemSourceFeedback is for items that are from the Feedback
	ItemSourceFeedback
)

type ItemState

type ItemState int64

ItemState qualifies the state of a item in the pipeline

const (
	// ItemFresh is the initial state of a item either it's from HQ, the Queue or Feedback
	ItemFresh ItemState = iota
	// ItemPreProcessed is the state after the item has been pre-processed
	ItemPreProcessed
	// ItemArchived is the state after the item has been archived
	ItemArchived
	// ItemFailed is the state after the item has failed
	ItemFailed
	// ItemCompleted is the state after the item has been completed
	ItemCompleted
	// ItemSeen is the state given to an item that has been seen before and is not going to be processed
	ItemSeen
	// ItemGotRedirected is the state after the item has been redirected
	ItemGotRedirected
	// ItemGotChildren is the state after the item has got children
	ItemGotChildren
)

func (ItemState) String

func (s ItemState) String() string

type URL

type URL struct {
	Raw string

	Hops      int // This determines the number of hops this item is the result of, a hop is a "jump" from 1 page to another page
	Redirects int
	// contains filtered or unexported fields
}

func NewURL

func NewURL(raw string) (URL, error)

NewURL parses a raw URL string and returns a URL object. If the URL is invalid, it returns a URL object with the raw string and an error.

func (*URL) GetBase

func (u *URL) GetBase() *url.URL

GetBase returns the base URL of the item

func (*URL) GetBody

func (u *URL) GetBody() spooledtempfile.ReadSeekCloser

func (*URL) GetDocumentCache

func (u *URL) GetDocumentCache() *goquery.Document

func (*URL) GetDocumentEncoding

func (u *URL) GetDocumentEncoding() encoding.Encoding

func (*URL) GetHops

func (u *URL) GetHops() int

func (*URL) GetMIMEType

func (u *URL) GetMIMEType() *mimetype.MIME

if mimetype is not set, try to get it from Content-Type header and cache it.

WARN: Remember to check for nil return values

func (*URL) GetParsed

func (u *URL) GetParsed() *url.URL

func (*URL) GetRedirects

func (u *URL) GetRedirects() int

func (*URL) GetRequest

func (u *URL) GetRequest() *http.Request

func (*URL) GetResponse

func (u *URL) GetResponse() *http.Response

NOTE:

In normal mode, GetResponse() always returns a valid *http.Response
In headless mode, GetResponse() always returns nil

func (*URL) Parse

func (u *URL) Parse() (err error)

func (*URL) RewindBody

func (u *URL) RewindBody()

func (*URL) SetBase

func (u *URL) SetBase(base *url.URL)

SetBase sets the base URL of the item

func (*URL) SetBody

func (u *URL) SetBody(body spooledtempfile.ReadSeekCloser)

func (*URL) SetDocumentCache

func (u *URL) SetDocumentCache(doc *goquery.Document)

func (*URL) SetDocumentEncoding

func (u *URL) SetDocumentEncoding(enc encoding.Encoding)

func (*URL) SetHops

func (u *URL) SetHops(hops int)

func (*URL) SetMIMEType

func (u *URL) SetMIMEType(mimetype *mimetype.MIME)

func (*URL) SetRequest

func (u *URL) SetRequest(r *http.Request)

func (*URL) SetResponse

func (u *URL) SetResponse(r *http.Response)

func (*URL) String

func (u *URL) String() string

Jump to

Keyboard shortcuts

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