Merge pull request #892 from SkynetLabs/tus-max-upload-size

support dynamic max upload size on tus endpoint
This commit is contained in:
Karol Wypchło 2021-06-23 11:10:46 +02:00 committed by GitHub
commit 4885069ef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -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 return 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