models

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DocumentHistoryActionCreate         = "create"
	DocumentHistoryActionRename         = "rename"
	DocumentHistoryActionDescription    = "description"
	DocumentHistoryActionDate           = "date"
	DocumentHistoryActionLanguage       = "lang"
	DocumentHistoryActionContent        = "content"
	DocumentHistoryActionMetadataRemove = "remove metadata"
	DocumentHistoryActionMetadataAdd    = "add metadata"
	DocumentHistoryActionDelete         = "delete"
	DocumentHistoryActionRestore        = "restore"
	DocumentHistoryActionFavorite       = "favorite"
	DocumentHistoryActionUnFavorite     = "unfavorite"
)

Variables

ProcessStepsAll is a list of default steps to run for new document.

View Source
var ProcessStepsKeys = map[ProcessStep]string{
	ProcessHash:           "hash",
	ProcessThumbnail:      "thumbnail",
	ProcessParseContent:   "content",
	ProcessDetectLanguage: "detect-language",
	ProcessRules:          "rules",
	ProcessFts:            "fts",
}

ProcessStepsOrder is the order in which the steps are to be run in ascending order.

Functions

func GetPrettySize

func GetPrettySize(bytes int64) string

GetSize returns human-formatted size

func MidnightForDate

func MidnightForDate(t time.Time) time.Time

Types

type Document

type Document struct {
	Timestamp
	Id          string    `db:"id"`
	UserId      int       `db:"user_id"`
	Name        string    `db:"name"`
	Description string    `db:"description"`
	Content     string    `db:"content"`
	Filename    string    `db:"filename"`
	Hash        string    `db:"hash"`
	Mimetype    string    `db:"mimetype"`
	Size        int64     `db:"size"`
	Date        time.Time `db:"date"`
	Metadata    []Metadata
	Tags        []Tag
	Lang        Lang `db:"lang"`
	Shares      int  `db:"shares"`
	Favorite    bool `db:"favorite"`

	DeletedAt sql.NullTime `db:"deleted_at"`
}

Document represents single file and data related to it.

func (*Document) Diff

func (d *Document) Diff(newDocument *Document, userId int) ([]DocumentHistory, error)

Diffs returns a list of DocumentHistory items from d -> newDocument. Metadata changes are not evaluated.

func (*Document) FilterAttributes

func (d *Document) FilterAttributes() []string

func (*Document) GetSize

func (d *Document) GetSize() string

GetSize returns human-formatted size

func (*Document) GetType

func (d *Document) GetType() string

GetType returns either 'pdf' or 'image' depending on type of content.

func (*Document) HasMetadataKey

func (d *Document) HasMetadataKey(keyId int) bool

HasMetadataKey returns true if document has given metadata key.

func (*Document) HasMetadataKeyValue

func (d *Document) HasMetadataKeyValue(keyId, valueId int) bool

HasMetadataKeyValue returns true if document has given metadata key and value.

func (*Document) Init

func (d *Document) Init()

Init initializes new document. It ensures document has valid uuid assigned to it.

func (*Document) IsImage

func (d *Document) IsImage() bool

IsImage returns true if document file is image.

func (*Document) IsPdf

func (d *Document) IsPdf() bool

IsPdf returns true id document file is pdf.

func (*Document) SortAttributes

func (d *Document) SortAttributes() []string

func (*Document) SortNoCase

func (d *Document) SortNoCase() []string

type DocumentHistory

type DocumentHistory struct {
	Id         int       `db:"id" json:"id"`
	DocumentId string    `db:"document_id" json:"document_id"`
	Action     string    `db:"action" json:"action"`
	OldValue   string    `db:"old_value" json:"old_value"`
	NewValue   string    `db:"new_value" json:"new_value"`
	UserId     int       `db:"user_id" json:"user_id"`
	User       string    `db:"user" json:"user"`
	CreatedAt  time.Time `db:"created_at" json:"created_at"`
}

func MetadataDiff

func MetadataDiff(id string, userId int, original, updated *MetadataArray) []DocumentHistory

func (*DocumentHistory) FilterAttributes

func (dh *DocumentHistory) FilterAttributes() []string

func (*DocumentHistory) SortAttributes

func (dh *DocumentHistory) SortAttributes() []string

func (*DocumentHistory) SortNoCase

func (dh *DocumentHistory) SortNoCase() []string

func (*DocumentHistory) Update

func (dh *DocumentHistory) Update()

type DocumentHistoryAction

type DocumentHistoryAction string

type DocumentMetadataHistoryEntry

type DocumentMetadataHistoryEntry struct {
	KeyId   int `json:"key_id"`
	ValueId int `json:"value_id"`
}

type DocumentSharePermission added in v0.6.0

type DocumentSharePermission struct {
	UserId      int         `db:"user_id"`
	Username    string      `db:"user_name"`
	DocumentId  string      `db:"document_id"`
	Permissions Permissions `db:"permissions"`
	Timestamp
}

type Int

type Int int64

Int as an integer that accepts null values from database.

func (*Int) Scan

func (i *Int) Scan(src interface{}) error

func (Int) Value

func (i Int) Value() (driver.Value, error)

type IntId

type IntId uint64

func (*IntId) Scan

func (i *IntId) Scan(src interface{}) error

Scan scans duration from postgres string: (00:00:00). Only hours-minutes-seconds are supported.

func (IntId) Value

func (i IntId) Value() (driver.Value, error)

type Job

type Job struct {
	Id         int         `db:"id" json:"id"`
	DocumentId string      `db:"document_id" json:"document_id"`
	Message    string      `db:"message" json:"message"`
	Status     JobStatus   `json:"status"`
	Step       ProcessStep `db:"process_step"`

	StartedAt time.Time `db:"started_at" json:"started_at"`
	StoppedAt time.Time `db:"stopped_at" json:"stopped_at"`
}

Job is a pipeline that each document goes through. It consists of multiple steps to process document. Job is only used for logging purposes.

type JobComposite

type JobComposite struct {
	Job
	Duration time.Duration `db:"duration" json:"duration"`
}

JobComposite contains additional information. Actual underlying model is still Job.

func (*JobComposite) SetDuration

func (jc *JobComposite) SetDuration()

type JobStatus

type JobStatus string

JobStatus describes status for process-step It maps as integer to database.

const (
	JobAwaiting JobStatus = "Awaiting"
	JobRunning  JobStatus = "Running"
	JobFinished JobStatus = "Finished"
	JobFailure  JobStatus = "Failure"
)

func (*JobStatus) Scan

func (j *JobStatus) Scan(src interface{}) error

func (*JobStatus) Value

func (j *JobStatus) Value() (driver.Value, error)

type Lang added in v0.5.0

type Lang string

func (*Lang) Scan added in v0.5.0

func (l *Lang) Scan(src interface{}) error

func (Lang) String added in v0.5.0

func (l Lang) String() string

func (Lang) Value added in v0.5.0

func (l Lang) Value() (driver.Value, error)

type Language added in v0.5.0

type Language struct {
	Id   string `json:"id" db:"id"`
	Name string `json:"name" db:"name"`
}

type LinkedDocument

type LinkedDocument struct {
	DocumentId   string    `json:"id"`
	DocumentName string    `json:"name"`
	CreatedAt    time.Time `json:"created_at"`
}

LinkedDocument represents documents that are linked together

type Metadata

type Metadata struct {
	KeyId   int    `db:"key_id" json:"key_id"`
	Key     string `db:"key" json:"key"`
	Icon    string `db:"icon" json:"icon"`
	Style   string `db:"style" json:"style"`
	ValueId int    `db:"value_id" json:"value_id"`
	Value   string `db:"value" json:"value"`
}

Metadata is metadata key-value pair assigned to document

type MetadataArray added in v0.6.0

type MetadataArray []Metadata

func (*MetadataArray) Len added in v0.6.0

func (m *MetadataArray) Len() int

func (*MetadataArray) Less added in v0.6.0

func (m *MetadataArray) Less(i, j int) bool

func (*MetadataArray) Swap added in v0.6.0

func (m *MetadataArray) Swap(i, j int)

type MetadataKey

type MetadataKey struct {
	Id        int       `db:"id" json:"id"`
	UserId    int       `db:"user_id" json:"-"`
	Key       string    `db:"key" json:"key"`
	CreatedAt time.Time `db:"created_at" json:"created_at"`
	Comment   string    `db:"comment" json:"comment"`
	Icon      string    `db:"icon" json:"icon"`
	Style     string    `db:"style" json:"style"`
}

func (*MetadataKey) FilterAttributes

func (m *MetadataKey) FilterAttributes() []string

func (*MetadataKey) SortAttributes

func (m *MetadataKey) SortAttributes() []string

func (*MetadataKey) SortNoCase

func (m *MetadataKey) SortNoCase() []string

func (*MetadataKey) Update

func (m *MetadataKey) Update()

type MetadataKeyAnnotated

type MetadataKeyAnnotated struct {
	MetadataKey
	MetadataKeyStatistics
}

type MetadataKeyStatistics

type MetadataKeyStatistics struct {
	NumDocuments      int `db:"documents_count" json:"documents_count"`
	NumMetadataValues int `db:"values_count" json:"metadata_values_count"`
}

type MetadataRuleType

type MetadataRuleType string
const (
	MetadataMatchExact MetadataRuleType = "exact"
	MetadataMatchRegex MetadataRuleType = "regex"
)

type MetadataSearchResult added in v0.6.0

type MetadataSearchResult struct {
	Keys   []MetadataKey   `json:"keys"`
	Values []MetadataValue `json:"values"`
}

type MetadataValue

type MetadataValue struct {
	Id           int       `db:"id" json:"id"`
	UserId       int       `db:"user_id" json:"-"`
	Key          string    `db:"key" json:"key"`
	KeyId        int       `db:"key_id" json:"key_id"`
	Value        string    `db:"value" json:"value"`
	CreatedAt    time.Time `db:"created_at" json:"created_at"`
	Comment      string    `db:"comment" json:"comment"`
	NumDocuments int       `db:"documents_count" json:"documents_count"`

	// MatchDocuments instructs to try to automatically match MetadataValue inside documents
	MatchDocuments bool             `db:"match_documents" json:"match_documents"`
	MatchType      MetadataRuleType `db:"match_type" json:"match_type"`
	MatchFilter    string           `db:"match_filter" json:"match_filter"`
}

func (*MetadataValue) FilterAttributes

func (m *MetadataValue) FilterAttributes() []string

func (*MetadataValue) SortAttributes

func (m *MetadataValue) SortAttributes() []string

func (*MetadataValue) SortNoCase

func (m *MetadataValue) SortNoCase() []string

func (*MetadataValue) Update

func (m *MetadataValue) Update()

type Modeler

type Modeler interface {
	// Update marks model as updated.
	Update()
	// FilterAttributes returns list of attributes that can be used for filtering.
	FilterAttributes() []string

	// SortAttributes returns list of attributes that can be used for sorting.
	SortAttributes() []string

	SortNoCase() []string
}

Modeler is a basic interface for all models.

type PasswordResetToken

type PasswordResetToken struct {
	Timestamp
	Id        int       `db:"id"`
	UserId    int       `db:"user_id"`
	Token     string    `db:"token"`
	ExpiresAt time.Time `db:"expires_at"`
}

func (*PasswordResetToken) HasExpired

func (p *PasswordResetToken) HasExpired() bool

func (*PasswordResetToken) TokenMatches

func (p *PasswordResetToken) TokenMatches(token string) (bool, error)

func (*PasswordResetToken) Validate

func (p *PasswordResetToken) Validate() error

type Permissions added in v0.6.0

type Permissions struct {
	Read   bool `json:"read"`
	Write  bool `json:"write"`
	Delete bool `json:"delete"`
}

func (*Permissions) Scan added in v0.6.0

func (p *Permissions) Scan(src interface{}) error

func (Permissions) Value added in v0.6.0

func (p Permissions) Value() (driver.Value, error)

type ProcessItem

type ProcessItem struct {
	DocumentId string `db:"document_id"`
	Document   *Document
	Action     ProcessStep `db:"action"`
	CreatedAt  time.Time   `db:"created_at"`
	Trigger    RuleTrigger `db:"trigger"`
}

ProcessItem contains document that awaits further processing.

type ProcessStep

type ProcessStep string

ProcessStep describes next step for document. It maps as integer to database.

const (
	ProcessHash           ProcessStep = "hash"
	ProcessThumbnail      ProcessStep = "thumbnail"
	ProcessParseContent   ProcessStep = "extract"
	ProcessDetectLanguage ProcessStep = "detect-language"
	ProcessRules          ProcessStep = "rules"
	ProcessFts            ProcessStep = "fts"
)

func (*ProcessStep) Scan

func (ps *ProcessStep) Scan(src interface{}) error

func (ProcessStep) String

func (ps ProcessStep) String() string

func (*ProcessStep) Value

func (ps *ProcessStep) Value() (driver.Value, error)

type Rule

type Rule struct {
	Id          int                    `db:"id"`
	UserId      int                    `db:"user_id"`
	Name        string                 `db:"name"`
	Description string                 `db:"description"`
	Enabled     bool                   `db:"enabled"`
	Order       int                    `db:"rule_order"`
	Mode        RuleConditionMatchType `db:"mode"`
	Timestamp
	Triggers RuleTriggerArray `db:"triggers"`

	Conditions []*RuleCondition
	Actions    []*RuleAction
}

func (*Rule) Validate

func (r *Rule) Validate() error

type RuleAction

type RuleAction struct {
	Id      int  `db:"id"`
	RuleId  int  `db:"rule_id"`
	Enabled bool `db:"enabled"`
	// OnCondition, if vs else
	OnCondition bool `db:"on_condition"`

	Action            RuleActionType `db:"action"`
	Value             string         `db:"value"`
	MetadataKey       IntId          `db:"metadata_key"`
	MetadataValue     IntId          `db:"metadata_value"`
	MetadataKeyName   Text           `db:"metadata_key_name"`
	MetadataValueName Text           `db:"metadata_value_name"`
}

type RuleActionType

type RuleActionType string
const (
	RuleActionSetName           RuleActionType = "name_set"
	RuleActionAppendName        RuleActionType = "name_append"
	RuleActionSetDescription    RuleActionType = "description_set"
	RuleActionAppendDescription RuleActionType = "description_append"
	RuleActionAddMetadata       RuleActionType = "metadata_add"
	RuleActionRemoveMetadata    RuleActionType = "metadata_remove"
	RuleActionSetDate           RuleActionType = "date_set"
)

func (RuleActionType) String

func (r RuleActionType) String() string

type RuleCondition

type RuleCondition struct {
	Id              int  `db:"id"`
	RuleId          int  `db:"rule_id"`
	Enabled         bool `db:"enabled"`
	CaseInsensitive bool `db:"case_insensitive"`
	// Inverted inverts the match result
	Inverted      bool              `db:"inverted_match"`
	ConditionType RuleConditionType `db:"condition_type"`

	// IsRegex defines whether to apply regex pattern
	IsRegex bool `db:"is_regex"`
	// Value to compare against, if text field
	Value   string `db:"value"`
	DateFmt string `db:"date_fmt"`

	// Metadata to operate with
	MetadataKey       IntId `db:"metadata_key"`
	MetadataValue     IntId `db:"metadata_value"`
	MetadataKeyName   Text  `db:"metadata_key_name"`
	MetadataValueName Text  `db:"metadata_value_name"`
}

func (*RuleCondition) HasMetadata

func (r *RuleCondition) HasMetadata() bool

func (*RuleCondition) Validate

func (r *RuleCondition) Validate() error

type RuleConditionMatchType

type RuleConditionMatchType int
const (
	// RuleMatchAll requires all conditions must be matched
	RuleMatchAll RuleConditionMatchType = 1
	//RuleMatchAny allows any condition to match
	RuleMatchAny RuleConditionMatchType = 2
)

func (*RuleConditionMatchType) FromString

func (r *RuleConditionMatchType) FromString(str string) error

func (RuleConditionMatchType) String

func (r RuleConditionMatchType) String() string

type RuleConditionType

type RuleConditionType string
const (
	RuleConditionNameIs       RuleConditionType = "name_is"
	RuleConditionNameStarts   RuleConditionType = "name_starts"
	RuleConditionNameContains RuleConditionType = "name_contains"

	RuleConditionDescriptionIs       RuleConditionType = "description_is"
	RuleConditionDescriptionStarts   RuleConditionType = "description_starts"
	RuleConditionDescriptionContains RuleConditionType = "description_contains"

	RuleConditionContentIs       RuleConditionType = "content_is"
	RuleConditionContentStarts   RuleConditionType = "content_starts"
	RuleConditionContentContains RuleConditionType = "content_contains"

	RuleConditionDateIs     RuleConditionType = "date_is"
	RuleConditionDateAfter  RuleConditionType = "date_after"
	RuleConditionDateBefore RuleConditionType = "date_before"

	RuleConditionMetadataHasKey        RuleConditionType = "metadata_has_key"
	RuleConditionMetadataHasKeyValue   RuleConditionType = "metadata_has_key_value"
	RuleConditionMetadataCount         RuleConditionType = "metadata_count"
	RuleConditionMetadataCountLessThan RuleConditionType = "metadata_count_less_than"
	RuleConditionMetadataCountMoreThan RuleConditionType = "metadata_count_more_than"
)

func (RuleConditionType) String

func (r RuleConditionType) String() string

type RuleTrigger added in v0.6.0

type RuleTrigger string
const (
	RuleTriggerCreate RuleTrigger = "document-create"
	RuleTriggerUpdate RuleTrigger = "document-update"
)

type RuleTriggerArray added in v0.6.0

type RuleTriggerArray []RuleTrigger

func (*RuleTriggerArray) Scan added in v0.6.0

func (t *RuleTriggerArray) Scan(src interface{}) error

func (*RuleTriggerArray) ToJsonString added in v0.6.0

func (t *RuleTriggerArray) ToJsonString() string

func (*RuleTriggerArray) Value added in v0.6.0

func (t *RuleTriggerArray) Value() (driver.Value, error)

type SystemStatistics

type SystemStatistics struct {
	DocumentsInQueue            int    `json:"documents_queued" db:"documents_queued"`
	DocumentsProcessedToday     int    `json:"documents_processed_today" db:"documents_processed_today"`
	DocumentsProcessedLastWeek  int    `json:"documents_processed_past_week" db:"documents_processed_past_week"`
	DocumentsProcessedLastMonth int    `json:"documents_processed_past_month" db:"documents_processed_past_month"`
	DocumentsTotal              int    `json:"documents_total" db:"documents_total"`
	DocumentsTotalSize          int64  `json:"documents_total_size" db:"documents_size"`
	DocumentsTotalSizeString    string `json:"documents_total_size_string"`
	ServerLoad                  string `json:"server_load"`
}

type Tag

type Tag struct {
	Id        int       `db:"id" json:"id"`
	Key       string    `db:"key" json:"key"`
	Comment   string    `db:"comment" json:"comment"`
	CreatedAt time.Time `db:"created_at" json:"created_at"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}

Tag is a per-user label to add to documents. It has many-to-many relationship with documents.

type TagComposite

type TagComposite struct {
	Tag
	DocumentCount int `db:"document_count" json:"document_count"`
}

type Text

type Text string

func (*Text) Scan

func (t *Text) Scan(src interface{}) error

func (Text) String

func (t Text) String() string

func (Text) Value

func (t Text) Value() (driver.Value, error)

type Timestamp

type Timestamp struct {
	CreatedAt time.Time `db:"created_at" json:"created_at"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}

func (*Timestamp) FilterAttributes

func (t *Timestamp) FilterAttributes() []string

func (*Timestamp) SortAttributes

func (t *Timestamp) SortAttributes() []string

func (*Timestamp) SortNoCase

func (t *Timestamp) SortNoCase() []string

func (*Timestamp) Update

func (t *Timestamp) Update()

type Token

type Token struct {
	Timestamp
	Id            int       `json:"id" db:"id"`
	UserId        int       `json:"user_id" db:"user_id"`
	Key           string    `json:"key" db:"key"`
	Name          string    `json:"name" db:"name"`
	IpAddr        string    `json:"ip_addr" db:"ip_address"`
	ExpiresAt     time.Time `json:"expires_at" db:"expires_at"`
	LastSeen      time.Time `json:"last_seen" db:"last_seen"`
	LastConfirmed time.Time `json:"last_confirmed" db:"last_confirmed"`
}

func (*Token) ConfirmationExpired

func (t *Token) ConfirmationExpired() bool

func (*Token) HasExpired

func (t *Token) HasExpired() bool

func (*Token) Init

func (t *Token) Init() error

type UpdateUserSharing added in v0.6.0

type UpdateUserSharing struct {
	UserId      int         `json:"user_id"`
	Permissions Permissions `json:"permissions"`
}

type User

type User struct {
	Timestamp
	Id       int    `db:"id"`
	Name     string `db:"name"`
	Password string `db:"password"`
	Email    string `db:"email"`
	IsAdmin  bool   `db:"admin"`
	IsActive bool   `db:"active"`
}

func (*User) PasswordMatches

func (u *User) PasswordMatches(password string) (bool, error)

func (*User) SetPassword

func (u *User) SetPassword(newPassw string) error

type UserDocumentStatistics

type UserDocumentStatistics struct {
	UserId               int                    `json:"id"`
	NumDocuments         int                    `json:"num_documents"`
	YearlyStats          []UserDocumentYearStat `json:"yearly_stats"`
	NumMetadataKeys      int                    `json:"num_metadata_keys"`
	NumMetadataValues    int                    `json:"num_metadata_values"`
	LastDocumentsUpdated []string               `json:"last_documents_updated"`
	LastDocumentsAdded   []string               `json:"last_documents_added"`
	LastDocumentsViewed  []string               `json:"last_documents_viewed"`
	Favorites            []string               `json:"favorites"`
}

UserDocumentStatistics contains various about user's documents.

type UserDocumentYearStat

type UserDocumentYearStat struct {
	// year
	// Example: 2020
	Year int `json:"year" db:"year"`
	// number of documents
	// Example: 49
	NumDocuments int `json:"num_documents" db:"count"`
}

type UserInfo

type UserInfo struct {
	UserId        int       `json:"id" db:"user_id"`
	UserName      string    `json:"user_name" db:"username"`
	Email         string    `json:"email" db:"email"`
	IsActive      bool      `json:"is_active" db:"active"`
	UpdatedAt     time.Time `json:"updated_at" db:"updated_at"`
	CreatedAt     time.Time `json:"created_at" db:"created_at"`
	DocumentCount Int       `json:"documents_count" db:"documents_count"`
	DocumentsSize Int       `json:"documents_size" db:"documents_size"`
	IsAdmin       bool      `json:"is_admin" db:"admin"`
	LastSeen      time.Time `json:"last_seen" db:"last_seen"`

	Indexing bool `json:"indexing"`
}

type UserPreferences

type UserPreferences struct {
	UserId        int       `json:"user_id" db:"user_id"`
	UserName      string    `json:"user_name" db:"username"`
	Email         string    `json:"email" db:"email"`
	UpdatedAt     time.Time `json:"updated_at" db:"updated_at"`
	CreatedAt     time.Time `json:"created_at" db:"created_at"`
	DocumentCount Int       `json:"documents_count" db:"documents_count"`
	DocumentsSize Int       `json:"documents_size" db:"documents_size"`
	IsAdmin       bool      `json:"is_admin" db:"is_admin"`
}

UserPreferences are per-user preferences and configuration options.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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