diff options
Diffstat (limited to 'src/routes/index.js')
-rw-r--r-- | src/routes/index.js | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/routes/index.js b/src/routes/index.js index 01c17fa..f60fd96 100644 --- a/src/routes/index.js +++ b/src/routes/index.js | |||
@@ -11,25 +11,25 @@ router.get("/", async (req, res) => { | |||
11 | 11 | ||
12 | // GET /r/:id | 12 | // GET /r/:id |
13 | router.get("/r/:subreddit", async (req, res) => { | 13 | router.get("/r/:subreddit", async (req, res) => { |
14 | var subreddit = req.params.subreddit; | 14 | const subreddit = req.params.subreddit; |
15 | var query = req.query ? req.query : {}; | 15 | const query = req.query ? req.query : {}; |
16 | if (!query.sort) { | 16 | if (!query.sort) { |
17 | query.sort = "hot"; | 17 | query.sort = "hot"; |
18 | } | 18 | } |
19 | 19 | ||
20 | var postsReq = G.getSubmissions(query.sort, `${subreddit}`, query); | 20 | const postsReq = G.getSubmissions(query.sort, `${subreddit}`, query); |
21 | var aboutReq = G.getSubreddit(`${subreddit}`); | 21 | const aboutReq = G.getSubreddit(`${subreddit}`); |
22 | 22 | ||
23 | var [posts, about] = await Promise.all([postsReq, aboutReq]); | 23 | const [posts, about] = await Promise.all([postsReq, aboutReq]); |
24 | 24 | ||
25 | res.render("index", { subreddit, posts, about, query }); | 25 | res.render("index", { subreddit, posts, about, query }); |
26 | }); | 26 | }); |
27 | 27 | ||
28 | // GET /comments/:id | 28 | // GET /comments/:id |
29 | router.get("/comments/:id", async (req, res) => { | 29 | router.get("/comments/:id", async (req, res) => { |
30 | var id = req.params.id; | 30 | const id = req.params.id; |
31 | 31 | ||
32 | var params = { | 32 | const params = { |
33 | limit: 50, | 33 | limit: 50, |
34 | }; | 34 | }; |
35 | response = await G.getSubmissionComments(id, params); | 35 | response = await G.getSubmissionComments(id, params); |
@@ -44,20 +44,19 @@ router.get("/subs", async (req, res) => { | |||
44 | 44 | ||
45 | // GET /media | 45 | // GET /media |
46 | router.get("/media/*", async (req, res) => { | 46 | router.get("/media/*", async (req, res) => { |
47 | var url = req.params[0]; | 47 | const url = req.params[0]; |
48 | console.log(`making request to ${url}`); | 48 | const ext = url.split(".").pop().toLowerCase(); |
49 | return await fetch(url, { | 49 | const kind = ["jpg", "jpeg", "png", "gif", "webp"].includes(ext) |
50 | headers: { | 50 | ? "img" |
51 | Accept: "*/*", | 51 | : "video"; |
52 | }, | 52 | res.render("media", { kind, url }); |
53 | }); | ||
54 | }); | 53 | }); |
55 | 54 | ||
56 | module.exports = router; | 55 | module.exports = router; |
57 | 56 | ||
58 | function unescape_submission(response) { | 57 | function unescape_submission(response) { |
59 | var post = response.submission.data; | 58 | const post = response.submission.data; |
60 | var comments = response.comments; | 59 | const comments = response.comments; |
61 | 60 | ||
62 | if (post.selftext_html) { | 61 | if (post.selftext_html) { |
63 | post.selftext_html = he.decode(post.selftext_html); | 62 | post.selftext_html = he.decode(post.selftext_html); |