From 3814a67517f229fd592cd51cec07a9903d75a385 Mon Sep 17 00:00:00 2001 From: teddit Date: Thu, 3 Dec 2020 17:15:43 +0100 Subject: [PATCH] sorting comments in post to config file --- config.js | 1 + inc/processPostMedia.js | 4 ++-- routes.js | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/config.js b/config.js index 0ae2323..db4dc1c 100644 --- a/config.js +++ b/config.js @@ -27,6 +27,7 @@ const config = { searches: 600, sidebar: 60 * 60 * 24 * 7 // 7 days }, + post_comments_sort: 'confidence', // one of: confidence, top, new, controversial, old, random, qa, live valid_media_domains: ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'thumbs.gfycat.com', 'i.ytimg.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/processPostMedia.js b/inc/processPostMedia.js index e30f840..336da06 100644 --- a/inc/processPostMedia.js +++ b/inc/processPostMedia.js @@ -2,10 +2,10 @@ module.exports = function() { this.processPostMedia = (obj, post, post_media, has_gif, reddit_video, gif_to_mp4) => { return new Promise(resolve => { (async () => { - let validEmbedDomains = ['gfycat.com', 'youtube.com'] + let valid_embed_domains = ['gfycat.com', 'youtube.com'] if(post_media || has_gif) { if(!has_gif) { - if(validEmbedDomains.includes(post_media.type)) { + if(valid_embed_domains.includes(post_media.type)) { if(post_media.type === 'gfycat.com') { obj.has_media = true obj.media = { diff --git a/routes.js b/routes.js index 9dc09b5..263a746 100644 --- a/routes.js +++ b/routes.js @@ -503,7 +503,7 @@ module.exports = (app, redis, fetch, RedditAPI) => { } })() } else { - fetch(`https://oauth.reddit.com${comments_url}?api_type=json&context=${context}`, redditApiGETHeaders()) + fetch(`https://oauth.reddit.com${comments_url}?api_type=json&sort=${config.post_comments_sort}&context=${context}`, redditApiGETHeaders()) .then(result => { if(result.status === 200) { result.json() @@ -724,7 +724,7 @@ module.exports = (app, redis, fetch, RedditAPI) => { console.log(`Redirecting to ${post_url} with cursor...`); return res.redirect(`${post_url}?cursor=${page}&page=${page}`) } else { - let url = `https://oauth.reddit.com/api/morechildren?api_type=json&children=${ids_to_show}&limit_children=false&link_id=t3_${post_id}&sort=confidence` + let url = `https://oauth.reddit.com/api/morechildren?api_type=json&children=${ids_to_show}&limit_children=false&link_id=t3_${post_id}&sort=${config.post_comments_sort}` fetch(url, redditApiGETHeaders()) .then(result => { if(result.status === 200) {