we need user_preferences for the 2nd argument for replaceDomains() to work properly #187

This commit is contained in:
teddit 2021-04-08 17:04:50 +02:00
parent cc8b893fbc
commit 769205d4d7
2 changed files with 8 additions and 8 deletions

View File

@ -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,

View File

@ -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)
}
}
}