Refactoring for migrating to binny library

This commit is contained in:
eikek
2021-09-22 00:28:47 +02:00
parent 1f98d948b0
commit 20a829cf7a
45 changed files with 485 additions and 344 deletions

View File

@ -26,7 +26,6 @@ import docspell.store.queries.{AttachmentLight => QAttachmentLight}
import docspell.store.records._
import docspell.store.{AddResult, UpdateResult}
import bitpeace.FileMeta
import org.http4s.headers.`Content-Type`
import org.http4s.multipart.Multipart
import org.log4s.Logger
@ -140,17 +139,23 @@ trait Conversions {
def mkAttachment(
item: OItemSearch.ItemData
)(ra: RAttachment, m: FileMeta): Attachment = {
)(ra: RAttachment, m: RFileMeta): Attachment = {
val converted =
item.sources.find(_._1.id == ra.id).exists(_._2.checksum != m.checksum)
Attachment(ra.id, ra.name, m.length, MimeType.unsafe(m.mimetype.asString), converted)
Attachment(
ra.id,
ra.name,
m.length.bytes,
MimeType.unsafe(m.mimetype.asString),
converted
)
}
def mkAttachmentSource(ra: RAttachmentSource, m: FileMeta): AttachmentSource =
AttachmentSource(ra.id, ra.name, m.length, MimeType.unsafe(m.mimetype.asString))
def mkAttachmentSource(ra: RAttachmentSource, m: RFileMeta): AttachmentSource =
AttachmentSource(ra.id, ra.name, m.length.bytes, MimeType.unsafe(m.mimetype.asString))
def mkAttachmentArchive(ra: RAttachmentArchive, m: FileMeta): AttachmentSource =
AttachmentSource(ra.id, ra.name, m.length, MimeType.unsafe(m.mimetype.asString))
def mkAttachmentArchive(ra: RAttachmentArchive, m: RFileMeta): AttachmentSource =
AttachmentSource(ra.id, ra.name, m.length.bytes, MimeType.unsafe(m.mimetype.asString))
// item list

View File

@ -12,8 +12,8 @@ import cats.effect._
import cats.implicits._
import docspell.backend.ops._
import docspell.store.records.RFileMeta
import bitpeace.FileMeta
import org.http4s._
import org.http4s.circe.CirceEntityEncoder._
import org.http4s.dsl.Http4sDsl
@ -30,8 +30,8 @@ object BinaryUtil {
val mt = MediaType.unsafeParse(data.meta.mimetype.asString)
val ctype = `Content-Type`(mt)
val cntLen = `Content-Length`.unsafeFromLong(data.meta.length)
val eTag = ETag(data.meta.checksum)
val cntLen = `Content-Length`.unsafeFromLong(data.meta.length.bytes)
val eTag = ETag(data.meta.checksum.toHex)
val disp =
`Content-Disposition`(
"inline",
@ -48,16 +48,16 @@ object BinaryUtil {
dsl: Http4sDsl[F]
)(data: OItemSearch.BinaryData[F]): F[Response[F]] = {
import dsl._
withResponseHeaders(dsl, Ok(data.data.take(data.meta.length)))(data)
withResponseHeaders(dsl, Ok(data.data.take(data.meta.length.bytes)))(data)
}
def matchETag[F[_]](
fileData: Option[FileMeta],
fileData: Option[RFileMeta],
noneMatch: Option[NonEmptyList[EntityTag]]
): Boolean =
(fileData, noneMatch) match {
case (Some(meta), Some(nm)) =>
meta.checksum == nm.head.tag
meta.checksum.toHex == nm.head.tag
case _ =>
false
}