mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Use different file stores based on config
This commit is contained in:
@ -18,9 +18,18 @@ import docspell.logging.{Level, LogConfig}
|
||||
import com.github.eikek.calev.CalEvent
|
||||
import pureconfig.ConfigReader
|
||||
import pureconfig.error.{CannotConvert, FailureReason}
|
||||
import pureconfig.generic.{CoproductHint, FieldCoproductHint}
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
object Implicits {
|
||||
// the value "s-3" looks strange, this is to allow to write "s3" in the config
|
||||
implicit val fileStoreCoproductHint: CoproductHint[FileStoreConfig] =
|
||||
new FieldCoproductHint[FileStoreConfig]("type") {
|
||||
override def fieldValue(name: String) =
|
||||
if (name.equalsIgnoreCase("S3")) "s3"
|
||||
else super.fieldValue(name)
|
||||
}
|
||||
|
||||
implicit val accountIdReader: ConfigReader[AccountId] =
|
||||
ConfigReader[String].emap(reason(AccountId.parse))
|
||||
|
||||
@ -42,6 +51,9 @@ object Implicits {
|
||||
implicit val identReader: ConfigReader[Ident] =
|
||||
ConfigReader[String].emap(reason(Ident.fromString))
|
||||
|
||||
implicit def identMapReader[B: ConfigReader]: ConfigReader[Map[Ident, B]] =
|
||||
pureconfig.configurable.genericMapReader[Ident, B](reason(Ident.fromString))
|
||||
|
||||
implicit val byteVectorReader: ConfigReader[ByteVector] =
|
||||
ConfigReader[String].emap(reason { str =>
|
||||
if (str.startsWith("hex:"))
|
||||
@ -70,6 +82,9 @@ object Implicits {
|
||||
implicit val logLevelReader: ConfigReader[Level] =
|
||||
ConfigReader[String].emap(reason(Level.fromString))
|
||||
|
||||
implicit val fileStoreTypeReader: ConfigReader[FileStoreType] =
|
||||
ConfigReader[String].emap(reason(FileStoreType.fromString))
|
||||
|
||||
def reason[A: ClassTag](
|
||||
f: String => Either[String, A]
|
||||
): String => Either[FailureReason, A] =
|
||||
|
Reference in New Issue
Block a user