Merge branch 'main' into main

This commit is contained in:
zutart 2021-04-09 22:29:39 +02:00
commit d31f6a97e8
8 changed files with 22 additions and 17 deletions

View File

@ -6,8 +6,10 @@ RUN apk add ffmpeg
# Install NPM dependencies and copy the project # Install NPM dependencies and copy the project
WORKDIR /teddit WORKDIR /teddit
COPY . /teddit/ COPY . ./
RUN npm install --no-optional RUN npm install --no-optional
COPY config.js.template /teddit/config.js COPY config.js.template ./config.js
RUN find ./static/ -type d -exec chmod -R 777 {} \;
CMD npm start CMD npm start

8
app.js
View File

@ -7,7 +7,6 @@ global.ratelimit_counts = {}
global.ratelimit_timestamps = {} global.ratelimit_timestamps = {}
const pug = require('pug') const pug = require('pug')
const path = require('path')
const compression = require('compression') const compression = require('compression')
const express = require('express') const express = require('express')
const cookieParser = require('cookie-parser') const cookieParser = require('cookie-parser')
@ -53,7 +52,12 @@ const fs = require('fs')
const app = express() const app = express()
const request = require('postman-request') const request = require('postman-request')
const commons = require('./inc/commons.js')(request, fs) const commons = require('./inc/commons.js')(request, fs)
const dlAndSave = require('./inc/downloadAndSave.js')(commons) const dlAndSave = require('./inc/downloadAndSave.js')(commons);
['pics/thumbs', 'pics/flairs', 'pics/icons', 'vids']
.map(d => `./static/${d}`)
.filter(d => !fs.existsSync(d))
.forEach(d => fs.mkdirSync(d, { recursive: true }))
if(!config.https_enabled && config.redirect_http_to_https) { if(!config.https_enabled && config.redirect_http_to_https) {
console.error(`Cannot redirect HTTP=>HTTPS while "https_enabled" is false.`) console.error(`Cannot redirect HTTP=>HTTPS while "https_enabled" is false.`)

View File

@ -20,7 +20,7 @@ module.exports = function(request, fs) {
if(!error) { if(!error) {
resolve({ success: true }) resolve({ success: true })
} else { } else {
resolve({ success: false }) resolve({ success: false, error })
} }
}) })
}).catch((err) => { }).catch((err) => {

View File

@ -89,7 +89,7 @@ module.exports = function(tools) {
let temp_files = [temp_path, audio_path] let temp_files = [temp_path, audio_path]
deleteFiles(temp_files, (error) => { deleteFiles(temp_files, (error) => {
if(error) { if(error) {
console.log(`Error while deleting temporay files:`, error) console.log(`Error while deleting temporary files:`, error)
} }
}) })
resolve(final_url) resolve(final_url)

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) { if(post.crosspost_parent_list) {
post.crosspost = post.crosspost_parent_list[0] post.crosspost = post.crosspost_parent_list[0]
} }
if(post.crosspost) { 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 = { obj.crosspost = {
author: post.crosspost.author, author: post.crosspost.author,
created: post.crosspost.created_utc, created: post.crosspost.created_utc,

View File

@ -1,6 +1,6 @@
module.exports = function() { module.exports = function() {
const config = require('../config') 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 => { return new Promise(resolve => {
(async () => { (async () => {
if(post_media || has_gif) { if(post_media || has_gif) {
@ -24,7 +24,7 @@ module.exports = function() {
width: post_media.oembed.thumbnail_width, width: post_media.oembed.thumbnail_width,
thumbnail: await downloadAndSave(post_media.oembed.thumbnail_url, '', false, true), thumbnail: await downloadAndSave(post_media.oembed.thumbnail_url, '', false, true),
author_name: post_media.oembed.author_name, author_name: post_media.oembed.author_name,
author_url: post_media.oembed.author_url, author_url: replaceDomains(post_media.oembed.author_url, user_preferences),
title: post_media.oembed.title, title: post_media.oembed.title,
duration: null, duration: null,
is_gif: null, is_gif: null,
@ -37,9 +37,8 @@ module.exports = function() {
let r = /iframe.*?src=\"(.*?)\"/; let r = /iframe.*?src=\"(.*?)\"/;
let src = r.exec(str)[1] let src = r.exec(str)[1]
let youtube_id = src.split('/embed/')[1].split('?')[0] let youtube_id = src.split('/embed/')[1].split('?')[0]
// TODO: Invidious youtube URLs.
let youtube_url = `https://youtube.com/watch?v=${youtube_id}` let youtube_url = `https://youtube.com/watch?v=${youtube_id}`
obj.media.embed_src = youtube_url obj.media.embed_src = replaceDomains(youtube_url, user_preferences)
} catch(error) { } catch(error) {
console.error(`Error while trying to get src link from embed youtube html.`, error) console.error(`Error while trying to get src link from embed youtube html.`, error)
} }
@ -67,7 +66,7 @@ module.exports = function() {
source: 'external', source: 'external',
height: post_media.oembed.height, height: post_media.oembed.height,
width: post_media.oembed.width, width: post_media.oembed.width,
provider_url: post_media.oembed.provider_url, provider_url: replaceDomains(post_media.oembed.provider_url, user_preferences),
provider_name: post_media.oembed.provider_name, provider_name: post_media.oembed.provider_name,
title: post_media.oembed.title, title: post_media.oembed.title,
duration: null, duration: null,
@ -79,12 +78,12 @@ module.exports = function() {
let str = post_media.oembed.html let str = post_media.oembed.html
let r = /iframe.*?src=\"(.*?)\"/; let r = /iframe.*?src=\"(.*?)\"/;
let src = r.exec(str)[1] let src = r.exec(str)[1]
obj.media.embed_src = cleanUrl(src) obj.media.embed_src = replaceDomains(cleanUrl(src), user_preferences)
} catch(error) { } catch(error) {
//console.error(`Error while trying to get src link from embed html.`, error) //console.error(`Error while trying to get src link from embed html.`, error)
} }
if(!obj.media.embed_src) { if(!obj.media.embed_src) {
obj.media.embed_src = post_media.oembed.url obj.media.embed_src = replaceDomains(post_media.oembed.url, user_preferences)
} }
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "teddit", "name": "teddit",
"version": "0.2.2", "version": "0.3.1",
"description": "A free and open source alternative Reddit front-end focused on privacy.", "description": "A free and open source alternative Reddit front-end focused on privacy.",
"homepage": "https://teddit.net", "homepage": "https://teddit.net",
"bugs": { "bugs": {

View File

@ -21,5 +21,5 @@ html
.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")
p.version v.0.2.2 p.version v.0.3.1
include includes/footer.pug include includes/footer.pug