Add a route to get the item preview

This is the first available preview of an attachment wrt position. If
all attachments have a preview image, the preview of the first
attachment is returned.
This commit is contained in:
Eike Kettner
2020-11-08 14:22:33 +01:00
parent 8cc89fd3b7
commit 757ad31165
5 changed files with 123 additions and 0 deletions

View File

@ -41,6 +41,8 @@ trait OItemSearch[F[_]] {
collective: Ident
): F[Option[AttachmentPreviewData[F]]]
def findItemPreview(item: 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]]
@ -188,6 +190,26 @@ object OItemSearch {
(None: Option[AttachmentPreviewData[F]]).pure[F]
})
def findItemPreview(
item: Ident,
collective: Ident
): F[Option[AttachmentPreviewData[F]]] =
store
.transact(RAttachmentPreview.findByItemAndCollective(item, 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