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:
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2020 Eike K. & Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.common
|
||||
|
||||
import fs2.io.file.Path
|
||||
|
||||
sealed trait FileStoreConfig {
|
||||
def enabled: Boolean
|
||||
def storeType: FileStoreType
|
||||
}
|
||||
object FileStoreConfig {
|
||||
case class DefaultDatabase(enabled: Boolean) extends FileStoreConfig {
|
||||
val storeType = FileStoreType.DefaultDatabase
|
||||
}
|
||||
|
||||
case class FileSystem(
|
||||
enabled: Boolean,
|
||||
directory: Path
|
||||
) extends FileStoreConfig {
|
||||
val storeType = FileStoreType.FileSystem
|
||||
}
|
||||
|
||||
case class S3(
|
||||
enabled: Boolean,
|
||||
endpoint: String,
|
||||
accessKey: String,
|
||||
secretKey: String,
|
||||
bucket: String
|
||||
) extends FileStoreConfig {
|
||||
val storeType = FileStoreType.S3
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2020 Eike K. & Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.common
|
||||
|
||||
import cats.data.NonEmptyList
|
||||
|
||||
sealed trait FileStoreType { self: Product =>
|
||||
def name: String =
|
||||
productPrefix.toLowerCase
|
||||
}
|
||||
object FileStoreType {
|
||||
case object DefaultDatabase extends FileStoreType
|
||||
|
||||
case object S3 extends FileStoreType
|
||||
|
||||
case object FileSystem extends FileStoreType
|
||||
|
||||
val all: NonEmptyList[FileStoreType] =
|
||||
NonEmptyList.of(DefaultDatabase, S3, FileSystem)
|
||||
|
||||
def fromString(str: String): Either[String, FileStoreType] =
|
||||
all
|
||||
.find(_.name.equalsIgnoreCase(str))
|
||||
.toRight(s"Invalid file store type: $str")
|
||||
|
||||
def unsafeFromString(str: String): FileStoreType =
|
||||
fromString(str).fold(sys.error, identity)
|
||||
}
|
Reference in New Issue
Block a user