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/6] 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/6] 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/6] 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 From 7b83daef552c8f2e598b75802d18ba1674c447eb Mon Sep 17 00:00:00 2001 From: 3np <3np@3np> Date: Wed, 7 Apr 2021 13:30:25 +0900 Subject: [PATCH 4/6] Rewrite domains of embedded/youtube media --- inc/processPostMedia.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/inc/processPostMedia.js b/inc/processPostMedia.js index caea4fc..1e962d3 100644 --- a/inc/processPostMedia.js +++ b/inc/processPostMedia.js @@ -24,7 +24,7 @@ module.exports = function() { width: post_media.oembed.thumbnail_width, thumbnail: await downloadAndSave(post_media.oembed.thumbnail_url, '', false, true), author_name: post_media.oembed.author_name, - author_url: post_media.oembed.author_url, + author_url: replaceDomains(post_media.oembed.author_url), title: post_media.oembed.title, duration: null, is_gif: null, @@ -37,9 +37,8 @@ module.exports = function() { let r = /iframe.*?src=\"(.*?)\"/; let src = r.exec(str)[1] let youtube_id = src.split('/embed/')[1].split('?')[0] - // TODO: Invidious youtube URLs. let youtube_url = `https://youtube.com/watch?v=${youtube_id}` - obj.media.embed_src = youtube_url + obj.media.embed_src = replaceDomains(youtube_url) } catch(error) { console.error(`Error while trying to get src link from embed youtube html.`, error) } @@ -67,7 +66,7 @@ module.exports = function() { source: 'external', height: post_media.oembed.height, width: post_media.oembed.width, - provider_url: post_media.oembed.provider_url, + provider_url: replaceDomains(post_media.oembed.provider_url), provider_name: post_media.oembed.provider_name, title: post_media.oembed.title, duration: null, @@ -79,12 +78,12 @@ module.exports = function() { let str = post_media.oembed.html let r = /iframe.*?src=\"(.*?)\"/; let src = r.exec(str)[1] - obj.media.embed_src = cleanUrl(src) + obj.media.embed_src = replaceDomains(cleanUrl(src)) } catch(error) { //console.error(`Error while trying to get src link from embed html.`, error) } if(!obj.media.embed_src) { - obj.media.embed_src = post_media.oembed.url + obj.media.embed_src = replaceDomains(post_media.oembed.url) } } } From 769205d4d75f8a60b532df23830aa6da47071431 Mon Sep 17 00:00:00 2001 From: teddit Date: Thu, 8 Apr 2021 17:04:50 +0200 Subject: [PATCH 5/6] we need user_preferences for the 2nd argument for replaceDomains() to work properly #187 --- inc/processJsonPost.js | 4 ++-- inc/processPostMedia.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/inc/processJsonPost.js b/inc/processJsonPost.js index 170c291..e621c0c 100644 --- a/inc/processJsonPost.js +++ b/inc/processJsonPost.js @@ -76,13 +76,13 @@ module.exports = function(fetch) { } } - obj = await processPostMedia(obj, post, post.media, has_gif, reddit_video, gif_to_mp4) + obj = await processPostMedia(obj, post, post.media, has_gif, reddit_video, gif_to_mp4, user_preferences) if(post.crosspost_parent_list) { post.crosspost = post.crosspost_parent_list[0] } if(post.crosspost) { - obj = await processPostMedia(obj, post.crosspost, post.crosspost.media, has_gif, reddit_video, gif_to_mp4) + obj = await processPostMedia(obj, post.crosspost, post.crosspost.media, has_gif, reddit_video, gif_to_mp4, user_preferences) obj.crosspost = { author: post.crosspost.author, created: post.crosspost.created_utc, diff --git a/inc/processPostMedia.js b/inc/processPostMedia.js index 1e962d3..da1b83a 100644 --- a/inc/processPostMedia.js +++ b/inc/processPostMedia.js @@ -1,6 +1,6 @@ module.exports = function() { const config = require('../config') - this.processPostMedia = (obj, post, post_media, has_gif, reddit_video, gif_to_mp4) => { + this.processPostMedia = (obj, post, post_media, has_gif, reddit_video, gif_to_mp4, user_preferences) => { return new Promise(resolve => { (async () => { if(post_media || has_gif) { @@ -24,7 +24,7 @@ module.exports = function() { width: post_media.oembed.thumbnail_width, thumbnail: await downloadAndSave(post_media.oembed.thumbnail_url, '', false, true), author_name: post_media.oembed.author_name, - author_url: replaceDomains(post_media.oembed.author_url), + author_url: replaceDomains(post_media.oembed.author_url, user_preferences), title: post_media.oembed.title, duration: null, is_gif: null, @@ -38,7 +38,7 @@ module.exports = function() { let src = r.exec(str)[1] let youtube_id = src.split('/embed/')[1].split('?')[0] let youtube_url = `https://youtube.com/watch?v=${youtube_id}` - obj.media.embed_src = replaceDomains(youtube_url) + obj.media.embed_src = replaceDomains(youtube_url, user_preferences) } catch(error) { console.error(`Error while trying to get src link from embed youtube html.`, error) } @@ -66,7 +66,7 @@ module.exports = function() { source: 'external', height: post_media.oembed.height, width: post_media.oembed.width, - provider_url: replaceDomains(post_media.oembed.provider_url), + provider_url: replaceDomains(post_media.oembed.provider_url, user_preferences), provider_name: post_media.oembed.provider_name, title: post_media.oembed.title, duration: null, @@ -78,12 +78,12 @@ module.exports = function() { let str = post_media.oembed.html let r = /iframe.*?src=\"(.*?)\"/; let src = r.exec(str)[1] - obj.media.embed_src = replaceDomains(cleanUrl(src)) + obj.media.embed_src = replaceDomains(cleanUrl(src), user_preferences) } catch(error) { //console.error(`Error while trying to get src link from embed html.`, error) } if(!obj.media.embed_src) { - obj.media.embed_src = replaceDomains(post_media.oembed.url) + obj.media.embed_src = replaceDomains(post_media.oembed.url, user_preferences) } } } From 006ac93de57b952ff4dbfb71fa9c2a31b43ade24 Mon Sep 17 00:00:00 2001 From: teddit Date: Thu, 8 Apr 2021 17:06:42 +0200 Subject: [PATCH 6/6] up version --- package.json | 2 +- views/about.pug | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 730c01d..c56547f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "teddit", - "version": "0.2.2", + "version": "0.3.1", "description": "A free and open source alternative Reddit front-end focused on privacy.", "homepage": "https://teddit.net", "bugs": { diff --git a/views/about.pug b/views/about.pug index b769af2..eba33b1 100644 --- a/views/about.pug +++ b/views/about.pug @@ -21,5 +21,5 @@ html .bottom a(href="https://en.wikipedia.org/wiki/Piratbyr%C3%A5n#Kopimi", target="_blank") img(src="kopimi.gif") - p.version v.0.2.2 + p.version v.0.3.1 include includes/footer.pug