paperless

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checksum

func Checksum(data []byte) string

/ Generic functionality

func ChecksumFile

func ChecksumFile(path string) (sum string, err error)

func Cli

func Cli(opts util.Options, args []string) error

func CreateDefaultPool

func CreateDefaultPool(runners int)

func DeleteImage

func DeleteImage(img *Image, db *db, destdir string) error

DeleteImage deletes the image's files and data from the database

func FileServer

func FileServer(r chi.Router, path string, root http.FileSystem)

FileServer conveniently sets up a http.FileServer handler to serve static files from a http.FileSystem. As chi updated to 3.x, the equivalent function was removed. This one is copied from the example in: https://github.com/go-chi/chi/blob/master/_examples/fileserver/main.go

func MkdirParents

func MkdirParents(filename string) error

MkdirParents creates all parent directories of the given path or returns an error if they couldn't be created

func PathAbs

func PathAbs(rootdir, path string) string

Similar to filepath.Abs except the root directory is given

func ProcessImage

func ProcessImage(img *Image, scriptname string, db *db, destdir string) (err error)

func RunCmdChain

func RunCmdChain(c *CmdChain, s *Status) (err error)

func SetupLogging

func SetupLogging()

func StartWeb

func StartWeb(o util.Options) (err error)

Types

type Cmd

type Cmd struct {
	Cmd []string
}

func NewCmd

func NewCmd(cmdstr string) (c *Cmd, err error)

NewCmd creates a new Cmd from given command string

func (*Cmd) Run

func (c *Cmd) Run(s *Status) (err error)

func (*Cmd) Validate

func (c *Cmd) Validate(e *Environment) (err error)

Validate makes sure the command is proper and can be run

type CmdChain

type CmdChain struct {

	//TODO remove this (this should come from outside)
	Environment

	Links []Link
}

func NewCmdChainScript

func NewCmdChainScript(script string) (c *CmdChain, err error)

NewCmdChainScript creates a CmdChain from a script where each command is on a separate line. The following syntax elements are supported:

- Empty lines are filtered out.

- Comments start with # and end with EOL.

- Constants are strings that begin with $ and they can be set before running the cmdchain.

- Temporary files are strings that start with $tmp and they are automatically created before running the cmdchain and removed afterwards.

func (*CmdChain) Run

func (c *CmdChain) Run(s *Status) (err error)

func (*CmdChain) Validate

func (c *CmdChain) Validate(e *Environment) (err error)

type Environment

type Environment struct {

	// Constants are variables that are defined before a command chain is run
	Constants map[string]string

	// Tempfiles are constants that house a name of a temporary file. The
	// files are created before the chain is run and they are removed at
	// the end.
	TempFiles []string

	// The directory where the commands are run. This is a created
	// temporary directory
	RootDir string

	// AllowedCommands contain the commands that are allowed. If this is
	// nil, all commands are allowed.
	AllowedCommands map[string]bool
	// contains filtered or unexported fields
}

Environment is the run environment for each command. It is supplied as part of Status for a Link when it is Run or Validated.

type Image

type Image struct {
	// in img
	Id            int
	Checksum      string
	Fileid        string
	ScanDate      time.Time
	AddDate       time.Time
	InterpretDate time.Time
	ProcessLog    string
	Filename      string

	// in imgtext
	Text    string
	Comment string

	// in tags
	Tags []Tag
}

func SaveImage

func SaveImage(filename string, data []byte, db *db, destdir string, tags string) (ret Image, err error)

SaveImage saves the image to db and starts to process it

func (*Image) CleanFile

func (i *Image) CleanFile(basedir string) string

func (*Image) OrigFile

func (i *Image) OrigFile(basedir string) string

func (*Image) ThumbFile

func (i *Image) ThumbFile(basedir string) string

func (*Image) TxtFile

func (i *Image) TxtFile(basedir string) string

type ImageResult added in v0.8.0

type ImageResult struct {
	PageResult
	Images []Image
}

type Job

type Job struct {
	Job      func()
	Finalize func()
}
type Link interface {
	Validate(*Environment) error
	Run(*Status) error
}

type Page

type Page struct {
	// Id that was the last of the previous page
	SinceId int

	// Count is the number of items in the page
	Count int
}

Pagination support

type PageResult added in v0.8.0

type PageResult struct {
	// Number of items returned by the whole search
	ResultCount int

	// IDs of the items that are the first of their page
	SinceIDs []int

	// Count is the number of items in the page
	Count int
}

PageResult adds navigation information to the paginated data

type Query added in v0.8.0

type Query struct {
}

type Runner

type Runner struct {
	RunnerCount int
	ChanBuffer  int
	Job         func(string)
	Finalize    func(string)
}

func CreateRunner

func CreateRunner(runners int) Runner

func (Runner) Do

func (run Runner) Do(data []string)

type RunnerPool

type RunnerPool struct {
	// contains filtered or unexported fields
}
var Pool *RunnerPool

func CreatePool

func CreatePool(runners int) RunnerPool

func (*RunnerPool) Delete

func (pool *RunnerPool) Delete()

func (*RunnerPool) Do

func (pool *RunnerPool) Do(job Job)

type Script

type Script struct {
	Id     int
	Name   string
	Script string
}
type Search struct {
	ID      int
	OrderBy string
	Match   string
	Tag     string
}

type Status

type Status struct {
	// The log output will be written to this
	Log io.Writer

	Environment
}

Status is the runtime status of the command chain

type Tag

type Tag struct {
	Id      int
	Name    string
	Comment string
}

type Token added in v0.8.0

type Token struct {
	Type  TokenType
	Value string
	Pos   int
}

type TokenType added in v0.8.0

type TokenType int
const (
	TokEOF   TokenType = -1
	TokError TokenType = iota
	TokCanceled
	TokAnd
	TokOr
	TokNot
	TokQuote
	TokString
	TokParOpen
	TokParClose
)

Jump to

Keyboard shortcuts

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