uploaded files are stored in random nested directories

This commit is contained in:
Karol Wypchlo 2020-04-28 17:15:40 +02:00 committed by Karol Wypchło
parent e1cd5a0ef4
commit d875ae2367
1 changed files with 14 additions and 6 deletions

View File

@ -20,10 +20,6 @@ server {
client_body_timeout 5s; client_body_timeout 5s;
client_header_timeout 5s; client_header_timeout 5s;
# Auto generate a uuid for each file. This means users are able to upload
# Skyfiles without having to provide a uuid
rewrite ^/skynet/skyfile/?$ /skynet/skyfile/$request_id$1;
# NOTE: make sure to enable any additional configuration you might need like gzip # NOTE: make sure to enable any additional configuration you might need like gzip
location / { location / {
@ -56,11 +52,23 @@ server {
proxy_pass http://127.0.0.1:9980/skynet/stats; proxy_pass http://127.0.0.1:9980/skynet/stats;
} }
location /skynet/skyfile/ { location /skynet/skyfile {
limit_conn uploads_by_ip 10; # ddos protection: max 10 uploads at a time limit_conn uploads_by_ip 10; # ddos protection: max 10 uploads at a time
client_max_body_size 1000M; # make sure to limit the size of upload to a sane value client_max_body_size 1000M; # make sure to limit the size of upload to a sane value
proxy_read_timeout 600; proxy_read_timeout 600;
# Extract 3 sets of 2 characters from $request_id and assign to $dir1, $dir2, $dir3
# respectfully. The rest of the $request_id is going to be assigned to $dir4.
# We use those variables to automaticallygenerate unique path for uploaded file, yet
# we want to limit the number of folders on one directory level so we create nested path.
# Example path result: /af/24/9b/c5ec894920ccc45634dc9a8065
if ($request_id ~* "(\w{2})(\w{2})(\w{2})(\w+)") {
set $dir1 $1;
set $dir2 $2;
set $dir3 $3;
set $dir4 $4;
}
# proxy this call to siad endpoint (make sure the ip is correct) # proxy this call to siad endpoint (make sure the ip is correct)
# #
# note that we point uploads to port '9970', do this when you want to # note that we point uploads to port '9970', do this when you want to
@ -70,7 +78,7 @@ server {
# siad setup, make sure only the download portal runs in 'portal mode'. # siad setup, make sure only the download portal runs in 'portal mode'.
# The upload siad can be run in normal mode. Set the port to '9980' if # The upload siad can be run in normal mode. Set the port to '9980' if
# you do not want to run your portal in the double siad setup. # you do not want to run your portal in the double siad setup.
proxy_pass http://127.0.0.1:9970; proxy_pass http://127.0.0.1:9970/skynet/skyfile/$dir1/$dir2/$dir3/$dir4;
proxy_set_header Expect $http_expect; proxy_set_header Expect $http_expect;
add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Origin *;