rinser

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const FormFileKey = "file"
View Source
const FormLangKey = "lang"
View Source
const FormURLKey = "url"
View Source
const WorkerImage = "ghcr.io/linkdata/rinseworker"

Variables

View Source
var ErrContentEncoded = errors.New("Content-Encoding is set")
View Source
var ErrDocumentTooLarge = errors.New("document too large")
View Source
var ErrDuplicateUUID = errors.New("duplicate UUID")
View Source
var ErrIllegalLanguage = errors.New("illegal language string")
View Source
var ErrIllegalURLScheme = errors.New("illegal URL scheme")
View Source
var ErrImageSeenTwice = errors.New("image file seen twice")
View Source
var ErrMissingDocument = errors.New("no document found")
View Source
var ErrMultipleDocuments = errors.New("multiple documents found")
View Source
var ErrWorkerRootDirNotFound = errors.New("/opt/rinseworker not found")
View Source
var LanguageCode = map[string]string{}/* 103 elements not displayed */
View Source
var LanguageTika = map[string]string{
	"da": "dan",
	"de": "deu",
	"et": "est",
	"el": "ell",
	"en": "eng",
	"es": "spa",
	"fi": "fin",
	"fr": "fra",
	"hu": "hun",
	"is": "isl",
	"it": "ita",
	"nl": "nld",
	"no": "nor",
	"pl": "pol",
	"pt": "por",
	"ru": "rus",
	"sv": "swe",
	"th": "tha",
}

Functions

func HTTPJSON

func HTTPJSON(hw http.ResponseWriter, code int, obj any)

func SendHTTPError

func SendHTTPError(hw http.ResponseWriter, code int, err error)

Types

type AddJobURL

type AddJobURL struct {
	URL  string `json:"url" example:"https://getsamplefiles.com/download/pdf/sample-1.pdf"`
	Lang string `json:"lang" example:"auto"`
}

type HTTPError

type HTTPError struct {
	Code  int
	Error string
}

type Job

type Job struct {
	*Rinse  `json:"-"`
	Workdir string    `json:"workdir" example:"/tmp/rinse-550e8400-e29b-41d4-a716-446655440000"`
	Datadir string    `json:"-"`
	Name    string    `json:"name" example:"example.docx"`
	Created time.Time `json:"created" example:"2024-01-01T12:00:00+00:00" format:"dateTime"`
	UUID    uuid.UUID `json:"uuid" example:"550e8400-e29b-41d4-a716-446655440000" format:"uuid"`

	Error    error  `json:"error,omitempty"`
	PdfName  string `json:"pdfname,omitempty" example:"example-rinsed.pdf"` // rinsed PDF file name
	Language string `json:"lang,omitempty" example:"auto"`
	Done     bool   `json:"done,omitempty" example:"false"`
	Diskuse  int64  `json:"diskuse,omitempty" example:"1234"`
	Pages    int    `json:"pages,omitempty" example:"1"`
	// contains filtered or unexported fields
}

func NewJob

func NewJob(rns *Rinse, name, lang string) (job *Job, err error)

func (*Job) Button

func (job *Job) Button() jaws.ClickHandler

func (*Job) Close

func (job *Job) Close()

func (*Job) DocumentName

func (job *Job) DocumentName() (s string)

func (*Job) HasMeta

func (job *Job) HasMeta() (yes bool)

func (*Job) Lang

func (job *Job) Lang() (s string)

func (*Job) MetaPath

func (job *Job) MetaPath() string

func (*Job) Preview

func (job *Job) Preview(numPages, imgWidth int) (b []byte, err error)

func (*Job) Previewable

func (job *Job) Previewable() (yes bool)

func (*Job) ResultName

func (job *Job) ResultName() (s string)

func (*Job) ResultPath

func (job *Job) ResultPath() string

func (*Job) Start

func (job *Job) Start(maxTime time.Duration) (err error)

func (*Job) State

func (job *Job) State() (state JobState)

func (*Job) UiJobMeta

func (job *Job) UiJobMeta() jaws.Updater

func (*Job) UiJobPreview

func (job *Job) UiJobPreview() jaws.Updater
func (job *Job) UiLink() jaws.HtmlGetter

func (*Job) UiStatus

func (job *Job) UiStatus() (ui jaws.HtmlGetter)

type JobState

type JobState int
const (
	JobNew JobState = iota
	JobStarting
	JobDownload
	JobExtractMeta
	JobDetectLanguage
	JobDocToPdf
	JobPdfToImages
	JobTesseract
	JobEnding
	JobFinished
	JobFailed
)

type Rinse

type Rinse struct {
	Config     *webserv.Config
	Jaws       *jaws.Jaws
	RunscBin   string
	RootDir    string
	FaviconURI string
	Languages  []string
	// contains filtered or unexported fields
}

func New

func New(cfg *webserv.Config, mux *http.ServeMux, jw *jaws.Jaws, devel bool) (rns *Rinse, err error)

func (*Rinse) AddJob

func (rns *Rinse) AddJob(job *Job) (err error)

func (*Rinse) AutoCleanup added in v0.7.0

func (rns *Rinse) AutoCleanup() (n int)

func (*Rinse) Close

func (rns *Rinse) Close()

func (*Rinse) FindJob

func (rns *Rinse) FindJob(s string) *Job

func (*Rinse) FormFileKey

func (rns *Rinse) FormFileKey() string

func (*Rinse) FormLangKey

func (rns *Rinse) FormLangKey() string

func (*Rinse) FormURLKey

func (rns *Rinse) FormURLKey() string

func (*Rinse) IsClosed

func (rns *Rinse) IsClosed() (yes bool)

func (*Rinse) JawsContains

func (rns *Rinse) JawsContains(e *jaws.Element) (contents []jaws.UI)

JawsContains implements jaws.Container.

func (*Rinse) JobList

func (rns *Rinse) JobList() (jobs []*Job)

func (*Rinse) LanguageName

func (rns *Rinse) LanguageName(code string) string

func (*Rinse) MaxConcurrent

func (rns *Rinse) MaxConcurrent() (n int)

func (*Rinse) MaxRuntime added in v0.7.0

func (rns *Rinse) MaxRuntime() (n int)

func (*Rinse) MaxUploadSize added in v0.7.0

func (rns *Rinse) MaxUploadSize() (n int64)

func (*Rinse) MaybeStartJob

func (rns *Rinse) MaybeStartJob() (err error)

func (*Rinse) NewJob added in v0.7.0

func (rns *Rinse) NewJob(name, lang string) (job *Job, err error)

func (*Rinse) PkgName

func (rns *Rinse) PkgName() string

func (*Rinse) PkgVersion

func (rns *Rinse) PkgVersion() string

func (*Rinse) RESTDELETEJobsUUID

func (rns *Rinse) RESTDELETEJobsUUID(hw http.ResponseWriter, hr *http.Request)

RESTDELETEJobsUUID godoc

@Summary		Delete a job
@Description	Delete by job UUID
@Tags			jobs
@Accept			*/*
@Produce		json
@Param			uuid	path		string	true	"49d1e304-d2b8-46bf-b6a6-f1e9b797e1b0"
@Success		200		{object}	Job
@Failure		404		{object}	HTTPError
@Router			/jobs/{uuid} [delete]

func (*Rinse) RESTGETJobs

func (rns *Rinse) RESTGETJobs(hw http.ResponseWriter, hr *http.Request)

RESTGETJobs godoc

@Summary		List jobs
@Description	Get a list of all jobs.
@Tags			jobs
@Accept			*/*
@Produce		json
@Success		200	{array}	Job
@Router			/jobs [get]

func (*Rinse) RESTGETJobsUUID

func (rns *Rinse) RESTGETJobsUUID(hw http.ResponseWriter, hr *http.Request)

RESTGETJobsUUID godoc

@Summary		Get job metadata.
@Description	Get job metadata by UUID.
@Tags			jobs
@Accept			json
@Produce		json
@Param			uuid	path		string	true	"49d1e304-d2b8-46bf-b6a6-f1e9b797e1b0"
@Success		200		{object}	Job
@Failure		404		{object}	HTTPError
@Router			/jobs/{uuid} [get]

func (*Rinse) RESTGETJobsUUIDMeta

func (rns *Rinse) RESTGETJobsUUIDMeta(hw http.ResponseWriter, hr *http.Request)

RESTGETJobsUUIDMeta godoc

@Summary		Get the jobs document metadata.
@Description	Get the jobs document metadata.
@Tags			jobs
@Accept			*/*
@Produce		json
@Param			uuid	path		string	true	"49d1e304-d2b8-46bf-b6a6-f1e9b797e1b0"
@Success		200		{file}		file	""
@Success		202		{object}	Job		"Metadata not yet ready."
@Failure		404		{object}	HTTPError
@Failure		410		{object}	HTTPError "Job failed."
@Failure		500		{object}	HTTPError
@Router			/jobs/{uuid}/meta [get]

func (*Rinse) RESTGETJobsUUIDPreview

func (rns *Rinse) RESTGETJobsUUIDPreview(w http.ResponseWriter, r *http.Request)

RESTGETJobsUUIDPreview godoc

@Summary		Show a job preview image
@Description	show job preview image by UUID
@Tags			jobs
@Accept			*/*
@Produce		html
@Produce		jpeg
@Param			uuid	path		string	true	"49d1e304-d2b8-46bf-b6a6-f1e9b797e1b0"
@Param			pages	query		int		false	"1"
@Param			width	query		int		false	"172"
@Success		200		{html}		html	""
@Success		200		{jpeg}		jpeg	""
@Success		202		{object}	Job		"Preview not yet ready."
@Failure		400		{object}	HTTPError
@Failure		404		{object}	HTTPError
@Failure		410		{object}	HTTPError	"Job failed."
@Failure		500		{object}	HTTPError
@Router			/jobs/{uuid}/preview [get]

func (*Rinse) RESTGETJobsUUIDRinsed

func (rns *Rinse) RESTGETJobsUUIDRinsed(hw http.ResponseWriter, hr *http.Request)

RESTGETJobsUUIDRinsed godoc

@Summary		Get the jobs rinsed document.
@Description	Get the jobs rinsed document.
@Tags			jobs
@Accept			*/*
@Produce		application/pdf
@Produce		json
@Param			uuid	path		string	true	"49d1e304-d2b8-46bf-b6a6-f1e9b797e1b0"
@Success		200		{file}		file	""
@Success		202		{object}	Job		"Rinsed version not yet ready."
@Failure		404		{object}	HTTPError
@Failure		410		{object}	HTTPError "Job failed."
@Failure		500		{object}	HTTPError
@Router			/jobs/{uuid}/rinsed [get]

func (*Rinse) RESTPOSTJobs

func (rns *Rinse) RESTPOSTJobs(hw http.ResponseWriter, hr *http.Request)

RESTPOSTJobs godoc

@Summary		Add a job
@Description	Add job with either a file using multipart/form-data or a URL using json.
@Tags			jobs
@Accept			json
@Accept			multipart/form-data
@Produce		json
@Param			addjoburl	body		AddJobURL	false	"Add job by URL"
@Param			file		formData	file		false	"this is a test file"
@Param			lang		query		string		false	"eng"
@Success		200			{object}	Job
@Failure		400			{object}	HTTPError
@Failure		404			{object}	HTTPError
@Failure		415			{object}	HTTPError
@Failure		500			{object}	HTTPError
@Router			/jobs [post]

func (*Rinse) RemoveJob

func (rns *Rinse) RemoveJob(job *Job)

func (*Rinse) UiAutoCleanup

func (rns *Rinse) UiAutoCleanup() jaws.HtmlGetter

func (*Rinse) UiClock

func (rns *Rinse) UiClock() jaws.HtmlGetter

func (*Rinse) UiMaxConcurrent

func (rns *Rinse) UiMaxConcurrent() jaws.HtmlGetter

func (*Rinse) UiMaxRuntime

func (rns *Rinse) UiMaxRuntime() jaws.HtmlGetter

func (*Rinse) UiMaxSize

func (rns *Rinse) UiMaxSize() jaws.HtmlGetter
func (rns *Rinse) UiNavLink(rq *http.Request, url, title string) template.HTML

Jump to

Keyboard shortcuts

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