From 3fdccd49d584bce8bd362e5a2bb66338f7b5233f Mon Sep 17 00:00:00 2001 From: 3np <3np@3np> Date: Tue, 6 Apr 2021 00:58:25 +0900 Subject: [PATCH 1/3] Create upload directories if they don't exist --- app.js | 8 ++++++-- inc/commons.js | 2 +- inc/downloadAndSave.js | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index ff38ac1..e718983 100644 --- a/app.js +++ b/app.js @@ -7,7 +7,6 @@ global.ratelimit_counts = {} global.ratelimit_timestamps = {} const pug = require('pug') -const path = require('path') const compression = require('compression') const express = require('express') const cookieParser = require('cookie-parser') @@ -53,7 +52,12 @@ const fs = require('fs') const app = express() const request = require('postman-request') const commons = require('./inc/commons.js')(request, fs) -const dlAndSave = require('./inc/downloadAndSave.js')(commons) +const dlAndSave = require('./inc/downloadAndSave.js')(commons); + +['pics/thumbs', 'pics/flairs', 'pics/icons', 'vids'] + .map(d => `./static/${d}`) + .filter(d => !fs.existsSync(d)) + .forEach(d => fs.mkdirSync(d, { recursive: true })) if(!config.https_enabled && config.redirect_http_to_https) { console.error(`Cannot redirect HTTP=>HTTPS while "https_enabled" is false.`) diff --git a/inc/commons.js b/inc/commons.js index 85d9304..f6e3c28 100644 --- a/inc/commons.js +++ b/inc/commons.js @@ -20,7 +20,7 @@ module.exports = function(request, fs) { if(!error) { resolve({ success: true }) } else { - resolve({ success: false }) + resolve({ success: false, error }) } }) }).catch((err) => { diff --git a/inc/downloadAndSave.js b/inc/downloadAndSave.js index 3126933..0585216 100644 --- a/inc/downloadAndSave.js +++ b/inc/downloadAndSave.js @@ -89,7 +89,7 @@ module.exports = function(tools) { let temp_files = [temp_path, audio_path] deleteFiles(temp_files, (error) => { if(error) { - console.log(`Error while deleting temporay files:`, error) + console.log(`Error while deleting temporary files:`, error) } }) resolve(final_url) From f0b2204e72c2f89e9eed19a026de15ce39f1d950 Mon Sep 17 00:00:00 2001 From: 3np <3np@3np> Date: Tue, 6 Apr 2021 00:59:02 +0900 Subject: [PATCH 2/3] Set global write permissions on upload directories To play nicely with tmpfs mounts --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index b6fcb9b..85a7357 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,6 @@ COPY . /teddit/ RUN npm install --no-optional COPY config.js.template /teddit/config.js +RUN find /teddit/static/ -type d -exec chmod -R 777 {} \; + CMD npm start From 68c2a354e4f765aa9d40176136a881f9ffc7f632 Mon Sep 17 00:00:00 2001 From: 3np <3np@3np> Date: Wed, 7 Apr 2021 13:10:06 +0900 Subject: [PATCH 3/3] Use relative paths in Dockerfile --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 85a7357..028b14b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,10 +6,10 @@ RUN apk add ffmpeg # Install NPM dependencies and copy the project WORKDIR /teddit -COPY . /teddit/ +COPY . ./ RUN npm install --no-optional -COPY config.js.template /teddit/config.js +COPY config.js.template ./config.js -RUN find /teddit/static/ -type d -exec chmod -R 777 {} \; +RUN find ./static/ -type d -exec chmod -R 777 {} \; CMD npm start