diff options
author | Zach Smith <zach@driver.xyz> | 2017-04-27 11:55:16 -0700 |
---|---|---|
committer | Zach Smith <zach@driver.xyz> | 2017-05-04 10:34:33 -0700 |
commit | e9ea2ab850a5251369217b48fd99b65ef4b6985d (patch) | |
tree | ede2f324d0a4d875e19187ca789dc8105817aaf2 /src/main/scala/xyz/driver/core/file/package.scala | |
parent | d6695390a60aaaa907f0b8744ce5757fde30a9eb (diff) | |
download | driver-core-e9ea2ab850a5251369217b48fd99b65ef4b6985d.tar.gz driver-core-e9ea2ab850a5251369217b48fd99b65ef4b6985d.tar.bz2 driver-core-e9ea2ab850a5251369217b48fd99b65ef4b6985d.zip |
Split FileStorage implementations into separate files
Diffstat (limited to 'src/main/scala/xyz/driver/core/file/package.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/file/package.scala | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/core/file/package.scala b/src/main/scala/xyz/driver/core/file/package.scala new file mode 100644 index 0000000..8c06010 --- /dev/null +++ b/src/main/scala/xyz/driver/core/file/package.scala @@ -0,0 +1,51 @@ +package xyz.driver.core + +import java.io.File +import java.nio.file.Path + +import xyz.driver.core.time.Time + +import scala.concurrent.Future +import scalaz.{ListT, OptionT} + +package file { + final case class FileLink( + name: Name[File], + location: Path, + revision: Revision[File], + lastModificationDate: Time, + fileSize: Long + ) + + trait FileService { + + def getFileLink(id: Name[File]): FileLink + + def getFile(fileLink: FileLink): File + } + + trait FileStorage { + + def upload(localSource: File, destination: Path): Future[Unit] + + def download(filePath: Path): OptionT[Future, File] + + def delete(filePath: Path): Future[Unit] + + def list(path: Path): ListT[Future, FileLink] + + /** List of characters to avoid in S3 (I would say file names in general) + * + * @see http://stackoverflow.com/questions/7116450/what-are-valid-s3-key-names-that-can-be-accessed-via-the-s3-rest-api + */ + private val illegalChars = "\\^`><{}][#%~|&@:,$=+?; " + + protected def checkSafeFileName[T](filePath: Path)(f: => T): T = { + filePath.toString.find(c => illegalChars.contains(c)) match { + case Some(illegalCharacter) => + throw new IllegalArgumentException(s"File name cannot contain character `$illegalCharacter`") + case None => f + } + } + } +} |