diff options
author | Akshay <[email protected]> | 2024-11-26 21:19:41 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2024-11-26 21:19:41 +0000 |
commit | 0d4d90ba058ed3b7ee0d4054602096d16151303c (patch) | |
tree | f244a4b9c575cd6cd0cef489c3beb5595b36677c | |
parent | 964700b06ea8779b9dc0f0f9fe0b399627402682 (diff) |
add search page, support spoiler/nsfw imgs
-rw-r--r-- | src/assets/missing.svg | 9 | ||||
-rw-r--r-- | src/assets/nsfw.svg | 7 | ||||
-rw-r--r-- | src/assets/spoiler.svg | 8 | ||||
-rw-r--r-- | src/auth.js | 4 | ||||
-rw-r--r-- | src/index.js | 1 | ||||
-rw-r--r-- | src/mixins/post.pug | 2 | ||||
-rw-r--r-- | src/mixins/postUtils.pug | 12 | ||||
-rw-r--r-- | src/public/styles.css | 10 | ||||
-rw-r--r-- | src/routes/index.js | 9 | ||||
-rw-r--r-- | src/views/comments.pug | 3 | ||||
-rw-r--r-- | src/views/index.pug | 4 | ||||
-rw-r--r-- | src/views/sub-search.pug | 3 |
12 files changed, 57 insertions, 15 deletions
diff --git a/src/assets/missing.svg b/src/assets/missing.svg new file mode 100644 index 0000000..2438603 --- /dev/null +++ b/src/assets/missing.svg | |||
@@ -0,0 +1,9 @@ | |||
1 | <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"> | ||
2 | <rect x="2" y="2" width="196" height="196" style="fill:#999;stroke:#000000"/> | ||
3 | <text x="50%" y="50%" font-size="36" text-anchor="middle" alignment-baseline="middle" font-family="monospace, sans-serif" fill="#000000"> | ||
4 | missing | ||
5 | </text> | ||
6 | <style/> | ||
7 | </svg> | ||
8 | |||
9 | |||
diff --git a/src/assets/nsfw.svg b/src/assets/nsfw.svg new file mode 100644 index 0000000..5adaa9c --- /dev/null +++ b/src/assets/nsfw.svg | |||
@@ -0,0 +1,7 @@ | |||
1 | <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"> | ||
2 | <rect x="2" y="2" width="196" height="196" style="fill:#ff123a;stroke:#000000"/> | ||
3 | <text x="50%" y="50%" font-size="36" text-anchor="middle" alignment-baseline="middle" font-family="monospace, sans-serif" fill="#000000"> | ||
4 | nsfw | ||
5 | </text> | ||
6 | <style/> | ||
7 | </svg> | ||
diff --git a/src/assets/spoiler.svg b/src/assets/spoiler.svg new file mode 100644 index 0000000..aed3392 --- /dev/null +++ b/src/assets/spoiler.svg | |||
@@ -0,0 +1,8 @@ | |||
1 | <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"> | ||
2 | <rect x="2" y="2" width="196" height="196" style="fill:#999;stroke:#000000"/> | ||
3 | <text x="50%" y="50%" font-size="36" text-anchor="middle" alignment-baseline="middle" font-family="monospace, sans-serif" fill="#000000"> | ||
4 | spoiler | ||
5 | </text> | ||
6 | <style/> | ||
7 | </svg> | ||
8 | |||
diff --git a/src/auth.js b/src/auth.js index 78e3dea..f040a08 100644 --- a/src/auth.js +++ b/src/auth.js | |||
@@ -27,7 +27,9 @@ function authenticateToken(req, res, next) { | |||
27 | 27 | ||
28 | function authenticateAdmin(req, res, next) { | 28 | function authenticateAdmin(req, res, next) { |
29 | if (!req.cookies || !req.cookies.auth_token) { | 29 | if (!req.cookies || !req.cookies.auth_token) { |
30 | return res.redirect("/login"); | 30 | return res.redirect( |
31 | `/login?redirect=${encodeURIComponent(req.originalUrl)}`, | ||
32 | ); | ||
31 | } | 33 | } |
32 | 34 | ||
33 | const token = req.cookies.auth_token; | 35 | const token = req.cookies.auth_token; |
diff --git a/src/index.js b/src/index.js index 6296534..f6680c1 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -16,6 +16,7 @@ const routes = require("./routes/index"); | |||
16 | app.use(express.json()); | 16 | app.use(express.json()); |
17 | app.use(express.urlencoded({ extended: true })); | 17 | app.use(express.urlencoded({ extended: true })); |
18 | app.use(express.static(path.join(__dirname, "public"))); | 18 | app.use(express.static(path.join(__dirname, "public"))); |
19 | app.use(express.static(path.join(__dirname, "assets"))); | ||
19 | app.use(cookieParser()); | 20 | app.use(cookieParser()); |
20 | app.use( | 21 | app.use( |
21 | rateLimit({ | 22 | rateLimit({ |
diff --git a/src/mixins/post.pug b/src/mixins/post.pug index 76fa1b8..4287801 100644 --- a/src/mixins/post.pug +++ b/src/mixins/post.pug | |||
@@ -26,7 +26,7 @@ mixin post(p) | |||
26 | img(src=item.url onclick=`toggleDetails('${p.id}')`) | 26 | img(src=item.url onclick=`toggleDetails('${p.id}')`) |
27 | else if isPostImage(p) | 27 | else if isPostImage(p) |
28 | - var url = postThumbnail(p) | 28 | - var url = postThumbnail(p) |
29 | img(src=url onclick=`toggleDetails('${p.id}')`) | 29 | img(src=url onclick=`toggleDetails('${p.id}')`) |
30 | else if isPostVideo(p) | 30 | else if isPostVideo(p) |
31 | - var url = p.secure_media.reddit_video.scrubber_media_url | 31 | - var url = p.secure_media.reddit_video.scrubber_media_url |
32 | video(src=url data-dashjs-player width='100px' height='100px' onclick=`toggleDetails('${p.id}')`) | 32 | video(src=url data-dashjs-player width='100px' height='100px' onclick=`toggleDetails('${p.id}')`) |
diff --git a/src/mixins/postUtils.pug b/src/mixins/postUtils.pug index 555e388..816adf7 100644 --- a/src/mixins/postUtils.pug +++ b/src/mixins/postUtils.pug | |||
@@ -4,12 +4,18 @@ | |||
4 | } | 4 | } |
5 | - | 5 | - |
6 | function isPostImage(p) { | 6 | function isPostImage(p) { |
7 | return (p.post_hint == "image" && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default"); | 7 | const imgRe = /\.(png|jpg|jpeg|gif|webp|bmp|tiff|svg)$/i; |
8 | return (p.post_hint == "image" && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default") | ||
9 | || imgRe.test(p.url); | ||
8 | } | 10 | } |
9 | - | 11 | - |
10 | function postThumbnail(p) { | 12 | function postThumbnail(p) { |
11 | if (p.thumbnail == "image") { | 13 | if (p.thumbnail == "image" || p.thumbnail == "") { |
12 | return p.url | 14 | return p.url; |
15 | } else if (p.over_18) { | ||
16 | return "/nsfw.svg"; | ||
17 | } else if (p.thumbnail == "spoiler") { | ||
18 | return "/spoiler.svg"; | ||
13 | } else { | 19 | } else { |
14 | return p.thumbnail; | 20 | return p.thumbnail; |
15 | } | 21 | } |
diff --git a/src/public/styles.css b/src/public/styles.css index 3b3e80d..090205e 100644 --- a/src/public/styles.css +++ b/src/public/styles.css | |||
@@ -158,14 +158,10 @@ summary::before { | |||
158 | .info-item, .header-item, .footer-item { | 158 | .info-item, .header-item, .footer-item { |
159 | margin-right: 14px; | 159 | margin-right: 14px; |
160 | } | 160 | } |
161 | |||
162 | .media-preview img, | ||
163 | .media-preview video { | ||
164 | object-fit: cover; | ||
165 | } | ||
166 | 161 | ||
167 | .media-preview img, | 162 | .media-preview img, |
168 | .media-preview video { | 163 | .media-preview video { |
164 | object-fit: cover; | ||
169 | width: 4rem; | 165 | width: 4rem; |
170 | height: 4rem; | 166 | height: 4rem; |
171 | } | 167 | } |
@@ -565,3 +561,7 @@ form input[type="submit"]:hover { | |||
565 | flex-direction: column; | 561 | flex-direction: column; |
566 | gap: 20px; | 562 | gap: 20px; |
567 | } | 563 | } |
564 | |||
565 | .about { | ||
566 | padding-bottom: 20px; | ||
567 | } | ||
diff --git a/src/routes/index.js b/src/routes/index.js index 6e54ef3..d4cfd35 100644 --- a/src/routes/index.js +++ b/src/routes/index.js | |||
@@ -131,7 +131,14 @@ router.get("/search", authenticateToken, async (req, res) => { | |||
131 | items.length === 0 | 131 | items.length === 0 |
132 | ? "no results found" | 132 | ? "no results found" |
133 | : `showing ${items.length} results`; | 133 | : `showing ${items.length} results`; |
134 | res.render("sub-search", { items, subs, after, message, user: req.user }); | 134 | res.render("sub-search", { |
135 | items, | ||
136 | subs, | ||
137 | after, | ||
138 | message, | ||
139 | user: req.user, | ||
140 | original_query: req.query.q, | ||
141 | }); | ||
135 | } | 142 | } |
136 | }); | 143 | }); |
137 | 144 | ||
diff --git a/src/views/comments.pug b/src/views/comments.pug index e9bd332..844dfcc 100644 --- a/src/views/comments.pug +++ b/src/views/comments.pug | |||
@@ -43,7 +43,8 @@ html | |||
43 | a(href=`/media/${item.url}`) | 43 | a(href=`/media/${item.url}`) |
44 | img(src=item.url loading="lazy") | 44 | img(src=item.url loading="lazy") |
45 | else if isPostImage(post) | 45 | else if isPostImage(post) |
46 | img(src=post.url).post-media | 46 | a(href=`/media/${post.url}`) |
47 | img(src=post.url).post-media | ||
47 | else if isPostVideo(post) | 48 | else if isPostVideo(post) |
48 | - var url = post.secure_media.reddit_video.dash_url | 49 | - var url = post.secure_media.reddit_video.dash_url |
49 | video(controls data-dashjs-player src=`${url}`).post-media | 50 | video(controls data-dashjs-player src=`${url}`).post-media |
diff --git a/src/views/index.pug b/src/views/index.pug index a3bcd84..ea730fb 100644 --- a/src/views/index.pug +++ b/src/views/index.pug | |||
@@ -25,9 +25,9 @@ html | |||
25 | else | 25 | else |
26 | button(onclick=`toggleSub('${subreddit}')` id=`thinger_${subreddit}`) subscribe | 26 | button(onclick=`toggleSub('${subreddit}')` id=`thinger_${subreddit}`) subscribe |
27 | if about && !isMulti | 27 | if about && !isMulti |
28 | p #{about.public_description} | 28 | div.about #{about.public_description} |
29 | else | 29 | else |
30 | p | 30 | div.about |
31 | | consider donating to | 31 | | consider donating to |
32 | a(href="https://donate.stripe.com/dR62bTaZH1295Da4gg") oppiliappan | 32 | a(href="https://donate.stripe.com/dR62bTaZH1295Da4gg") oppiliappan |
33 | |, author of readit | 33 | |, author of readit |
diff --git a/src/views/sub-search.pug b/src/views/sub-search.pug index da33214..bf0d402 100644 --- a/src/views/sub-search.pug +++ b/src/views/sub-search.pug | |||
@@ -11,7 +11,8 @@ html | |||
11 | div.hero | 11 | div.hero |
12 | h1 search subreddits | 12 | h1 search subreddits |
13 | form(action="/search" method="get").search-bar | 13 | form(action="/search" method="get").search-bar |
14 | input(type="text" name="q" placeholder="search subreddits (add +nsfw to include over-18 results)" required).search-input | 14 | - var prefill = original_query ?? ""; |
15 | input(type="text" name="q" placeholder="search subreddits (add +nsfw to include over-18 results)" value=prefill required).search-input | ||
15 | button(type="submit").search-button go | 16 | button(type="submit").search-button go |
16 | if message | 17 | if message |
17 | div.search-message | 18 | div.search-message |