From e16f87f1857da9b75ddd2ffa05c78741ff99f5ad Mon Sep 17 00:00:00 2001 From: eikek Date: Sun, 3 Mar 2024 09:38:49 +0100 Subject: [PATCH 1/2] Move download config options to the correct place --- .../main/scala/sharry/backend/config/FilesConfig.scala | 4 +--- modules/restserver/src/main/resources/reference.conf | 10 ++++++---- .../main/scala/sharry/restserver/config/Config.scala | 5 +++++ .../scala/sharry/restserver/routes/ByteResponse.scala | 3 +-- .../sharry/restserver/routes/OpenShareRoutes.scala | 4 ++-- .../scala/sharry/restserver/routes/ShareRoutes.scala | 4 ++-- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/modules/backend/src/main/scala/sharry/backend/config/FilesConfig.scala b/modules/backend/src/main/scala/sharry/backend/config/FilesConfig.scala index 43860b0f..6d8ffd9f 100644 --- a/modules/backend/src/main/scala/sharry/backend/config/FilesConfig.scala +++ b/modules/backend/src/main/scala/sharry/backend/config/FilesConfig.scala @@ -3,15 +3,13 @@ package sharry.backend.config import cats.data.{Validated, ValidatedNec} import cats.syntax.all._ -import sharry.common.ByteSize import sharry.common.Ident import sharry.store.FileStoreConfig case class FilesConfig( defaultStore: Ident, stores: Map[Ident, FileStoreConfig], - copyFiles: CopyFilesConfig, - downloadChunkSize: ByteSize + copyFiles: CopyFilesConfig ) { val enabledStores: Map[Ident, FileStoreConfig] = diff --git a/modules/restserver/src/main/resources/reference.conf b/modules/restserver/src/main/resources/reference.conf index 740fc2b8..fe83db83 100644 --- a/modules/restserver/src/main/resources/reference.conf +++ b/modules/restserver/src/main/resources/reference.conf @@ -16,6 +16,12 @@ sharry.restserver { port = ${?SHARRY_BIND_PORT} } + file-download { + # For open range requests, use this amount of data when + # responding. + download-chunk-size = "4M" + } + # Configures logging logging { # The format for the log messages. Can be one of: @@ -358,10 +364,6 @@ sharry.restserver { # How many files to copy in parallel. parallel = 2 } - - # For open range requests, use this amount of data when - # responding. - download-chunk-size = "4M" } # Checksums of uploaded files are computed in the background. diff --git a/modules/restserver/src/main/scala/sharry/restserver/config/Config.scala b/modules/restserver/src/main/scala/sharry/restserver/config/Config.scala index 8b82eeb2..8a481627 100644 --- a/modules/restserver/src/main/scala/sharry/restserver/config/Config.scala +++ b/modules/restserver/src/main/scala/sharry/restserver/config/Config.scala @@ -13,6 +13,7 @@ case class Config( baseUrl: LenientUri, aliasMemberEnabled: Boolean, bind: Config.Bind, + fileDownload: Config.FileDownload, logging: LogConfig, webapp: Config.Webapp, backend: BackendConfig @@ -61,6 +62,10 @@ object Config { case class Bind(address: Host, port: Port) + case class FileDownload( + downloadChunkSize: ByteSize + ) + case class Webapp( appName: String, appIcon: String, diff --git a/modules/restserver/src/main/scala/sharry/restserver/routes/ByteResponse.scala b/modules/restserver/src/main/scala/sharry/restserver/routes/ByteResponse.scala index 6fbd9ab5..cd68a3cf 100644 --- a/modules/restserver/src/main/scala/sharry/restserver/routes/ByteResponse.scala +++ b/modules/restserver/src/main/scala/sharry/restserver/routes/ByteResponse.scala @@ -82,7 +82,7 @@ object ByteResponse { val isHead = req.method == Method.HEAD val data = if (!isHead) file.data else Stream.empty etagResponse(dsl, req, file).getOrElseF( - Ok(data) + Ok.apply(data) .map(setETag(file.fileMeta)) .map( _.putHeaders( @@ -90,7 +90,6 @@ object ByteResponse { `Accept-Ranges`.bytes, `Last-Modified`(timestamp(file)), `Content-Disposition`("inline", fileNameMap(file)), - `Content-Length`(file.fileMeta.length.bytes), fileSizeHeader(file.fileMeta.length) ) ) diff --git a/modules/restserver/src/main/scala/sharry/restserver/routes/OpenShareRoutes.scala b/modules/restserver/src/main/scala/sharry/restserver/routes/OpenShareRoutes.scala index 0cc8f788..d2e89442 100644 --- a/modules/restserver/src/main/scala/sharry/restserver/routes/OpenShareRoutes.scala +++ b/modules/restserver/src/main/scala/sharry/restserver/routes/OpenShareRoutes.scala @@ -24,12 +24,12 @@ object OpenShareRoutes { case req @ GET -> Root / Ident(id) / "file" / Ident(fid) => val pw = SharryPassword(req) - val chunkSize = cfg.backend.files.downloadChunkSize + val chunkSize = cfg.fileDownload.downloadChunkSize ByteResponse(dsl, req, backend, ShareId.publish(id), pw, chunkSize, fid) case req @ HEAD -> Root / Ident(id) / "file" / Ident(fid) => val pw = SharryPassword(req) - val chunkSize = cfg.backend.files.downloadChunkSize + val chunkSize = cfg.fileDownload.downloadChunkSize ByteResponse(dsl, req, backend, ShareId.publish(id), pw, chunkSize, fid) } } diff --git a/modules/restserver/src/main/scala/sharry/restserver/routes/ShareRoutes.scala b/modules/restserver/src/main/scala/sharry/restserver/routes/ShareRoutes.scala index 4c7bea8a..77769344 100644 --- a/modules/restserver/src/main/scala/sharry/restserver/routes/ShareRoutes.scala +++ b/modules/restserver/src/main/scala/sharry/restserver/routes/ShareRoutes.scala @@ -71,7 +71,7 @@ object ShareRoutes { case req @ GET -> Root / Ident(id) / "file" / Ident(fid) => val pw = SharryPassword(req) - val chunkSize = cfg.backend.files.downloadChunkSize + val chunkSize = cfg.fileDownload.downloadChunkSize ByteResponse( dsl, req, @@ -84,7 +84,7 @@ object ShareRoutes { case req @ HEAD -> Root / Ident(id) / "file" / Ident(fid) => val pw = SharryPassword(req) - val chunkSize = cfg.backend.files.downloadChunkSize + val chunkSize = cfg.fileDownload.downloadChunkSize ByteResponse( dsl, req, From 5198feec16d6ce5c6238b6d5f70db01a77f684db Mon Sep 17 00:00:00 2001 From: eikek Date: Sun, 3 Mar 2024 09:40:49 +0100 Subject: [PATCH 2/2] Remove obsolete travis link from README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index e866b776..cdf28b1d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ height="120px" style="padding-right: 20px"> -[![Build Status](https://travis-ci.org/eikek/sharry.svg?branch=master)](https://travis-ci.org/eikek/sharry) [![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org) # Sharry