mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Download multiple files as zip
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 cats.data.NonEmptyList
|
||||
|
||||
import io.circe.{Decoder, Encoder}
|
||||
|
||||
sealed trait DownloadAllType {
|
||||
def name: String
|
||||
}
|
||||
|
||||
object DownloadAllType {
|
||||
|
||||
case object Converted extends DownloadAllType { val name = "converted" }
|
||||
case object Original extends DownloadAllType { val name = "original" }
|
||||
|
||||
val all: NonEmptyList[DownloadAllType] =
|
||||
NonEmptyList.of(Converted, Original)
|
||||
|
||||
def fromString(str: String): Either[String, DownloadAllType] =
|
||||
all.find(_.name.equalsIgnoreCase(str)).toRight(s"Unknown type: $str")
|
||||
|
||||
def unsafeFromString(str: String): DownloadAllType =
|
||||
fromString(str).fold(sys.error, identity)
|
||||
|
||||
implicit val jsonEncoder: Encoder[DownloadAllType] =
|
||||
Encoder.encodeString.contramap(_.name)
|
||||
|
||||
implicit val jsonDecoder: Decoder[DownloadAllType] =
|
||||
Decoder.decodeString.emap(fromString)
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2020 Eike K. & Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.common
|
||||
|
||||
import cats.data.NonEmptyList
|
||||
|
||||
import io.circe.{Decoder, Encoder}
|
||||
|
||||
sealed trait DownloadState {
|
||||
def name: String
|
||||
}
|
||||
object DownloadState {
|
||||
case object Forbidden extends DownloadState { val name = "forbidden" }
|
||||
case object NotPresent extends DownloadState { val name = "notpresent" }
|
||||
case object Preparing extends DownloadState { val name = "preparing" }
|
||||
case object Present extends DownloadState { val name = "present" }
|
||||
case object Empty extends DownloadState { val name = "empty" }
|
||||
|
||||
val all: NonEmptyList[DownloadState] =
|
||||
NonEmptyList.of(Forbidden, NotPresent, Preparing, Present, Empty)
|
||||
|
||||
def fromString(str: String): Either[String, DownloadState] =
|
||||
all.find(_.name.equalsIgnoreCase(str)).toRight(s"Unknown download-state: $str")
|
||||
|
||||
def unsafeFromString(str: String): DownloadState =
|
||||
fromString(str).fold(sys.error, identity)
|
||||
|
||||
implicit val jsonEncoder: Encoder[DownloadState] =
|
||||
Encoder.encodeString.contramap(_.name)
|
||||
|
||||
implicit val jsonDecoder: Decoder[DownloadState] =
|
||||
Decoder.decodeString.emap(fromString)
|
||||
}
|
@ -31,9 +31,16 @@ object FileCategory {
|
||||
case object AttachmentConvert extends FileCategory
|
||||
case object PreviewImage extends FileCategory
|
||||
case object Classifier extends FileCategory
|
||||
case object DownloadAll extends FileCategory
|
||||
|
||||
val all: NonEmptyList[FileCategory] =
|
||||
NonEmptyList.of(AttachmentSource, AttachmentConvert, PreviewImage, Classifier)
|
||||
NonEmptyList.of(
|
||||
AttachmentSource,
|
||||
AttachmentConvert,
|
||||
PreviewImage,
|
||||
Classifier,
|
||||
DownloadAll
|
||||
)
|
||||
|
||||
def fromString(str: String): Either[String, FileCategory] =
|
||||
all.find(_.id.id == str).toRight(s"Unknown category: $str")
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
package docspell.common
|
||||
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.temporal.ChronoUnit
|
||||
import java.time.{Duration => _, _}
|
||||
|
||||
@ -47,6 +48,11 @@ case class Timestamp(value: Instant) {
|
||||
|
||||
def asString: String = value.toString
|
||||
|
||||
def forFilename: String =
|
||||
DateTimeFormatter
|
||||
.ofPattern("YYYY-MM-dd'T'HH-mm-ss")
|
||||
.format(value.atOffset(ZoneOffset.UTC))
|
||||
|
||||
def <(other: Timestamp): Boolean =
|
||||
this.value.isBefore(other.value)
|
||||
|
||||
|
Reference in New Issue
Block a user