mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Send results from processing documents in the event
This commit is contained in:
@ -10,6 +10,9 @@ import docspell.common._
|
||||
import docspell.joex.process.ItemData.AttachmentDates
|
||||
import docspell.store.records.{RAttachment, RAttachmentMeta, RItem}
|
||||
|
||||
import io.circe.syntax.EncoderOps
|
||||
import io.circe.{Encoder, Json}
|
||||
|
||||
/** Data that is carried across all processing tasks.
|
||||
*
|
||||
* @param item
|
||||
@ -94,4 +97,28 @@ object ItemData {
|
||||
dates.map(dl => dl.label.copy(label = dl.date.toString))
|
||||
}
|
||||
|
||||
// Used to encode the result passed to the job-done event
|
||||
implicit val jsonEncoder: Encoder[ItemData] =
|
||||
Encoder.instance { data =>
|
||||
val metaMap = data.metas.groupMap(_.id)(identity)
|
||||
Json.obj(
|
||||
"id" -> data.item.id.asJson,
|
||||
"name" -> data.item.name.asJson,
|
||||
"collective" -> data.item.cid.asJson,
|
||||
"source" -> data.item.source.asJson,
|
||||
"attachments" -> data.attachments
|
||||
.map(a =>
|
||||
Json.obj(
|
||||
"id" -> a.id.asJson,
|
||||
"name" -> a.name.asJson,
|
||||
"content" -> metaMap.get(a.id).flatMap(_.head.content).asJson,
|
||||
"language" -> metaMap.get(a.id).flatMap(_.head.language).asJson,
|
||||
"pages" -> metaMap.get(a.id).flatMap(_.head.pages).asJson
|
||||
)
|
||||
)
|
||||
.asJson,
|
||||
"tags" -> data.tags.asJson,
|
||||
"assumedTags" -> data.classifyTags.asJson
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -40,18 +40,18 @@ object ItemHandler {
|
||||
fts: FtsClient[F],
|
||||
analyser: TextAnalyser[F],
|
||||
regexNer: RegexNerFile[F]
|
||||
): Task[F, Args, Unit] =
|
||||
): Task[F, Args, Option[ItemData]] =
|
||||
logBeginning.flatMap(_ =>
|
||||
DuplicateCheck[F]
|
||||
.flatMap(args =>
|
||||
if (args.files.isEmpty) logNoFiles
|
||||
if (args.files.isEmpty) logNoFiles.map(_ => None)
|
||||
else {
|
||||
val create: Task[F, Args, ItemData] =
|
||||
CreateItem[F].contramap(_ => args.pure[F])
|
||||
create
|
||||
.flatMap(itemStateTask(ItemState.Processing))
|
||||
.flatMap(safeProcess[F](cfg, itemOps, fts, analyser, regexNer))
|
||||
.map(_ => ())
|
||||
.map(_.some)
|
||||
}
|
||||
)
|
||||
)
|
||||
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Eike K. & Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.notification.api
|
||||
|
||||
import docspell.notification.api.Event._
|
||||
|
||||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
|
||||
import io.circe.{Decoder, Encoder}
|
||||
|
||||
trait EventCodec {
|
||||
|
||||
implicit val tagsChangedDecoder: Decoder[TagsChanged] = deriveDecoder
|
||||
implicit val tagsChangedEncoder: Encoder[TagsChanged] = deriveEncoder
|
||||
|
||||
implicit val eventDecoder: Decoder[Event] =
|
||||
deriveDecoder
|
||||
implicit val eventEncoder: Encoder[Event] =
|
||||
deriveEncoder
|
||||
}
|
Reference in New Issue
Block a user