mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Add simple route to get the preview image
This commit is contained in:
@ -36,6 +36,11 @@ trait OItemSearch[F[_]] {
|
||||
collective: Ident
|
||||
): F[Option[AttachmentArchiveData[F]]]
|
||||
|
||||
def findAttachmentPreview(
|
||||
id: Ident,
|
||||
collective: Ident
|
||||
): F[Option[AttachmentPreviewData[F]]]
|
||||
|
||||
def findAttachmentMeta(id: Ident, collective: Ident): F[Option[RAttachmentMeta]]
|
||||
|
||||
def findByFileCollective(checksum: String, collective: Ident): F[Vector[RItem]]
|
||||
@ -82,6 +87,15 @@ object OItemSearch {
|
||||
val fileId = rs.fileId
|
||||
}
|
||||
|
||||
case class AttachmentPreviewData[F[_]](
|
||||
rs: RAttachmentPreview,
|
||||
meta: FileMeta,
|
||||
data: Stream[F, Byte]
|
||||
) extends BinaryData[F] {
|
||||
val name = rs.name
|
||||
val fileId = rs.fileId
|
||||
}
|
||||
|
||||
case class AttachmentArchiveData[F[_]](
|
||||
rs: RAttachmentArchive,
|
||||
meta: FileMeta,
|
||||
@ -154,6 +168,26 @@ object OItemSearch {
|
||||
(None: Option[AttachmentSourceData[F]]).pure[F]
|
||||
})
|
||||
|
||||
def findAttachmentPreview(
|
||||
id: Ident,
|
||||
collective: Ident
|
||||
): F[Option[AttachmentPreviewData[F]]] =
|
||||
store
|
||||
.transact(RAttachmentPreview.findByIdAndCollective(id, collective))
|
||||
.flatMap({
|
||||
case Some(ra) =>
|
||||
makeBinaryData(ra.fileId) { m =>
|
||||
AttachmentPreviewData[F](
|
||||
ra,
|
||||
m,
|
||||
store.bitpeace.fetchData2(RangeDef.all)(Stream.emit(m))
|
||||
)
|
||||
}
|
||||
|
||||
case None =>
|
||||
(None: Option[AttachmentPreviewData[F]]).pure[F]
|
||||
})
|
||||
|
||||
def findAttachmentArchive(
|
||||
id: Ident,
|
||||
collective: Ident
|
||||
|
Reference in New Issue
Block a user