When teddifying URLs to se for links, images, or video, use correct protocol scheme

This commit is contained in:
analogue 2022-03-13 22:13:21 +00:00
parent a53a9fc3df
commit ee7508b24a
1 changed files with 7 additions and 0 deletions

View File

@ -39,8 +39,10 @@ module.exports = function(request, fs) {
this.teddifyUrl = (url, user_preferences) => {
try {
let u = new URL(url)
let domain_replaced = false
if(u.host === 'www.reddit.com' || u.host === 'reddit.com') {
url = url.replace(u.host, config.domain)
domain_replaced = true
if(u.pathname.startsWith('/gallery/'))
url = url.replace('/gallery/', '/comments/')
}
@ -50,10 +52,15 @@ module.exports = function(request, fs) {
let file_ext = getFileExtension(url)
if(image_exts.includes(file_ext))
url = url.replace(`${u.host}/`, `${config.domain}/pics/w:null_`)
domain_replaced = true
if(video_exts.includes(file_ext) || !image_exts.includes(file_ext))
url = url.replace(u.host, `${config.domain}/vids`) + '.mp4'
domain_replaced = true
}
if(domain_replaced && !user_preferences.https_enabled) {
url = url.replace('https:', 'http:')
}
} catch(e) { }
url = replaceDomains(url, user_preferences)
return url