core

package
v0.0.0-...-713aa60 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Inbound = "."
	Dest    = "~/Documents"

	TimestampPrefixMatch, _ = regexp.Compile(`^\d\d\d\d\d\d\d\d-\d\d\d\d\d\d\.\d\d\d_(.*)$`)
)
View Source
var (
	DEPENDENCIES = map[string]string{
		"pdftotext": "display textual preview of pdf",
		"xdg-open":  "open pdf in your default viewer",
		"ocrmypdf":  "run ocr on pdf",
		"img2pdf":   "convert image to pdf",
		"ag":        "list your documents very fast",
		"fzf":       "fuzzy search through your documents",
		"rga":       "ripgrep-all - use in combination with fzf to fuzzy search your documents",
	}
)
View Source
var (
	OCRMYPDF_ERRCODES = map[int]string{
		0:   "Everything worked as expected.",
		1:   "Invalid arguments, exited with an error.",
		2:   "The input file does not seem to be a valid PDF.",
		3:   "An external program required by OCRmyPDF is missing.",
		4:   "An output file was created, but it does not seem to be a valid PDF. The file will be available.",
		5:   "The user running OCRmyPDF does not have sufficient permissions to read the input file and write the output file.",
		6:   "The file already appears to contain text so it may not need OCR. See output message.",
		7:   "An error occurred in an external program (child process) and OCRmyPDF cannot continue.",
		8:   "The input PDF is encrypted. OCRmyPDF does not read encrypted PDFs. Use another program such as qpdf to remove encryption.",
		9:   "A custom configuration file was forwarded to Tesseract using --tesseract-config, and Tesseract rejected this file.",
		10:  "A valid PDF was created, PDF/A conversion failed. The file will be available.",
		15:  "Some other error occurred.",
		130: "The program was interrupted by pressing Ctrl+C.",
	}
)

Functions

func CheckDependencies

func CheckDependencies() (available, missing []string)

MissingExternDependencies returns a slice with the names of executables which are missing on the system to use all the functionality

func CountDirectory

func CountDirectory(directory string) int

CountDirectory returns the number of files in a directory

func GetCachedDirectoryFiles

func GetCachedDirectoryFiles(directoryname string) ([]fs.DirEntry, error)

GetCachedDirectoryFiles returns the list of files for the given directory name from the cache

func GetCachedDocPreview

func GetCachedDocPreview(name string) string

GetCachedDocPreview returns the text preview for the given file name from the cache

func GetDirectories

func GetDirectories() ([]fs.DirEntry, error)

GetDirectories returns a slice of the existing directories

func GetDirectoryFiles

func GetDirectoryFiles(directory string) ([]fs.DirEntry, error)

GetDirectoryFiles returns a slice of files in the directory

func GetDocPreview

func GetDocPreview(name string) string

GetDocPreview returns the text layer of a pdf as simple string by running the external commant pdftotext on it

func GetInboundFiles

func GetInboundFiles() ([]fs.DirEntry, error)

GetInboundFiles returns a slice of all inbound files

func GetOcrInboundFunc

func GetOcrInboundFunc(progress chan float32, currentFile chan string) (runner func(), err error)

GetOcrInboundFunc returns a function that can be run async to iterate all inbound files and add a text layer to scans progress can be watched by the channels that are passed here

func GetTimestampFilePrefix

func GetTimestampFilePrefix() string

GetTimestampFilePrefix returns as timestamp prefix Quite long, not sure about that yet, but it avoids duplicates / overwrites

func MoveFileToDirectory

func MoveFileToDirectory(name, newName, directoryName string) (string, error)

MoveFileToDirectory moves the given file with the given new name to the given directory. This also triggers a cache update for this directory.

func OcrPdf

func OcrPdf(name string) error

OcrPdf runs the external command ocrmypdf and so tries to add a text layer to scans

func OpenDocExternal

func OpenDocExternal(path string) error

OpenDocExternal tries to open the document in the systems default application for given type

func PrintCheckDeps

func PrintCheckDeps()

PrintCheckDeps runs a check for all external dependecies and prints out the result

func RemoveTimeStampFilePrefix

func RemoveTimeStampFilePrefix(name string) string

RemoveTimeStampFilePrefix would remove the timestamp from the files name if the file is prefixed with a timestamp that matches this programs default

func UpdateDirectoryFilesCache

func UpdateDirectoryFilesCache(directoryname string)

UpdateDirectoryFilesCache upates the list of files for the given directory name in the cache

func UpdateFilePreviewCache

func UpdateFilePreviewCache(filename string)

UpdateFilePreviewCache upates the text preview for the given file name in the cache

func WarmDirectoryFilesCache

func WarmDirectoryFilesCache(directories []fs.DirEntry)

WarmDirectoryFilesCache loads the list of files per directory and puts it into the cache the first element will be loaded sync to have it available as soon as the it is displayed by some ui the rest will be loaded async in goroutines

func WarmInboundFilePreviewCache

func WarmInboundFilePreviewCache(files []fs.DirEntry)

WarmInboundFilePreviewCache loads text previews for all inbound files into the cache the first preview will be loaded sync to have it available as soon as the it is displayed by some ui the rest will be loaded async in goroutines

Types

This section is empty.

Jump to

Keyboard shortcuts

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