From 38d77fdfbb68b332765eef03be0ce2fb78599b93 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Wed, 24 Jan 2018 05:29:13 +0700 Subject: [PATCH 1/7] Fix --- .gitignore | 1 + controllers/uploadController.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 13b9656..5c95e05 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ pages/custom/** migrate.js yarn.lock package-lock.json +.vscode/ diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 3fb9b55..9f10c8c 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -98,7 +98,7 @@ uploadsController.actuallyUpload = async (req, res, userid, album) => { hash: fileHash, ip: req.ip, albumid: album, - userid: userid.id, + userid: userid !== undefined ? userid.id : null, timestamp: Math.floor(Date.now() / 1000) }); } else { From 7de25210ce629fff1f731dd8a485ba0a3b8c30b6 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Wed, 24 Jan 2018 19:38:32 +0700 Subject: [PATCH 2/7] Proper undefined check --- controllers/uploadController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 9f10c8c..84fb40c 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -98,7 +98,7 @@ uploadsController.actuallyUpload = async (req, res, userid, album) => { hash: fileHash, ip: req.ip, albumid: album, - userid: userid !== undefined ? userid.id : null, + userid: typeof userid !== 'undefined' ? userid.id : null, timestamp: Math.floor(Date.now() / 1000) }); } else { From 5052cd26511f2e8f39844b180bf0e1df4141e473 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Wed, 24 Jan 2018 19:53:31 +0700 Subject: [PATCH 3/7] Sorry. At first I was concerned due to a particular ESLint rule called "no-undefined", but then after looking more deeply into it, I realized using typeof was unnecessary since "no-global-assign" and "no-shadow-restricted-names" were enabled and thus the previous method surely would not cause any problems. --- controllers/uploadController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 84fb40c..9f10c8c 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -98,7 +98,7 @@ uploadsController.actuallyUpload = async (req, res, userid, album) => { hash: fileHash, ip: req.ip, albumid: album, - userid: typeof userid !== 'undefined' ? userid.id : null, + userid: userid !== undefined ? userid.id : null, timestamp: Math.floor(Date.now() / 1000) }); } else { From 465607cd5b6e3cbce152a3df3df633904700a9b8 Mon Sep 17 00:00:00 2001 From: RyoshiKayo Date: Sat, 27 Jan 2018 06:16:21 +0100 Subject: [PATCH 4/7] Added HTTP NGINX sample config --- nginx.sample.conf | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/nginx.sample.conf b/nginx.sample.conf index c68f40f..98032f3 100644 --- a/nginx.sample.conf +++ b/nginx.sample.conf @@ -5,20 +5,9 @@ upstream backend { server { listen 80; listen [::]:80; - server_name lolisafe.moe; - return 301 https://$server_name$request_uri; -} - -server { - listen 443 ssl http2; - listen [::]:443 ssl http2; server_name lolisafe.moe; - ssl_certificate /path/to/your/fullchain.pem; - ssl_certificate_key /path/to/your/privkey.pem; - ssl_trusted_certificate /path/to/your/fullchain.pem; - client_max_body_size 100M; # Change this to the max file size you want to allow location / { From 9465cce88aadfabf715495bb3d6998ade45f700a Mon Sep 17 00:00:00 2001 From: RyoshiKayo Date: Sat, 27 Jan 2018 06:18:16 +0100 Subject: [PATCH 5/7] Renamed original NGINX config (SSL Version) --- nginx-ssl.sample.conf | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 nginx-ssl.sample.conf diff --git a/nginx-ssl.sample.conf b/nginx-ssl.sample.conf new file mode 100644 index 0000000..c68f40f --- /dev/null +++ b/nginx-ssl.sample.conf @@ -0,0 +1,43 @@ +upstream backend { + server 127.0.0.1:3000; # Change to the port you specified on lolisafe +} + +server { + listen 80; + listen [::]:80; + server_name lolisafe.moe; + return 301 https://$server_name$request_uri; +} + +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + + server_name lolisafe.moe; + + ssl_certificate /path/to/your/fullchain.pem; + ssl_certificate_key /path/to/your/privkey.pem; + ssl_trusted_certificate /path/to/your/fullchain.pem; + + client_max_body_size 100M; # Change this to the max file size you want to allow + + location / { + add_header Access-Control-Allow-Origin *; + root /path/to/your/uploads/folder; + try_files $uri @proxy; + } + + location @proxy { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-NginX-Proxy true; + proxy_pass http://backend; + proxy_redirect off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_redirect off; + proxy_set_header X-Forwarded-Proto $scheme; + } +} From 01f1c600ed56535e6c24f06f9fd88f81451c1878 Mon Sep 17 00:00:00 2001 From: RyoshiKayo Date: Sat, 27 Jan 2018 06:19:40 +0100 Subject: [PATCH 6/7] Matched ports from sample config --- nginx-ssl.sample.conf | 2 +- nginx.sample.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nginx-ssl.sample.conf b/nginx-ssl.sample.conf index c68f40f..2172564 100644 --- a/nginx-ssl.sample.conf +++ b/nginx-ssl.sample.conf @@ -1,5 +1,5 @@ upstream backend { - server 127.0.0.1:3000; # Change to the port you specified on lolisafe + server 127.0.0.1:9999; # Change to the port you specified on lolisafe } server { diff --git a/nginx.sample.conf b/nginx.sample.conf index 98032f3..71b8855 100644 --- a/nginx.sample.conf +++ b/nginx.sample.conf @@ -1,5 +1,5 @@ upstream backend { - server 127.0.0.1:3000; # Change to the port you specified on lolisafe + server 127.0.0.1:9999; # Change to the port you specified on lolisafe } server { From a9232b905cc9774952414f74017171b0545374b7 Mon Sep 17 00:00:00 2001 From: RyoshiKayo Date: Sat, 27 Jan 2018 06:24:21 +0100 Subject: [PATCH 7/7] Added NGINX SSL Version --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c43f2f..eae369f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,9 @@ downloads in. This also gives you the ability to serve them, for example, like t https://files.lolisafe.moe/yourFile.jpg Both cases require you to type the domain where the files will be served on the `domain` key below. -Which one you use is ultimately up to you. Either way, I've provided a [sample config file for nginx](https://github.com/WeebDev/lolisafe/blob/master/nginx.sample.conf) that you can use to set it up quickly and painlessly! +Which one you use is ultimately up to you. Either way, I've provided a sample config files for nginx that you can use to set it up quickly and painlessly! +- [Normal Version](https://github.com/WeebDev/lolisafe/blob/master/nginx.sample.conf) +- [SSL Version](https://github.com/WeebDev/lolisafe/blob/master/nginx-ssl.sample.conf) If you set `enableUserAccounts: true`, people will be able to create accounts on the service to keep track of their uploaded files and create albums to upload stuff to, pretty much like imgur does, but only through the API. Every user account has a token that the user can use to upload stuff through the API. You can find this token on the section called `Change your token` on the administration dashboard, and if it gets leaked or compromised you can renew it by clicking the button titled `Request new token`.