From dd495b0e6d61b665eecb9582d5d3c1591eec88f1 Mon Sep 17 00:00:00 2001 From: fatchan Date: Mon, 23 Sep 2019 05:23:12 +0000 Subject: [PATCH] add sfw boards, update homepage and webring to support and show this --- db/boards.js | 1 + gulp/res/css/style.css | 4 ++++ models/forms/changeboardsettings.js | 1 + schedules.js | 17 ++++++++++------- schedules/webring.js | 4 +++- server.js | 12 ++++++------ socketio.js | 1 + views/pages/home.pug | 20 +++++++++++++------- views/pages/managesettings.pug | 4 ++++ 9 files changed, 43 insertions(+), 21 deletions(-) diff --git a/db/boards.js b/db/boards.js index 0ea5ab2c..c771411d 100644 --- a/db/boards.js +++ b/db/boards.js @@ -115,6 +115,7 @@ module.exports = { 'sequence_value': 1, 'pph': 1, 'ips': 1, + 'settings.sfw': 1, 'settings.description': 1, 'settings.name': 1, } diff --git a/gulp/res/css/style.css b/gulp/res/css/style.css index 381138fb..e41ee381 100644 --- a/gulp/res/css/style.css +++ b/gulp/res/css/style.css @@ -356,6 +356,10 @@ td, th { cursor: pointer; } +.help { + cursor: help; +} + #postform:target + .toggle-summary { visibility: hidden; } diff --git a/models/forms/changeboardsettings.js b/models/forms/changeboardsettings.js index 2379448a..839f8ff2 100644 --- a/models/forms/changeboardsettings.js +++ b/models/forms/changeboardsettings.js @@ -40,6 +40,7 @@ module.exports = async (req, res, next) => { moderators, 'name': req.body.name && req.body.name.trim().length > 0 ? req.body.name : oldSettings.name, 'description': req.body.description && req.body.description.trim().length > 0 ? req.body.description : oldSettings.description, + 'sfw': req.body.sfw ? true : false, 'unlisted': req.body.unlisted ? true : false, 'locked': req.body.locked ? true : false, 'early404': req.body.early404 ? true : false, diff --git a/schedules.js b/schedules.js index 985cdb99..9a01fafc 100644 --- a/schedules.js +++ b/schedules.js @@ -16,16 +16,18 @@ const msTime = require(__dirname+'/helpers/mstime.js') //delete files for expired captchas const deleteCaptchas = require(__dirname+'/schedules/deletecaptchas.js'); - setInterval(async () => { - await deleteCaptchas().catch(e => console.error); + deleteCaptchas().catch(e => console.error); + setInterval(() => { + deleteCaptchas().catch(e => console.error); }, msTime.minute*5); //update webring if (enableWebring) { const updateWebring = require(__dirname+'/schedules/webring.js'); - setInterval(async () => { - await updateWebring().catch(e => console.error); - }, msTime.day); + updateWebring().catch(e => console.error); + setInterval(() => { + updateWebring().catch(e => console.error); + }, msTime.hour); } //update board stats and homepage @@ -41,8 +43,9 @@ const msTime = require(__dirname+'/helpers/mstime.js') //file pruning const pruneFiles = require(__dirname+'/schedules/prune.js'); - setInterval(async () => { - await pruneFiles().catch(e => console.error); + pruneFiles().catch(e => console.error); + setInterval(() => { + pruneFiles().catch(e => console.error); }, msTime.day); })(); diff --git a/schedules/webring.js b/schedules/webring.js index f7024659..a3169dad 100644 --- a/schedules/webring.js +++ b/schedules/webring.js @@ -2,7 +2,7 @@ const fetch = require('node-fetch') , { meta } = require(__dirname+'/../configs/main.json') - , { following, blacklist } = require(__dirname+'/../configs/webring.json') + , { logos, following, blacklist } = require(__dirname+'/../configs/webring.json') , { Boards } = require(__dirname+'/../db/') , { outputFile } = require('fs-extra') , cache = require(__dirname+'/../redis.js') @@ -44,6 +44,7 @@ module.exports = async () => { name: meta.siteName, url: meta.url, endpoint: `${meta.url}/webring.json`, + logos, following, blacklist, known, @@ -56,6 +57,7 @@ module.exports = async () => { postsPerHour: b.pph, totalPosts: b.sequence_value-1, uniqueUsers: b.ips, + nsfw: !b.settings.sfw }; }), } diff --git a/server.js b/server.js index 791ef1a1..c08b7190 100644 --- a/server.js +++ b/server.js @@ -32,7 +32,7 @@ const express = require('express') const { redisClient } = require(__dirname+'/redis.js'); // connect socketio - console.log('CONNECTING TO SOCKETIO'); + console.log('STARTING WEBSOCKET'); Socketio.connect(server); // disable useless express header @@ -102,28 +102,28 @@ const express = require('express') //listen server.listen(configs.port, '127.0.0.1', () => { new CachePugTemplates({ app, views }).start(); - console.log(`listening on port ${configs.port}`); + console.log(`LISTENING ON :${configs.port}`); //let PM2 know that this is ready for graceful reloads and to serialise startup if (typeof process.send === 'function') { //make sure we are a child process of PM2 i.e. not in dev - console.info('sending ready signal to PM2'); + console.log('SENT READY SIGNAL TO PM2'); process.send('ready'); } }); //listen for sigint from PM2 process.on('SIGINT', () => { - console.info('SIGINT SIGNAL RECEIVED'); + console.log('SIGINT SIGNAL RECEIVED'); // Stops the server from accepting new connections and finishes existing connections. server.close((err) => { // if error, log and exit with error (1 code) - console.info('CLOSING SERVER'); + console.log('CLOSING SERVER'); if (err) { console.error(err); process.exit(1); } // close database connection - console.info('DISCONNECTING MONGODB'); + console.log('DISCONNECTING MONGODB'); Mongo.client.close(); //close redis connection console.log('DISCONNECTING REDIS') diff --git a/socketio.js b/socketio.js index 7e8cdb25..ed145cc8 100644 --- a/socketio.js +++ b/socketio.js @@ -17,6 +17,7 @@ module.exports = { startRooms: () => { module.exports.io.on('connection', socket => { socket.on('room', room => { +//TODO: add some validation here that rooms exist or AT LEAST a regex for valid thread rooms socket.join(room); }); }); diff --git a/views/pages/home.pug b/views/pages/home.pug index 20fcc9f3..34d588ba 100644 --- a/views/pages/home.pug +++ b/views/pages/home.pug @@ -27,19 +27,22 @@ block content tr th Board th Description - th(style='cursor:help' title='Posts in the last hour') PPH - th(style='cursor:help' title='Unique IPs that have posted in the last 24h') Active Users + th.help(title='Posts in the last hour') PPH + th.help(title='Unique posters in the last 24h') Active Users th Total Posts each board in boards tr - td: a(href=`/${board._id}/`) /#{board._id}/ - #{board.settings.name} + td + if board.settings.sfw + span.help(title='Safe for work') 💼 + a(href=`/${board._id}/`) /#{board._id}/ - #{board.settings.name} td #{board.settings.description} td #{board.pph} td #{board.ips} td #{board.sequence_value-1} .table-container.flex-center.mv-10.text-center table - tr(style='cursor:help' title='Stats include hidden boards') + tr.help(title='Total stats including unlisted boards') th Total Posts th Total PPH th Active Users @@ -66,12 +69,15 @@ block content tr th Board th Description - th(style='cursor:help' title='Posts in the last hour') PPH - th(style='cursor:help' title='Unique IPs that have posted in the last 24h') Active Users + th.help(title='Posts in the last hour') PPH + th.help(title='Unique posters in the last 24h') Active Users th Total Posts each board in webringBoards tr - td: a(href=board.path) #{board.siteName} /#{board.uri}/ - #{board.title} + td + if !board.nsfw + span.help(title='Safe for work') 💼 + a(href=board.path) #{board.siteName} /#{board.uri}/ - #{board.title} td #{board.subtitle || '-'} td #{board.postsPerHour || '-'} td #{board.uniqueUsers || '-'} diff --git a/views/pages/managesettings.pug b/views/pages/managesettings.pug index 6d594ed7..74816b21 100644 --- a/views/pages/managesettings.pug +++ b/views/pages/managesettings.pug @@ -140,6 +140,10 @@ block content .label Unlisted label.postform-style.ph-5 input(type='checkbox', name='unlisted', value='true' checked=board.settings.unlisted) + .row + .label SFW + label.postform-style.ph-5 + input(type='checkbox', name='sfw', value='true' checked=board.settings.sfw) .row .label Theme select(name='theme')