mirror of
https://codeberg.org/teddit/teddit.git
synced 2026-04-18 21:45:06 -04:00
Implement a central link object
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
module.exports = function() {
|
||||
const config = require('../config');
|
||||
const link = require('./components/link')
|
||||
this.processJsonSubreddit = (json, from, subreddit_front, user_preferences, saved) => {
|
||||
return new Promise(resolve => {
|
||||
(async () => {
|
||||
@@ -35,43 +36,14 @@ module.exports = function() {
|
||||
|
||||
for(var i = 0; i < children_len; i++) {
|
||||
let data = json.data.children[i].data
|
||||
let images = null
|
||||
let is_self_link = false
|
||||
let valid_reddit_self_domains = ['reddit.com']
|
||||
|
||||
if(data.over_18)
|
||||
if((config.nsfw_enabled === false && user_preferences.nsfw_enabled != 'true') || user_preferences.nsfw_enabled === 'false')
|
||||
continue
|
||||
|
||||
if(data.domain) {
|
||||
let tld = data.domain.split('self.')
|
||||
if(tld.length > 1) {
|
||||
if(!tld[1].includes('.')) {
|
||||
is_self_link = true
|
||||
}
|
||||
}
|
||||
if(config.valid_media_domains.includes(data.domain) || valid_reddit_self_domains.includes(data.domain)) {
|
||||
is_self_link = true
|
||||
}
|
||||
}
|
||||
|
||||
if(data.preview && data.thumbnail !== 'self') {
|
||||
if(!data.url.startsWith('/r/') && isGif(data.url)) {
|
||||
images = {
|
||||
thumb: await downloadAndSave(data.thumbnail, 'thumb_')
|
||||
}
|
||||
} else {
|
||||
if(data.preview.images[0].resolutions[0]) {
|
||||
let preview = null
|
||||
if(!isGif(data.url) && !data.post_hint.includes(':video'))
|
||||
preview = await downloadAndSave(data.preview.images[0].source.url)
|
||||
images = {
|
||||
thumb: await downloadAndSave(data.preview.images[0].resolutions[0].url, 'thumb_'),
|
||||
preview: preview
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
// Todo: Remove this once the link component is done
|
||||
// but keep it for now in case we need it later
|
||||
let obj = {
|
||||
author: data.author,
|
||||
created: data.created_utc,
|
||||
@@ -97,7 +69,10 @@ module.exports = function() {
|
||||
subreddit_front: subreddit_front,
|
||||
link_flair: (user_preferences.flairs != 'false' ? await formatLinkFlair(data) : ''),
|
||||
user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(data) : '')
|
||||
}
|
||||
} */
|
||||
|
||||
let obj = await link.fromJson(data, user_preferences, subreddit_front)
|
||||
|
||||
ret.links.push(obj)
|
||||
}
|
||||
resolve(ret)
|
||||
|
||||
Reference in New Issue
Block a user