Merge pull request 'main' (#11) from teddit/teddit:main into changelog

Reviewed-on: https://codeberg.org/random_guy52/teddit/pulls/11
This commit is contained in:
random_guy52 2021-02-24 15:23:16 +01:00
commit c6ab579a69
8 changed files with 39 additions and 23 deletions

View File

@ -38,7 +38,7 @@ const config = {
searches: 600, searches: 600,
sidebar: 60 * 60 * 24 * 7, // 7 days sidebar: 60 * 60 * 24 * 7, // 7 days
shorts: 60 * 60 * 24 * 31, shorts: 60 * 60 * 24 * 31,
wikis: 60* 60 * 24 * 7, wikis: 60 * 60 * 24 * 7,
subreddits_explore: { subreddits_explore: {
front: 60 * 60 * 24 * 1, front: 60 * 60 * 24 * 1,
new_page: 60 new_page: 60
@ -51,6 +51,7 @@ const config = {
reddit: true, // old.reddit.com and reddit.com --> instance domain (config.domain) reddit: true, // old.reddit.com and reddit.com --> instance domain (config.domain)
}, },
valid_media_domains: ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'emoji.redditmedia.com', 'thumbs.gfycat.com', 'i.ytimg.com'], valid_media_domains: ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'emoji.redditmedia.com', 'thumbs.gfycat.com', 'i.ytimg.com'],
valid_embed_video_domains: ['gfycat.com', 'youtube.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.` 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.`
}; };

View File

@ -35,7 +35,8 @@ module.exports = function(tools) {
if (file_prefix === 'flair_') { if (file_prefix === 'flair_') {
// Flair emojis end in the name without a file extension // Flair emojis end in the name without a file extension
file_ext = 'png' file_ext = 'png'
} else if(!pathname.includes('.')) { /** } else if(!pathname.includes('.')) {
/**
* Sometimes reddit API returns video without extension, like * Sometimes reddit API returns video without extension, like
* "DASH_480" and not "DASH_480.mp4". * "DASH_480" and not "DASH_480.mp4".
*/ */
@ -57,6 +58,9 @@ module.exports = function(tools) {
resolve('') resolve('')
} else { } else {
let filename = `${temp_url.pathname.substr(1).split('/')[0]}.${file_ext}` let filename = `${temp_url.pathname.substr(1).split('/')[0]}.${file_ext}`
if(temp_url.hostname === 'thumbs.gfycat.com')
filename = `${temp_url.pathname.substr(1).split('/')[0]}`
let path = `./static/vids/${dir}${filename}` let path = `./static/vids/${dir}${filename}`
let temp_path = `./static/vids/${dir}temp_${filename}` let temp_path = `./static/vids/${dir}temp_${filename}`
if(!fs.existsSync(path)) { if(!fs.existsSync(path)) {

View File

@ -39,12 +39,17 @@ module.exports = function(fetch) {
user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(post) : '') user_flair: (user_preferences.flairs != 'false' ? await formatUserFlair(post) : '')
} }
let validEmbedDomains = ['gfycat.com', 'youtube.com'] let valid_embed_video_domains = ['gfycat.com']
let has_gif = false let has_gif = false
let gif_to_mp4 = null let gif_to_mp4 = null
let reddit_video = null let reddit_video = null
let embed_video = false
if(post.media)
if(valid_embed_video_domains.includes(post.media.type))
embed_video = true
if(post.preview) { if(post.preview && !embed_video) {
if(post.preview.reddit_video_preview) { if(post.preview.reddit_video_preview) {
if(post.preview.reddit_video_preview.is_gif) { if(post.preview.reddit_video_preview.is_gif) {
has_gif = true has_gif = true

View File

@ -3,28 +3,17 @@ module.exports = function() {
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) => {
return new Promise(resolve => { return new Promise(resolve => {
(async () => { (async () => {
let valid_embed_domains = ['gfycat.com', 'youtube.com']
if(post_media || has_gif) { if(post_media || has_gif) {
if(!has_gif) { if(!has_gif) {
if(valid_embed_domains.includes(post_media.type)) { if(config.valid_embed_video_domains.includes(post_media.type)) {
if(post_media.type === 'gfycat.com') { if(post_media.type === 'gfycat.com') {
obj.has_media = true obj.has_media = true
let video_url = post_media.oembed.thumbnail_url
video_url = video_url.replace('size_restricted.gif', 'mobile.mp4')
obj.media = { obj.media = {
source: await downloadAndSave(post_media.oembed.thumbnail_url), source: await downloadAndSave(video_url),
height: post_media.oembed.thumbnail_height, height: post_media.oembed.thumbnail_height,
width: post_media.oembed.thumbnail_width, width: post_media.oembed.thumbnail_width
duration: null,
is_gif: null,
not_hosted_in_reddit: true,
embed_src: null
}
try {
let str = post_media.oembed.html
let r = /iframe.*?src=\"(.*?)\"/;
let src = r.exec(str)[1]
obj.media.embed_src = cleanUrl(src)
} catch(error) {
console.error(`Error while trying to get src link from embed html.`, error)
} }
} }
if(post_media.type === 'youtube.com') { if(post_media.type === 'youtube.com') {

View File

@ -55,7 +55,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
} }
if(!subbed_subreddits_is_set) if(!subbed_subreddits_is_set)
res.clearCookie('subbed_subreddits') res.clearCookie('subbed_subreddits')
return res.redirect('/preferences') return res.redirect('/')
} catch(e) { } catch(e) {
console.error(`Error setting imported preferences to the cookies. Key: ${key}.`, error) console.error(`Error setting imported preferences to the cookies. Key: ${key}.`, error)
} }
@ -1456,6 +1456,14 @@ module.exports = (app, redis, fetch, RedditAPI) => {
}) })
app.post('/export_prefs', (req, res, next) => { app.post('/export_prefs', (req, res, next) => {
let export_saved = req.body.export_saved
let export_data = req.cookies
if(export_saved !== 'on') {
if(req.cookies.saved)
delete export_data.saved
}
let r = `${(Math.random().toString(36)+'00000000000000000').slice(2, 10+2).toUpperCase()}` let r = `${(Math.random().toString(36)+'00000000000000000').slice(2, 10+2).toUpperCase()}`
let key = `prefs_key:${r}` let key = `prefs_key:${r}`
redis.set(key, JSON.stringify(req.cookies), (error) => { redis.set(key, JSON.stringify(req.cookies), (error) => {

View File

@ -1466,6 +1466,11 @@ code {
background: #fff0; background: #fff0;
transition: none; transition: none;
} }
.md .md-spoiler-text:not(.revealed):active *,
.md .md-spoiler-text:not(.revealed):focus *,
.md .md-spoiler-text:not(.revealed):hover * {
opacity: 1;
}
@media only screen and (max-width: 768px) { @media only screen and (max-width: 768px) {
#user .info { #user .info {
float: right; float: right;

View File

@ -19,8 +19,6 @@ html
h2 Donating h2 Donating
p(class="word-break") XMR: 832ogRwuoSs2JGYg7wJTqshidK7dErgNdfpenQ9dzMghNXQTJRby1xGbqC3gW3GAifRM9E84J91VdMZRjoSJ32nkAZnaCEj p(class="word-break") XMR: 832ogRwuoSs2JGYg7wJTqshidK7dErgNdfpenQ9dzMghNXQTJRby1xGbqC3gW3GAifRM9E84J91VdMZRjoSJ32nkAZnaCEj
p BTC: bc1qlcrmt2pvlh4eq69l3l4h6z5jg74z2m2q3pasan p BTC: bc1qlcrmt2pvlh4eq69l3l4h6z5jg74z2m2q3pasan
h2 Contact
p orenom(at)tutanota.com
.bottom .bottom
a(href="https://en.wikipedia.org/wiki/Piratbyr%C3%A5n#Kopimi", target="_blank") a(href="https://en.wikipedia.org/wiki/Piratbyr%C3%A5n#Kopimi", target="_blank")
img(src="kopimi.gif") img(src="kopimi.gif")

View File

@ -75,6 +75,9 @@ html
.setting .setting
small By exporting your preferences you can transfer your subscribed subreddits and preferences to another device. Or you could create a bookmark if you tend to delete your cookies frequently. small By exporting your preferences you can transfer your subscribed subreddits and preferences to another device. Or you could create a bookmark if you tend to delete your cookies frequently.
br br
label(for="export_saved") Export saved posts:
input(type="checkbox", name="export_saved", id="export_saved")
br
input(type="submit", value="Export preferences") input(type="submit", value="Export preferences")
if preferences_key if preferences_key
- var protocol = 'http' - var protocol = 'http'
@ -89,5 +92,8 @@ html
.setting .setting
small By exporting your preferences you can transfer your subscribed subreddits and preferences to another device. Or you could create a bookmark if you tend to delete your cookies frequently. small By exporting your preferences you can transfer your subscribed subreddits and preferences to another device. Or you could create a bookmark if you tend to delete your cookies frequently.
br br
label(for="export_saved") Export saved posts:
input(type="checkbox", name="export_saved", id="export_saved")
br
input(type="submit", value="Export preferences") input(type="submit", value="Export preferences")
include includes/footer.pug include includes/footer.pug