Skip to content

Commit

Permalink
Move download config options to the correct place
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek committed Mar 3, 2024
1 parent 5e6edc3 commit e16f87f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
10 changes: 6 additions & 4 deletions modules/restserver/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ case class Config(
baseUrl: LenientUri,
aliasMemberEnabled: Boolean,
bind: Config.Bind,
fileDownload: Config.FileDownload,
logging: LogConfig,
webapp: Config.Webapp,
backend: BackendConfig
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ 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(
`Content-Type`(mediaType(file)),
`Accept-Ranges`.bytes,
`Last-Modified`(timestamp(file)),
`Content-Disposition`("inline", fileNameMap(file)),
`Content-Length`(file.fileMeta.length.bytes),
fileSizeHeader(file.fileMeta.length)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit e16f87f

Please sign in to comment.