Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move env QR_CODE_MAX_UPLOAD_LENGTH to runtime #171

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
push:
branches:
- main
- 170-move-env-QR_CODE_MAX_UPLOAD_LENGTH-to-runtime
release:
types: [published]

Expand Down
4 changes: 0 additions & 4 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ config :qrstorage, QrstorageWeb.Endpoint,
layout: false
]

# This is what will be used for the calculation on the client side. We add a buffer to account for deltas
# and overhead in the endpoint configuration, so the server actually allows for a bit more:
config :qrstorage, max_upload_length: System.get_env("QR_CODE_MAX_UPLOAD_LENGTH", "2666666")

# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
Expand Down
4 changes: 4 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ config :qrstorage, Qrstorage.Repo,
]
]

# This is what will be used for the calculation on the client side. We add a buffer to account for deltas
# and overhead in the endpoint configuration, so the server actually allows for a bit more:
config :qrstorage, max_upload_length: System.get_env("QR_CODE_MAX_UPLOAD_LENGTH", "2666666")

# Set possible translations
default_locale =
case config_env() do
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ services:
target: development
tty: true
environment:
DATABASE_USER: ${POSTGRES_USER:-postgres}
DATABASE_USER_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
DATABASE_NAME: ${POSTGRES_DB:-qrstorage_dev}
DATABASE_USER: ${POSTGRES_USER:-qrstorage-user}
DATABASE_USER_PASSWORD: ${POSTGRES_PASSWORD:-qrstorage-password}
DATABASE_NAME: ${POSTGRES_DB:-qrstorage-dev}
DATABASE_PORT: 5432
DATABASE_HOST: postgres
DATABASE_SSL: "false"
Expand Down Expand Up @@ -80,9 +80,9 @@ services:
postgres:
image: postgres:15
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_DB: ${POSTGRES_DB:-qrstorage_dev}
POSTGRES_USER: ${POSTGRES_USER:-qrstorage-user}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-qrstorage-password}
POSTGRES_DB: ${POSTGRES_DB:-qrstorage-dev}
PGDATA: /var/lib/postgresql/data/pgdata
restart: always
# Exposing the port is not needed unless you want to access this database instance from the host.
Expand Down
8 changes: 1 addition & 7 deletions lib/qrstorage_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,10 @@ defmodule QrstorageWeb.Endpoint do
plug Plug.RequestId
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]

# account for deltas and overhead for the upload length. deltas are roughly the same size as the actual input,
# so * 2 for deltas, plus 0.2 buffer for overhead and text characters:
upload_length_buffer = 2.2
max_upload_length = String.to_integer(Application.compile_env(:qrstorage, :max_upload_length))

plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Phoenix.json_library(),
length: ceil(max_upload_length * upload_length_buffer)
json_decoder: Phoenix.json_library()

plug Plug.MethodOverride
plug Plug.Head
Expand Down