From eb6b87cf1f3933fa2fde4909856655ce253875c9 Mon Sep 17 00:00:00 2001 From: 3nprob <3nprob@3nprob> Date: Thu, 7 Oct 2021 00:48:05 +0900 Subject: [PATCH] Make comments optional Since they require CLIENT_ID --- samples/.a_DfEsrAB.swp | Bin 8192 -> 0 bytes src/config.ts | 1 + src/handlers.ts | 6 +++++- templates/gallery.pug | 19 ++++++++++--------- 4 files changed, 16 insertions(+), 10 deletions(-) delete mode 100644 samples/.a_DfEsrAB.swp diff --git a/samples/.a_DfEsrAB.swp b/samples/.a_DfEsrAB.swp deleted file mode 100644 index 8bdac2a3dfcbf2341d35e7826b831da587de40b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmeIuy9&ZE6b9f_XF==>R2`f&wOw2l9UL6hNu*+ogPW$+4^_tKIcNx@TwV zMuPewKgqt3@#RXD7m9!>>TRconUdqlw{@sP00NZ+8pL&mb~e)Ov@Nr>tTc^g2tWV= z5P$##AOHafK;XXx5@C=>dcr#oBR@yyTK?9#c&+X${^Jb+2tWV=5P$##AOHafKmY;| JfWYqvd;n&VDV+cS diff --git a/src/config.ts b/src/config.ts index b04bb29..3fbe69a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,4 +5,5 @@ export default { http_proxy: process.env.RIMGU_HTTP_PROXY || null, https_proxy: process.env.RIMGU_HTTPS_PROXY || null, imgur_client_id: process.env.RIMGU_IMGUR_CLIENT_ID || null, + disable_comments: process.env.RIMGU_DISABLE_COMMENTS === 'true', }; diff --git a/src/handlers.ts b/src/handlers.ts index c59283f..aec9c3a 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -3,6 +3,8 @@ import '@hapi/vision'; import { fetchAlbumURL, fetchComments, fetchGallery, fetchMedia } from './fetchers'; import * as util from './util'; +import CONFIG from './config'; + export const handleMedia = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => { const { baseName, @@ -36,7 +38,9 @@ export const handleTag = (request: Hapi.Request, h: Hapi.ResponseToolkit) => { export const handleGallery = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => { const galleryID = request.params.galleryID; const gallery = await fetchGallery(galleryID); - const comments = await fetchComments(galleryID); + const comments = CONFIG.disable_comments + ? null + : await fetchComments(galleryID); return h.view('gallery', { ...gallery, comments, diff --git a/templates/gallery.pug b/templates/gallery.pug index fb94aa3..7770c4d 100644 --- a/templates/gallery.pug +++ b/templates/gallery.pug @@ -60,12 +60,13 @@ html a(class='TagPill' style='background: linear-gradient(0deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.2)) repeat scroll 0% 0%, rgba(0, 0, 0, 0) url("/' + tag.background_id + '_d.jpg?maxwidth=200&fidelity=grand") repeat scroll 0% 0%;' href='/t/'+tag.tag) #{tag.tag} - div(class='CommentsList') - div(class='CommentsList-headline') - div(class='CommentsList-headline--counter') - span #{comments.length} Comments - div - div(class='CommentsList-comments') - div(class='CommentsList-comments--container') - each comment in comments - +commentbox(comment) + if comments != null + div(class='CommentsList') + div(class='CommentsList-headline') + div(class='CommentsList-headline--counter') + span #{comments.length} Comments + div + div(class='CommentsList-comments') + div(class='CommentsList-comments--container') + each comment in comments + +commentbox(comment)