Provide endpoints to submit tasks to re-generate previews

The scaling factor can be given in the config file. When this changes,
images can be regenerated via POSTing to certain endpoints. It is
possible to regenerate just one attachment preview or all within a
collective.
This commit is contained in:
Eike Kettner
2020-11-09 01:18:48 +01:00
parent 6037b54959
commit f4e50c5229
20 changed files with 218 additions and 38 deletions

View File

@ -1,5 +1,6 @@
package docspell.extract
import docspell.extract.ocr.OcrConfig
import docspell.extract.pdfbox.PreviewConfig
case class ExtractConfig(ocr: OcrConfig, pdf: PdfConfig)
case class ExtractConfig(ocr: OcrConfig, pdf: PdfConfig, preview: PreviewConfig)

View File

@ -21,11 +21,13 @@ trait PdfboxPreview[F[_]] {
object PdfboxPreview {
def apply[F[_]: Sync](dpi: Float): F[PdfboxPreview[F]] =
def apply[F[_]: Sync](cfg: PreviewConfig): F[PdfboxPreview[F]] =
Sync[F].pure(new PdfboxPreview[F] {
def previewImage(pdf: Stream[F, Byte]): F[Option[BufferedImage]] =
PdfLoader.withDocumentStream(pdf)(doc => Sync[F].delay(getPageImage(doc, 0, dpi)))
PdfLoader.withDocumentStream(pdf)(doc =>
Sync[F].delay(getPageImage(doc, 0, cfg.dpi))
)
def previewPNG(pdf: Stream[F, Byte]): F[Option[Stream[F, Byte]]] =
previewImage(pdf).map(_.map(pngStream[F]))

View File

@ -0,0 +1,3 @@
package docspell.extract.pdfbox
case class PreviewConfig(dpi: Float)

View File

@ -21,7 +21,7 @@ object PdfboxPreviewTest extends SimpleTestSuite {
val data = file.readURL[IO](8192, blocker)
val sha256out =
Stream
.eval(PdfboxPreview[IO](48))
.eval(PdfboxPreview[IO](PreviewConfig(48)))
.evalMap(_.previewPNG(data))
.flatMap(_.get)
.through(fs2.hash.sha256)