From aae8495b137ffb3a7fc14c4d8364c71d2340d729 Mon Sep 17 00:00:00 2001 From: teddit Date: Wed, 10 Feb 2021 18:15:29 +0100 Subject: [PATCH 1/6] remove mail due to spam --- views/about.pug | 2 -- 1 file changed, 2 deletions(-) diff --git a/views/about.pug b/views/about.pug index 1bf9c17..76b4c9e 100644 --- a/views/about.pug +++ b/views/about.pug @@ -19,8 +19,6 @@ html h2 Donating p(class="word-break") XMR: 832ogRwuoSs2JGYg7wJTqshidK7dErgNdfpenQ9dzMghNXQTJRby1xGbqC3gW3GAifRM9E84J91VdMZRjoSJ32nkAZnaCEj p BTC: bc1qlcrmt2pvlh4eq69l3l4h6z5jg74z2m2q3pasan - h2 Contact - p orenom(at)tutanota.com .bottom a(href="https://en.wikipedia.org/wiki/Piratbyr%C3%A5n#Kopimi", target="_blank") img(src="kopimi.gif") From aeeeaa76b7a9089f8ff2e1271b0541c4c22e2ffe Mon Sep 17 00:00:00 2001 From: teddit Date: Sat, 13 Feb 2021 13:29:47 +0100 Subject: [PATCH 2/6] feature for ex-/including saved posts when exporting preferences --- routes.js | 10 +++++++++- views/preferences.pug | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/routes.js b/routes.js index 8f87f39..0e8acf0 100644 --- a/routes.js +++ b/routes.js @@ -55,7 +55,7 @@ module.exports = (app, redis, fetch, RedditAPI) => { } if(!subbed_subreddits_is_set) res.clearCookie('subbed_subreddits') - return res.redirect('/preferences') + return res.redirect('/') } catch(e) { console.error(`Error setting imported preferences to the cookies. Key: ${key}.`, error) } @@ -1456,6 +1456,14 @@ module.exports = (app, redis, fetch, RedditAPI) => { }) app.post('/export_prefs', (req, res, next) => { + let export_saved = req.body.export_saved + let export_data = req.cookies + + if(export_saved !== 'on') { + if(req.cookies.saved) + delete export_data.saved + } + let r = `${(Math.random().toString(36)+'00000000000000000').slice(2, 10+2).toUpperCase()}` let key = `prefs_key:${r}` redis.set(key, JSON.stringify(req.cookies), (error) => { diff --git a/views/preferences.pug b/views/preferences.pug index 1ec6fe2..fb01e4c 100644 --- a/views/preferences.pug +++ b/views/preferences.pug @@ -75,6 +75,9 @@ html .setting small By exporting your preferences you can transfer your subscribed subreddits and preferences to another device. Or you could create a bookmark if you tend to delete your cookies frequently. br + label(for="export_saved") Export saved posts: + input(type="checkbox", name="export_saved", id="export_saved") + br input(type="submit", value="Export preferences") if preferences_key - var protocol = 'http' @@ -89,5 +92,8 @@ html .setting small By exporting your preferences you can transfer your subscribed subreddits and preferences to another device. Or you could create a bookmark if you tend to delete your cookies frequently. br + label(for="export_saved") Export saved posts: + input(type="checkbox", name="export_saved", id="export_saved") + br input(type="submit", value="Export preferences") include includes/footer.pug From 75fde2985594dd62837f70c95a79214de18a37e5 Mon Sep 17 00:00:00 2001 From: teddit Date: Sun, 14 Feb 2021 19:07:36 +0100 Subject: [PATCH 3/6] fix spoiler text not always showing when focused --- static/css/styles.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/static/css/styles.css b/static/css/styles.css index c87b48f..7884c31 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -1466,6 +1466,11 @@ code { background: #fff0; transition: none; } +.md .md-spoiler-text:not(.revealed):active p, +.md .md-spoiler-text:not(.revealed):focus p, +.md .md-spoiler-text:not(.revealed):hover p { + opacity: 1; +} @media only screen and (max-width: 768px) { #user .info { float: right; From c64581d6a80cb54cdcec0814b5a0a1ac46d7ff29 Mon Sep 17 00:00:00 2001 From: teddit Date: Sun, 14 Feb 2021 19:10:57 +0100 Subject: [PATCH 4/6] Revert "fix spoiler text not always showing when focused" This reverts commit 75fde2985594dd62837f70c95a79214de18a37e5. --- static/css/styles.css | 5 ----- 1 file changed, 5 deletions(-) diff --git a/static/css/styles.css b/static/css/styles.css index 7884c31..c87b48f 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -1466,11 +1466,6 @@ code { background: #fff0; transition: none; } -.md .md-spoiler-text:not(.revealed):active p, -.md .md-spoiler-text:not(.revealed):focus p, -.md .md-spoiler-text:not(.revealed):hover p { - opacity: 1; -} @media only screen and (max-width: 768px) { #user .info { float: right; From 420df6bd4556e16851b81ec7d0fa1cbbe0253c76 Mon Sep 17 00:00:00 2001 From: teddit Date: Sun, 14 Feb 2021 19:12:02 +0100 Subject: [PATCH 5/6] fix spoiler text not always showing when focused --- static/css/styles.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/static/css/styles.css b/static/css/styles.css index c87b48f..1292747 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -1466,6 +1466,11 @@ code { background: #fff0; transition: none; } +.md .md-spoiler-text:not(.revealed):active *, +.md .md-spoiler-text:not(.revealed):focus *, +.md .md-spoiler-text:not(.revealed):hover * { + opacity: 1; +} @media only screen and (max-width: 768px) { #user .info { float: right; From 12a4de42cf81b2772333d10ccd11bd5f199b9e71 Mon Sep 17 00:00:00 2001 From: teddit Date: Fri, 19 Feb 2021 20:29:39 +0100 Subject: [PATCH 6/6] add gfycat.com support (fixes #15) --- config.js.template | 3 ++- inc/downloadAndSave.js | 6 +++++- inc/processJsonPost.js | 9 +++++++-- inc/processPostMedia.js | 21 +++++---------------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/config.js.template b/config.js.template index f54006c..a9c81c8 100644 --- a/config.js.template +++ b/config.js.template @@ -38,7 +38,7 @@ const config = { searches: 600, sidebar: 60 * 60 * 24 * 7, // 7 days shorts: 60 * 60 * 24 * 31, - wikis: 60* 60 * 24 * 7, + wikis: 60 * 60 * 24 * 7, subreddits_explore: { front: 60 * 60 * 24 * 1, new_page: 60 @@ -51,6 +51,7 @@ const config = { reddit: true, // old.reddit.com and reddit.com --> instance domain (config.domain) }, valid_media_domains: ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'emoji.redditmedia.com', 'thumbs.gfycat.com', 'i.ytimg.com'], + valid_embed_video_domains: ['gfycat.com', 'youtube.com'], reddit_api_error_text: `Seems like your instance is either blocked (e.g. due to API rate limiting), reddit is currently down, or your API key is expired and not renewd properly. This can also happen for other reasons.` }; diff --git a/inc/downloadAndSave.js b/inc/downloadAndSave.js index 0582d8e..2afaaab 100644 --- a/inc/downloadAndSave.js +++ b/inc/downloadAndSave.js @@ -35,7 +35,8 @@ module.exports = function(tools) { if (file_prefix === 'flair_') { // Flair emojis end in the name without a file extension file_ext = 'png' - } else if(!pathname.includes('.')) { /** + } else if(!pathname.includes('.')) { + /** * Sometimes reddit API returns video without extension, like * "DASH_480" and not "DASH_480.mp4". */ @@ -57,6 +58,9 @@ module.exports = function(tools) { resolve('') } else { let filename = `${temp_url.pathname.substr(1).split('/')[0]}.${file_ext}` + if(temp_url.hostname === 'thumbs.gfycat.com') + filename = `${temp_url.pathname.substr(1).split('/')[0]}` + let path = `./static/vids/${dir}${filename}` let temp_path = `./static/vids/${dir}temp_${filename}` if(!fs.existsSync(path)) { diff --git a/inc/processJsonPost.js b/inc/processJsonPost.js index b0524e7..9906181 100644 --- a/inc/processJsonPost.js +++ b/inc/processJsonPost.js @@ -39,12 +39,17 @@ module.exports = function(fetch) { user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(post) : '') } - let validEmbedDomains = ['gfycat.com', 'youtube.com'] + let valid_embed_video_domains = ['gfycat.com'] let has_gif = false let gif_to_mp4 = null let reddit_video = null + let embed_video = false + + if(post.media) + if(valid_embed_video_domains.includes(post.media.type)) + embed_video = true - if(post.preview) { + if(post.preview && !embed_video) { if(post.preview.reddit_video_preview) { if(post.preview.reddit_video_preview.is_gif) { has_gif = true diff --git a/inc/processPostMedia.js b/inc/processPostMedia.js index cbda0e2..caea4fc 100644 --- a/inc/processPostMedia.js +++ b/inc/processPostMedia.js @@ -3,28 +3,17 @@ module.exports = function() { this.processPostMedia = (obj, post, post_media, has_gif, reddit_video, gif_to_mp4) => { return new Promise(resolve => { (async () => { - let valid_embed_domains = ['gfycat.com', 'youtube.com'] if(post_media || has_gif) { if(!has_gif) { - if(valid_embed_domains.includes(post_media.type)) { + if(config.valid_embed_video_domains.includes(post_media.type)) { if(post_media.type === 'gfycat.com') { obj.has_media = true + let video_url = post_media.oembed.thumbnail_url + video_url = video_url.replace('size_restricted.gif', 'mobile.mp4') obj.media = { - source: await downloadAndSave(post_media.oembed.thumbnail_url), + source: await downloadAndSave(video_url), height: post_media.oembed.thumbnail_height, - width: post_media.oembed.thumbnail_width, - duration: null, - is_gif: null, - not_hosted_in_reddit: true, - embed_src: null - } - try { - let str = post_media.oembed.html - let r = /iframe.*?src=\"(.*?)\"/; - let src = r.exec(str)[1] - obj.media.embed_src = cleanUrl(src) - } catch(error) { - console.error(`Error while trying to get src link from embed html.`, error) + width: post_media.oembed.thumbnail_width } } if(post_media.type === 'youtube.com') {