mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Check file integrity
This commit is contained in:
@ -26,6 +26,14 @@ object BinnyUtils {
|
||||
def fileKeyToBinaryId(fk: FileKey): BinaryId =
|
||||
BinaryId(s"${fk.collective.id}/${fk.category.id.id}/${fk.id.id}")
|
||||
|
||||
def fileKeyPartToPrefix(fkp: FileKeyPart): Option[String] =
|
||||
fkp match {
|
||||
case FileKeyPart.Empty => None
|
||||
case FileKeyPart.Collective(cid) => Some(s"${cid.id}/%")
|
||||
case FileKeyPart.Category(cid, cat) => Some(s"${cid.id}/${cat.id.id}/%")
|
||||
case FileKeyPart.Key(key) => Some(fileKeyToBinaryId(key).id)
|
||||
}
|
||||
|
||||
def binaryIdToFileKey(bid: BinaryId): Either[String, FileKey] =
|
||||
bid.id.split('/').toList match {
|
||||
case cId :: catId :: fId :: Nil =>
|
||||
|
@ -8,8 +8,10 @@ package docspell.store.records
|
||||
|
||||
import cats.data.NonEmptyList
|
||||
import cats.implicits._
|
||||
import fs2.Stream
|
||||
|
||||
import docspell.common.{FileKey, _}
|
||||
import docspell.store.file.BinnyUtils
|
||||
import docspell.store.qb.DSL._
|
||||
import docspell.store.qb._
|
||||
|
||||
@ -44,6 +46,18 @@ object RFileMeta {
|
||||
def as(alias: String): Table =
|
||||
Table(Some(alias))
|
||||
|
||||
def findAll(part: FileKeyPart, chunkSize: Int): Stream[ConnectionIO, RFileMeta] = {
|
||||
val cond = BinnyUtils
|
||||
.fileKeyPartToPrefix(part)
|
||||
.map(prefix => T.id.cast[String].like(prefix))
|
||||
|
||||
Select(
|
||||
select(T.all),
|
||||
from(T),
|
||||
cond.getOrElse(Condition.unit)
|
||||
).build.query[RFileMeta].streamWithChunkSize(chunkSize)
|
||||
}
|
||||
|
||||
def insert(r: RFileMeta): ConnectionIO[Int] =
|
||||
DML.insert(T, T.all, fr"${r.id},${r.created},${r.mimetype},${r.length},${r.checksum}")
|
||||
|
||||
|
@ -68,7 +68,7 @@ object StoreFixture {
|
||||
ds <- dataSource(jdbc)
|
||||
xa <- makeXA(ds)
|
||||
cfg = FileRepositoryConfig.Database(64 * 1024)
|
||||
fr = FileRepository[IO](xa, ds, cfg)
|
||||
fr = FileRepository[IO](xa, ds, cfg, true)
|
||||
store = new StoreImpl[IO](fr, jdbc, ds, xa)
|
||||
_ <- Resource.eval(store.migrate)
|
||||
} yield store
|
||||
|
Reference in New Issue
Block a user