From 16139326f2fb5aea23614ac779171e31390b8f72 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 5 Nov 2024 17:42:41 +0000 Subject: add biome --- src/geddit.js | 894 ++++++++++++++++++++++++++++--------------------- src/index.js | 21 +- src/mixins/comment.pug | 4 +- src/routes/index.js | 96 +++--- 4 files changed, 568 insertions(+), 447 deletions(-) (limited to 'src') diff --git a/src/geddit.js b/src/geddit.js index 64e1564..d7e54e2 100644 --- a/src/geddit.js +++ b/src/geddit.js @@ -1,390 +1,510 @@ class Geddit { - constructor() { - this.host = "https://www.reddit.com"; - this.parameters = { - limit: 25, - include_over_18: true, - } - this.search_params = { - limit: 25, - include_over_18: true, - type: "sr,link,user", - } - } - - async getSubmissions(sort = null, subreddit = null, options = {}) { - let params = { - limit: 20, - include_over_18: true, - } - - sort = sort ? sort : "hot"; - subreddit = subreddit ? "/r/" + subreddit : ""; - - return await fetch(this.host + subreddit + `/${sort}.json?` + new URLSearchParams(Object.assign(params, options))) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - posts: data.children - })) - .catch(err => null); - - } - - async getDomainHot(domain, options = this.parameters) { - return await fetch(this.host + "/domain/" + domain + "/hot.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - posts: data.children - })) - .catch(err => null); - } - - async getDomainBest(domain, options = this.parameters) { - return await fetch(this.host + "/domain/" + domain + "/best.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - posts: data.children - })) - .catch(err => null); - } - - async getDomainTop(domain, options = this.parameters) { - return await fetch(this.host + "/domain/" + domain + "/top.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - posts: data.children - })) - .catch(err => null); - } - - async getDomainNew(domain, options = this.parameters) { - return await fetch(this.host + "/domain/" + domain + "/new.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - posts: data.children - })) - .catch(err => null); - } - - async getDomainRising(domain, options = this.parameters) { - return await fetch(this.host + "/domain/" + domain + "/rising.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - posts: data.children - })) - .catch(err => null); - } - - async getDomainControversial(domain, options = this.parameters) { - return await fetch(this.host + "/domain/" + domain + "/controversial.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - posts: data.children - })) - .catch(err => null); - } - - async getSubreddit(subreddit) { - return await fetch(this.host + "/r/" + subreddit + "/about.json") - .then(res => res.json()) - .then(json => json.data) - .catch(err => null); - } - - async getSubredditRules(subreddit) { - return await fetch(this.host + "/r/" + subreddit + "/about/rules.json") - .then(res => res.json()) - .then(json => json.data) - .catch(err => null); - } - - async getSubredditModerators(subreddit) { - return await fetch(this.host + "/r/" + subreddit + "/about/moderators.json") - .then(res => res.json()) - .then(json => json.data) - .then(data = ({ - users: data.children - })) - .catch(err => null); - } - - async getSubredditWikiPages(subreddit) { - return await fetch(this.host + "/r/" + subreddit + "/wiki/pages.json") - .then(res => res.json()) - .then(json => json.data) - .catch(err => null); - } - - async getSubredditWikiPage(subreddit, page) { - return await fetch(this.host + "/r/" + subreddit + "/wiki/" + page + ".json") - .then(res => res.json()) - .then(json => json.data) - .catch(err => null); - } - - async getSubredditWikiPageRevisions(subreddit, page) { - return await fetch(this.host + "/r/" + subreddit + "/wiki/revisions" + page + ".json") - .then(res => res.json()) - .then(json => json.data.children) - .catch(err => null); - } - - async getPopularSubreddits(options = this.parameters) { - return await fetch(this.host + "/subreddits/popular.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - subreddits: data.children - })) - .catch(err => null); - } - - async getNewSubreddits(options = this.parameters) { - return await fetch(this.host + "/subreddits/new.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - subreddits: data.children - })) - .catch(err => null); - } - - async getPremiumSubreddits(options = this.parameters) { - return await fetch(this.host + "/subreddits/premium.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - subreddits: data.children - })) - .catch(err => null); - } - - async getDefaultSubreddits(options = this.parameters) { - return await fetch(this.host + "/subreddits/default.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - subreddits: data.children - })) - .catch(err => null); - } - - async getPopularUsers(options = this.parameters) { - return await fetch(this.host + "/users/popular.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - users: data.children - })) - .catch(err => null); - } - - async getNewUsers(options = this.parameters) { - return await fetch(this.host + "/users/new.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - users: data.children - })) - .catch(err => null); - } - - async searchSubmissions(query, options = {}) { - options.q = query; - options.type = "link"; - - let params = { - limit: 25, - include_over_18: true - } - - return await fetch(this.host + "/search.json?" + new URLSearchParams(Object.assign(params, options))) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - items: data.children - })) - .catch(err => null); - } - - async searchSubreddits(query, options = {}) { - options.q = query; - - let params = { - limit: 25, - include_over_18: true - } - - return await fetch(this.host + "/subreddits/search.json?" + new URLSearchParams(Object.assign(params, options))) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - items: data.children - })) - .catch(err => null); - } - - async searchUsers(query, options = {}) { - options.q = query; - - let params = { - limit: 25, - include_over_18: true - } - - return await fetch(this.host + "/users/search.json?" + new URLSearchParams(Object.assign(params, options))) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - items: data.children - })) - .catch(err => null); - } - - async searchAll(query, subreddit = null, options = {}) { - options.q = query; - subreddit = subreddit ? "/r/" + subreddit : ""; - - let params = { - limit: 25, - include_over_18: true, - type: "sr,link,user", - } - - return await fetch(this.host + subreddit + "/search.json?" + new URLSearchParams(Object.assign(params, options))) - .then(res => res.json()) - .then(json => Array.isArray(json) ? ({ - after: json[1].data.after, - items: json[0].data.children.concat(json[1].data.children) - }) : ({ - after: json.data.after, - items: json.data.children - })) - .catch(err => null); - } - - async getSubmission(id) { - return await fetch(this.host + "/by_id/" + id + ".json") - .then(res => res.json()) - .then(json => json.data.children[0].data) - .catch(err => null); - } - - async getSubmissionComments(id, options = this.parameters) { - return await fetch(this.host + "/comments/" + id + ".json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => ({ - submission: json[0].data.children[0], - comments: json[1].data.children - })) - .catch(err => null); - } - - async getSubredditComments(subreddit, options = this.parameters) { - return await fetch(this.host + "/r/" + subreddit + "/comments.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data.children) - .catch(err => null); - } - - async getUser(username) { - return await fetch(this.host + "/user/" + username + "/about.json") - .then(res => res.json()) - .then(json => json.data) - .catch(err => null); - } - - async getUserOverview(username, options = this.parameters) { - return await fetch(this.host + "/user/" + username + "/overview.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - items: data.children - })) - .catch(err => null); - } - - async getUserComments(username, options = this.parameters) { - return await fetch(this.host + "/user/" + username + "/comments.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - items: data.children - })) - .catch(err => null); - } - - async getUserSubmissions(username, options = this.parameters) { - return await fetch(this.host + "/user/" + username + "/submitted.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data) - .then(data => ({ - after: data.after, - items: data.children - })) - .catch(err => null); - } - - async getLiveThread(id) { - return await fetch(this.host + "/live/" + id + "/about.json") - .then(res => res.json()) - .then(json => json.data) - .catch(err => null); - } - - async getLiveThreadUpdates(id, options = this.parameters) { - return await fetch(this.host + "/live/" + id + ".json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data.children) - .catch(err => null); - } - - - async getLiveThreadContributors(id, options = this.parameters) { - return await fetch(this.host + "/live/" + id + "/contributors.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data.children) - .catch(err => null); - } - - async getLiveThreadDiscussions(id, options = this.parameters) { - return await fetch(this.host + "/live/" + id + "/discussions.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data.children) - .catch(err => null); - } - - async getLiveThreadsNow(options = this.parameters) { - return await fetch(this.host + "/live/happening_now.json?" + new URLSearchParams(options)) - .then(res => res.json()) - .then(json => json.data.children) - .catch(err => null); - } + constructor() { + this.host = "https://www.reddit.com"; + this.parameters = { + limit: 25, + include_over_18: true, + }; + this.search_params = { + limit: 25, + include_over_18: true, + type: "sr,link,user", + }; + } + + async getSubmissions(sort = null, subreddit = null, options = {}) { + const params = { + limit: 20, + include_over_18: true, + }; + + sort = sort ? sort : "hot"; + subreddit = subreddit ? "/r/" + subreddit : ""; + + return await fetch( + this.host + + subreddit + + `/${sort}.json?` + + new URLSearchParams(Object.assign(params, options)), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + posts: data.children, + })) + .catch((err) => null); + } + + async getDomainHot(domain, options = this.parameters) { + return await fetch( + this.host + + "/domain/" + + domain + + "/hot.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + posts: data.children, + })) + .catch((err) => null); + } + + async getDomainBest(domain, options = this.parameters) { + return await fetch( + this.host + + "/domain/" + + domain + + "/best.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + posts: data.children, + })) + .catch((err) => null); + } + + async getDomainTop(domain, options = this.parameters) { + return await fetch( + this.host + + "/domain/" + + domain + + "/top.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + posts: data.children, + })) + .catch((err) => null); + } + + async getDomainNew(domain, options = this.parameters) { + return await fetch( + this.host + + "/domain/" + + domain + + "/new.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + posts: data.children, + })) + .catch((err) => null); + } + + async getDomainRising(domain, options = this.parameters) { + return await fetch( + this.host + + "/domain/" + + domain + + "/rising.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + posts: data.children, + })) + .catch((err) => null); + } + + async getDomainControversial(domain, options = this.parameters) { + return await fetch( + this.host + + "/domain/" + + domain + + "/controversial.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + posts: data.children, + })) + .catch((err) => null); + } + + async getSubreddit(subreddit) { + return await fetch(this.host + "/r/" + subreddit + "/about.json") + .then((res) => res.json()) + .then((json) => json.data) + .catch((err) => null); + } + + async getSubredditRules(subreddit) { + return await fetch(this.host + "/r/" + subreddit + "/about/rules.json") + .then((res) => res.json()) + .then((json) => json.data) + .catch((err) => null); + } + + async getSubredditModerators(subreddit) { + return await fetch(this.host + "/r/" + subreddit + "/about/moderators.json") + .then((res) => res.json()) + .then((json) => json.data) + .then( + (data = { + users: data.children, + }), + ) + .catch((err) => null); + } + + async getSubredditWikiPages(subreddit) { + return await fetch(this.host + "/r/" + subreddit + "/wiki/pages.json") + .then((res) => res.json()) + .then((json) => json.data) + .catch((err) => null); + } + + async getSubredditWikiPage(subreddit, page) { + return await fetch( + this.host + "/r/" + subreddit + "/wiki/" + page + ".json", + ) + .then((res) => res.json()) + .then((json) => json.data) + .catch((err) => null); + } + + async getSubredditWikiPageRevisions(subreddit, page) { + return await fetch( + this.host + "/r/" + subreddit + "/wiki/revisions" + page + ".json", + ) + .then((res) => res.json()) + .then((json) => json.data.children) + .catch((err) => null); + } + + async getPopularSubreddits(options = this.parameters) { + return await fetch( + this.host + "/subreddits/popular.json?" + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + subreddits: data.children, + })) + .catch((err) => null); + } + + async getNewSubreddits(options = this.parameters) { + return await fetch( + this.host + "/subreddits/new.json?" + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + subreddits: data.children, + })) + .catch((err) => null); + } + + async getPremiumSubreddits(options = this.parameters) { + return await fetch( + this.host + "/subreddits/premium.json?" + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + subreddits: data.children, + })) + .catch((err) => null); + } + + async getDefaultSubreddits(options = this.parameters) { + return await fetch( + this.host + "/subreddits/default.json?" + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + subreddits: data.children, + })) + .catch((err) => null); + } + + async getPopularUsers(options = this.parameters) { + return await fetch( + this.host + "/users/popular.json?" + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + users: data.children, + })) + .catch((err) => null); + } + + async getNewUsers(options = this.parameters) { + return await fetch( + this.host + "/users/new.json?" + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + users: data.children, + })) + .catch((err) => null); + } + + async searchSubmissions(query, options = {}) { + options.q = query; + options.type = "link"; + + const params = { + limit: 25, + include_over_18: true, + }; + + return await fetch( + this.host + + "/search.json?" + + new URLSearchParams(Object.assign(params, options)), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + items: data.children, + })) + .catch((err) => null); + } + + async searchSubreddits(query, options = {}) { + options.q = query; + + const params = { + limit: 25, + include_over_18: true, + }; + + return await fetch( + this.host + + "/subreddits/search.json?" + + new URLSearchParams(Object.assign(params, options)), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + items: data.children, + })) + .catch((err) => null); + } + + async searchUsers(query, options = {}) { + options.q = query; + + const params = { + limit: 25, + include_over_18: true, + }; + + return await fetch( + this.host + + "/users/search.json?" + + new URLSearchParams(Object.assign(params, options)), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + items: data.children, + })) + .catch((err) => null); + } + + async searchAll(query, subreddit = null, options = {}) { + options.q = query; + subreddit = subreddit ? "/r/" + subreddit : ""; + + const params = { + limit: 25, + include_over_18: true, + type: "sr,link,user", + }; + + return await fetch( + this.host + + subreddit + + "/search.json?" + + new URLSearchParams(Object.assign(params, options)), + ) + .then((res) => res.json()) + .then((json) => + Array.isArray(json) + ? { + after: json[1].data.after, + items: json[0].data.children.concat(json[1].data.children), + } + : { + after: json.data.after, + items: json.data.children, + }, + ) + .catch((err) => null); + } + + async getSubmission(id) { + return await fetch(this.host + "/by_id/" + id + ".json") + .then((res) => res.json()) + .then((json) => json.data.children[0].data) + .catch((err) => null); + } + + async getSubmissionComments(id, options = this.parameters) { + return await fetch( + this.host + "/comments/" + id + ".json?" + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => ({ + submission: json[0].data.children[0], + comments: json[1].data.children, + })) + .catch((err) => null); + } + + async getSubredditComments(subreddit, options = this.parameters) { + return await fetch( + this.host + + "/r/" + + subreddit + + "/comments.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data.children) + .catch((err) => null); + } + + async getUser(username) { + return await fetch(this.host + "/user/" + username + "/about.json") + .then((res) => res.json()) + .then((json) => json.data) + .catch((err) => null); + } + + async getUserOverview(username, options = this.parameters) { + return await fetch( + this.host + + "/user/" + + username + + "/overview.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + items: data.children, + })) + .catch((err) => null); + } + + async getUserComments(username, options = this.parameters) { + return await fetch( + this.host + + "/user/" + + username + + "/comments.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + items: data.children, + })) + .catch((err) => null); + } + + async getUserSubmissions(username, options = this.parameters) { + return await fetch( + this.host + + "/user/" + + username + + "/submitted.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data) + .then((data) => ({ + after: data.after, + items: data.children, + })) + .catch((err) => null); + } + + async getLiveThread(id) { + return await fetch(this.host + "/live/" + id + "/about.json") + .then((res) => res.json()) + .then((json) => json.data) + .catch((err) => null); + } + + async getLiveThreadUpdates(id, options = this.parameters) { + return await fetch( + this.host + "/live/" + id + ".json?" + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data.children) + .catch((err) => null); + } + + async getLiveThreadContributors(id, options = this.parameters) { + return await fetch( + this.host + + "/live/" + + id + + "/contributors.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data.children) + .catch((err) => null); + } + + async getLiveThreadDiscussions(id, options = this.parameters) { + return await fetch( + this.host + + "/live/" + + id + + "/discussions.json?" + + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data.children) + .catch((err) => null); + } + + async getLiveThreadsNow(options = this.parameters) { + return await fetch( + this.host + "/live/happening_now.json?" + new URLSearchParams(options), + ) + .then((res) => res.json()) + .then((json) => json.data.children) + .catch((err) => null); + } } -export { Geddit } +export { Geddit }; diff --git a/src/index.js b/src/index.js index 099ee4d..164ad49 100644 --- a/src/index.js +++ b/src/index.js @@ -1,18 +1,17 @@ -const express = require('express'); -const path = require('path'); -const routes = require('./routes/index'); -const geddit = require('./geddit.js'); +const express = require("express"); +const path = require("path"); +const routes = require("./routes/index"); +const geddit = require("./geddit.js"); const app = express(); -app.set('views', path.join(__dirname, 'views')); -app.set('view engine', 'pug'); +app.set("views", path.join(__dirname, "views")); +app.set("view engine", "pug"); -app.use(express.static(path.join(__dirname, 'public'))); -app.use('/', routes); +app.use(express.static(path.join(__dirname, "public"))); +app.use("/", routes); const port = process.env.READIT_PORT; -const server = app.listen(port?port:3000, () => { - console.log(`started on ${server.address().port}`); +const server = app.listen(port ? port : 3000, () => { + console.log(`started on ${server.address().port}`); }); - diff --git a/src/mixins/comment.pug b/src/mixins/comment.pug index 4249030..d02c221 100644 --- a/src/mixins/comment.pug +++ b/src/mixins/comment.pug @@ -19,10 +19,10 @@ mixin infoContainer(data) mixin comment(com, isfirst) - var data = com.data - - var kind = com.kind + - console.log(com) - var hasReplyData = hasReplies(data) - if kind == "more" + if com.kind == "more" div(class=`more ${isfirst ? 'first' : ''}`) | #{data.count} more #{fmttxt(data.count, 'comment')} else diff --git a/src/routes/index.js b/src/routes/index.js index 54a5b18..01c17fa 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,79 +1,81 @@ -const express = require('express'); -const he = require('he'); +const express = require("express"); +const he = require("he"); const router = express.Router(); -const geddit = require('../geddit.js'); +const geddit = require("../geddit.js"); const G = new geddit.Geddit(); - // GET / -router.get('/', async (req, res) => { - res.redirect("/r/all") +router.get("/", async (req, res) => { + res.redirect("/r/all"); }); // GET /r/:id -router.get('/r/:subreddit', async (req, res) => { - var subreddit = req.params.subreddit; - var query = req.query? req.query : {}; - if (!query.sort) { - query.sort = 'hot'; - } +router.get("/r/:subreddit", async (req, res) => { + var subreddit = req.params.subreddit; + var query = req.query ? req.query : {}; + if (!query.sort) { + query.sort = "hot"; + } - var postsReq = G.getSubmissions(query.sort, `${subreddit}`, query); - var aboutReq = G.getSubreddit(`${subreddit}`); + var postsReq = G.getSubmissions(query.sort, `${subreddit}`, query); + var aboutReq = G.getSubreddit(`${subreddit}`); - var [posts, about] = await Promise.all([postsReq, aboutReq]); + var [posts, about] = await Promise.all([postsReq, aboutReq]); - res.render('index', { subreddit, posts, about, query }); + res.render("index", { subreddit, posts, about, query }); }); // GET /comments/:id -router.get('/comments/:id', async (req, res) => { - var id = req.params.id; +router.get("/comments/:id", async (req, res) => { + var id = req.params.id; - response = await G.getSubmissionComments(id); + var params = { + limit: 50, + }; + response = await G.getSubmissionComments(id, params); - res.render('comments', unescape_submission(response)); + res.render("comments", unescape_submission(response)); }); // GET /subs -router.get('/subs', async (req, res) => { - res.render('subs'); +router.get("/subs", async (req, res) => { + res.render("subs"); }); // GET /media -router.get('/media/*', async (req, res) => { - var url = req.params[0]; - console.log(`making request to ${url}`); - return await fetch(url, { - headers: { - Accept: "*/*", - } - }); +router.get("/media/*", async (req, res) => { + var url = req.params[0]; + console.log(`making request to ${url}`); + return await fetch(url, { + headers: { + Accept: "*/*", + }, + }); }); module.exports = router; function unescape_submission(response) { - var post = response.submission.data; - var comments = response.comments; + var post = response.submission.data; + var comments = response.comments; - if (post.selftext_html) { - post.selftext_html = he.decode(post.selftext_html); - } - comments.forEach(unescape_comment); + if (post.selftext_html) { + post.selftext_html = he.decode(post.selftext_html); + } + comments.forEach(unescape_comment); - return { post, comments }; + return { post, comments }; } function unescape_comment(comment) { - if (comment.data.body_html) { - comment.data.body_html = he.decode(comment.data.body_html); - } - if (comment.data.replies) { - if(comment.data.replies.data) { - if(comment.data.replies.data.children) { - comment.data.replies.data.children.forEach(unescape_comment); - } - } - } + if (comment.data.body_html) { + comment.data.body_html = he.decode(comment.data.body_html); + } + if (comment.data.replies) { + if (comment.data.replies.data) { + if (comment.data.replies.data.children) { + comment.data.replies.data.children.forEach(unescape_comment); + } + } + } } -- cgit v1.2.3