2021-08-27 12:15:22 +00:00
|
|
|
include /etc/nginx/conf.d/include/cors;
|
|
|
|
|
|
|
|
limit_conn downloads_by_ip 100; # ddos protection: max 100 downloads at a time
|
|
|
|
|
2021-11-05 11:57:06 +00:00
|
|
|
# ensure that skylink that we pass around is base64 encoded (transform base32 encoded ones)
|
|
|
|
# this is important because we want only one format in cache keys and logs
|
2022-03-10 08:55:24 +00:00
|
|
|
set_by_lua_block $skylink { return require("skynet.skylink").parse(ngx.var.skylink) }
|
2021-11-05 11:57:06 +00:00
|
|
|
|
2021-08-27 12:15:22 +00:00
|
|
|
# default download rate to unlimited
|
|
|
|
set $limit_rate 0;
|
|
|
|
|
|
|
|
access_by_lua_block {
|
2021-12-23 14:09:54 +00:00
|
|
|
if require("skynet.account").accounts_enabled() then
|
|
|
|
-- check if portal is in authenticated only mode
|
|
|
|
if require("skynet.account").is_access_unauthorized() then
|
|
|
|
return require("skynet.account").exit_access_unauthorized()
|
|
|
|
end
|
2021-08-27 12:15:22 +00:00
|
|
|
|
2022-01-21 16:43:30 +00:00
|
|
|
-- check if portal is in subscription only mode
|
|
|
|
if require("skynet.account").is_access_forbidden() then
|
|
|
|
return require("skynet.account").exit_access_forbidden()
|
|
|
|
end
|
|
|
|
|
2021-12-23 14:09:54 +00:00
|
|
|
-- get account limits of currently authenticated user
|
|
|
|
local limits = require("skynet.account").get_account_limits()
|
|
|
|
|
|
|
|
-- apply download speed limit
|
2021-08-27 12:15:22 +00:00
|
|
|
ngx.var.limit_rate = limits.download
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
limit_rate_after 512k;
|
|
|
|
limit_rate $limit_rate;
|
|
|
|
|
|
|
|
proxy_read_timeout 600;
|
|
|
|
proxy_set_header User-Agent: Sia-Agent;
|
|
|
|
|
2022-03-15 08:40:25 +00:00
|
|
|
proxy_pass http://sia:9980/skynet/skylink/$skylink$path$is_args$args;
|
2022-04-01 14:14:55 +00:00
|
|
|
|
|
|
|
log_by_lua_block {
|
|
|
|
local skynet_account = require("skynet.account")
|
|
|
|
local skynet_modules = require("skynet.modules")
|
|
|
|
local skynet_scanner = require("skynet.scanner")
|
|
|
|
local skynet_tracker = require("skynet.tracker")
|
|
|
|
|
|
|
|
if skynet_modules.is_enabled("a") then
|
|
|
|
skynet_tracker.track_download(ngx.header["Skynet-Skylink"], ngx.status, skynet_account.get_auth_headers(), ngx.var.body_bytes_sent)
|
|
|
|
end
|
|
|
|
|
|
|
|
if skynet_modules.is_enabled("s") then
|
|
|
|
skynet_scanner.scan_skylink(ngx.header["Skynet-Skylink"])
|
|
|
|
end
|
|
|
|
}
|