mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-11-03 18:00:11 +00:00 
			
		
		
		
	Merge pull request #1451 from eikek/fix-large-file-upload
Fix large file upload
This commit is contained in:
		@@ -38,6 +38,17 @@ docspell.server {
 | 
			
		||||
    port = 7880
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  # Options for tuning the http server
 | 
			
		||||
  server-options {
 | 
			
		||||
    enable-http-2 = false
 | 
			
		||||
 | 
			
		||||
    # Maximum allowed connections
 | 
			
		||||
    max-connections = 1024
 | 
			
		||||
 | 
			
		||||
    # Timeout for waiting for the first output of the response
 | 
			
		||||
    response-timeout = 45s
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  # This is a hard limit to restrict the size of a batch that is
 | 
			
		||||
  # returned when searching for items. The user can set this limit
 | 
			
		||||
  # within the client config, but it is restricted by the server to
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ import docspell.ftssolr.SolrConfig
 | 
			
		||||
import docspell.logging.LogConfig
 | 
			
		||||
import docspell.oidc.ProviderConfig
 | 
			
		||||
import docspell.pubsub.naive.PubSubConfig
 | 
			
		||||
import docspell.restserver.Config.OpenIdConfig
 | 
			
		||||
import docspell.restserver.Config.{OpenIdConfig, ServerOptions}
 | 
			
		||||
import docspell.restserver.auth.OpenId
 | 
			
		||||
import docspell.restserver.http4s.InternalHeader
 | 
			
		||||
 | 
			
		||||
@@ -26,6 +26,7 @@ case class Config(
 | 
			
		||||
    internalUrl: LenientUri,
 | 
			
		||||
    logging: LogConfig,
 | 
			
		||||
    bind: Config.Bind,
 | 
			
		||||
    serverOptions: ServerOptions,
 | 
			
		||||
    backend: BackendConfig,
 | 
			
		||||
    auth: Login.Config,
 | 
			
		||||
    showClassificationSettings: Boolean,
 | 
			
		||||
@@ -50,6 +51,11 @@ case class Config(
 | 
			
		||||
 | 
			
		||||
object Config {
 | 
			
		||||
 | 
			
		||||
  case class ServerOptions(
 | 
			
		||||
      responseTimeout: Duration,
 | 
			
		||||
      enableHttp2: Boolean,
 | 
			
		||||
      maxConnections: Int
 | 
			
		||||
  )
 | 
			
		||||
  case class Bind(address: String, port: Int)
 | 
			
		||||
 | 
			
		||||
  case class AdminEndpoint(secret: String)
 | 
			
		||||
 
 | 
			
		||||
@@ -52,6 +52,9 @@ object RestServer {
 | 
			
		||||
              BlazeServerBuilder[F]
 | 
			
		||||
                .bindHttp(cfg.bind.port, cfg.bind.address)
 | 
			
		||||
                .withoutBanner
 | 
			
		||||
                .withResponseHeaderTimeout(cfg.serverOptions.responseTimeout.toScala)
 | 
			
		||||
                .enableHttp2(cfg.serverOptions.enableHttp2)
 | 
			
		||||
                .withMaxConnections(cfg.serverOptions.maxConnections)
 | 
			
		||||
                .withHttpWebSocketApp(
 | 
			
		||||
                  createHttpApp(setting, pubSub, restApp)
 | 
			
		||||
                )
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,6 @@ import docspell.restserver.http4s.ResponseGenerator
 | 
			
		||||
import org.http4s._
 | 
			
		||||
import org.http4s.circe.CirceEntityEncoder._
 | 
			
		||||
import org.http4s.dsl.Http4sDsl
 | 
			
		||||
import org.http4s.multipart.Multipart
 | 
			
		||||
import org.log4s._
 | 
			
		||||
 | 
			
		||||
object UploadRoutes {
 | 
			
		||||
@@ -80,8 +79,16 @@ object UploadRoutes {
 | 
			
		||||
  ): F[Response[F]] = {
 | 
			
		||||
    import dsl._
 | 
			
		||||
 | 
			
		||||
    val decodeMultipart =
 | 
			
		||||
      EntityDecoder
 | 
			
		||||
        .mixedMultipartResource(
 | 
			
		||||
          maxSizeBeforeWrite = 10 * 1024 * 1024
 | 
			
		||||
        )
 | 
			
		||||
        .evalMap(_.decode(req, strict = false).value)
 | 
			
		||||
        .rethrow
 | 
			
		||||
 | 
			
		||||
    decodeMultipart.use { multipart =>
 | 
			
		||||
      for {
 | 
			
		||||
      multipart <- req.as[Multipart[F]]
 | 
			
		||||
        updata <- readMultipart(
 | 
			
		||||
          multipart,
 | 
			
		||||
          "webapp",
 | 
			
		||||
@@ -93,4 +100,5 @@ object UploadRoutes {
 | 
			
		||||
        res <- Ok(basicResult(result))
 | 
			
		||||
      } yield res
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,11 @@ let
 | 
			
		||||
      address = "localhost";
 | 
			
		||||
      port = 7880;
 | 
			
		||||
    };
 | 
			
		||||
    server-options = {
 | 
			
		||||
      enable-http-2 = false;
 | 
			
		||||
      max-connections = 1024;
 | 
			
		||||
      response-timeout = "45s";
 | 
			
		||||
    };
 | 
			
		||||
    logging = {
 | 
			
		||||
      minimum-level = "Info";
 | 
			
		||||
      format = "Fancy";
 | 
			
		||||
@@ -214,6 +219,30 @@ in {
 | 
			
		||||
        description = "Address and port bind the rest server.";
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      server-options = mkOption {
 | 
			
		||||
        type = types.submodule({
 | 
			
		||||
          options = {
 | 
			
		||||
            enable-http-2 = mkOption {
 | 
			
		||||
              type = types.bool;
 | 
			
		||||
              default = defaults.server-options.enable-http-2;
 | 
			
		||||
              description = "Whether to enable http2";
 | 
			
		||||
            };
 | 
			
		||||
            max-connections = mkOption {
 | 
			
		||||
              type = types.int;
 | 
			
		||||
              default = defaults.server-options.max-connections;
 | 
			
		||||
              description = "Maximum number of client connections";
 | 
			
		||||
            };
 | 
			
		||||
            response-timeout = mkOption {
 | 
			
		||||
              type = types.str;
 | 
			
		||||
              default = defaults.server-options.response-timeout;
 | 
			
		||||
              description = "Timeout when waiting for the response.";
 | 
			
		||||
            };
 | 
			
		||||
          };
 | 
			
		||||
        });
 | 
			
		||||
        default = defaults.server-options;
 | 
			
		||||
        description = "Tuning the http server";
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      logging = mkOption {
 | 
			
		||||
        type = types.submodule({
 | 
			
		||||
          options = {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user