From 800fc543f7a76396f0ba5d4465bd5561bbd391a0 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Fri, 18 Jun 2021 14:02:28 +0200 Subject: [PATCH 1/2] support dynamic max upload size on tus endpoint --- docker/nginx/conf.d/client.conf | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index 3c20dd13..1a6b2f7d 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -337,6 +337,23 @@ server { # proxy /skynet/tus requests to siad endpoint with all arguments proxy_pass http://siad; + # set max upload size dynamically based on account limits + rewrite_by_lua_block { + -- set default limit value to 1 GB + ngx.req.set_header("SkynetMaxUploadSize", 1073741824) + + -- this block runs only when accounts are enabled + if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then end + + -- fetch account limits and set max upload size accordingly + local res = ngx.location.capture("/accounts/user/limits", { copy_all_vars = true }) + if res.status == ngx.HTTP_OK then + local json = require('cjson') + local limits = json.decode(res.body) + ngx.req.set_header("SkynetMaxUploadSize", limits.maxUploadSize) + end + } + # extract skylink from base64 encoded upload metadata and assign to a proper header header_filter_by_lua_block { if ngx.header["Upload-Metadata"] then From cf64fd210702e00de5d7051468c4784095162b3f Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Fri, 18 Jun 2021 17:00:53 +0200 Subject: [PATCH 2/2] missed return --- docker/nginx/conf.d/client.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index 1a6b2f7d..7316f03b 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -343,7 +343,7 @@ server { ngx.req.set_header("SkynetMaxUploadSize", 1073741824) -- this block runs only when accounts are enabled - if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then end + if os.getenv("ACCOUNTS_ENABLED", "0") == "0" then return end -- fetch account limits and set max upload size accordingly local res = ngx.location.capture("/accounts/user/limits", { copy_all_vars = true })