1
0
mirror of https://codeberg.org/teddit/teddit synced 2025-02-16 12:10:36 +01:00

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

View File

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