~jan0sch/smederee

Showing details for patch 7e3a1b158547496fd335f2251ed87c751a13ab79.
2023-04-13 (Thu), 5:29 AM - Jens Grassel - 7e3a1b158547496fd335f2251ed87c751a13ab79

Refactoring: Move maximum file size for rendering to configuration.

- add `render-maximum-file-size` to `reference.conf` with 128 KB default
- add `renderMaximumFileSize` to `ServiceConfig`
- remove hard coded value from `VcsRepositoryRoutes`
- make some more values in `VcsRepositoryRoutes` private
Summary of changes
3 files modified with 11 lines added and 6 lines removed
  • modules/hub/src/main/resources/reference.conf with 2 added and 0 removed lines
  • modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala with 4 added and 5 removed lines
  • modules/hub/src/main/scala/de/smederee/hub/config/SmedereeHubConfig.scala with 5 added and 1 removed lines
diff -rN -u old-smederee/modules/hub/src/main/resources/reference.conf new-smederee/modules/hub/src/main/resources/reference.conf
--- old-smederee/modules/hub/src/main/resources/reference.conf	2025-01-31 05:08:48.236803853 +0000
+++ new-smederee/modules/hub/src/main/resources/reference.conf	2025-01-31 05:08:48.236803853 +0000
@@ -35,6 +35,8 @@
 	# If it does not exist then it should be created with sensible permissions.
 	csrf-key-file = /var/tmp/smederee/csrf-key.bin
 	csrf-key-file = ${?SMEDEREE_CSRF_KEY_FILE}
+	# The maximum allowed size of a file in bytes to be displayed / rendered via the web interface.
+	render-maximum-file-size = 131072
 
 	# Settings affecting how the service will communicate several information to
 	# the "outside world" e.g. if it runs behind a reverse proxy.
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/config/SmedereeHubConfig.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/config/SmedereeHubConfig.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/config/SmedereeHubConfig.scala	2025-01-31 05:08:48.236803853 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/config/SmedereeHubConfig.scala	2025-01-31 05:08:48.236803853 +0000
@@ -180,6 +180,8 @@
   * @param downloadDirectory
   *   A directory into which files are written that are supposed to be downloaded by users (e.g. distribution files of
   *   repositories).
+  * @param renderMaximumFileSize
+  *   The maximum allowed size of a file in bytes to be displayed / rendered via the web interface.
   * @param authentication
   *   The configuration of the authentication feature.
   * @param billing
@@ -201,6 +203,7 @@
     port: Port,
     csrfKeyFile: Path,
     downloadDirectory: DirectoryPath,
+    renderMaximumFileSize: Long,
     authentication: AuthenticationConfiguration,
     billing: BillingConfiguration,
     darcs: DarcsConfiguration,
@@ -234,11 +237,12 @@
     ConfigReader.forProduct4("host", "path", "port", "scheme")(ExternalUrlConfiguration.apply)
 
   given ConfigReader[ServiceConfig] =
-    ConfigReader.forProduct11(
+    ConfigReader.forProduct12(
       "host",
       "port",
       "csrf-key-file",
       "download-directory",
+      "render-maximum-file-size",
       "authentication",
       "billing",
       "darcs",
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-01-31 05:08:48.236803853 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-01-31 05:08:48.236803853 +0000
@@ -64,12 +64,11 @@
 ) extends Http4sDsl[F] {
   private val log = LoggerFactory.getLogger(getClass)
 
+  private val MaximumFileSize = configuration.renderMaximumFileSize
   private val createRepoPath  = uri"/repo/create"
-  private val MaximumFileSize = 131072L // TODO: Move to configuration directive.
-
-  val darcsConfig = configuration.darcs
-  val linkConfig  = configuration.external
-  val sshConfig   = configuration.ssh
+  private val darcsConfig     = configuration.darcs
+  private val linkConfig      = configuration.external
+  private val sshConfig       = configuration.ssh
 
   // The base URI for our site which that be passed into some templates which create links themselfes.
   private val baseUri = linkConfig.createFullUri(Uri())