diff --git a/db/posts.js b/db/posts.js index 007bb106..e5c25a03 100644 --- a/db/posts.js +++ b/db/posts.js @@ -41,7 +41,7 @@ module.exports = { 'globalreports': 0, } }).sort({ - '_id': -1 + 'postId': -1 }).limit(5).toArray(); //reverse order for board page @@ -50,17 +50,41 @@ module.exports = { //temporary mitigation for deletion issue if (replies.length >= 5) { //count omitted image and posts - const numPreviewImages = replies.reduce((acc, post) => { - return acc + post.files.length; - }, 0); - thread.omittedimages = thread.replyimages - numPreviewImages; - thread.omittedposts = thread.replyposts - replies.length; + const counts = await module.exports.getOmitted(board, thread.postId); + const numPreviewImages = replies.reduce((acc, post) => { return acc + post.files.length }, 0); + thread.omittedimages = counts[0].images - numPreviewImages; + thread.omittedposts = counts[0].posts - replies.length; } })); return threads; }, + getOmitted: (board, thread) => { + return db.aggregate([ + { + '$match': { + 'thread': thread, + 'board': board, + } + }, { + '$group': { + '_id': null, + // omitted posts is number of documents returned + 'posts': { + '$sum': 1 + }, + //files is sum of all length of files arrays + 'images': { + '$sum': { + '$size': '$files' + } + } + } + } + ]).toArray(); + }, + getPages: (board) => { return db.countDocuments({ 'board': board, @@ -201,33 +225,23 @@ module.exports = { insertOne: async (board, data, thread) => { - if (data.thread !== null) { - //if not a thread, update reply and image count on op document; - const filter = { + //if a reply to thread, bump if not sage + if (data.thread !== null && data.email !== 'sage' && !thread.saged) { + await db.updateOne({ 'postId': data.thread, 'board': board - } - const query = { - '$inc': { - 'replyposts': 1, - 'replyimages': data.files.length - } - } - // bump thread if name not sage - if (data.email !== 'sage' && !thread.saged) { - query['$set'] = { - 'bumped': Date.now() + }, { + '$set': { + 'bumped':Date.now() } - } - await db.updateOne(filter, query); + }); } else { - //this is a new thread, so set the bump date + //this is a new thread, so set the bump date instead data.bumped = Date.now() } const postId = await Boards.getNextId(board); data.postId = postId; - await db.insertOne(data); return postId; diff --git a/models/forms/make-post.js b/models/forms/make-post.js index 3283cc54..6903a520 100644 --- a/models/forms/make-post.js +++ b/models/forms/make-post.js @@ -197,8 +197,6 @@ module.exports = async (req, res, next, numFiles) => { 'locked': false, 'saged': false, 'cyclic': false, - 'replyposts': 0, - 'replyimages': 0, }; let postId; diff --git a/style.css b/style.css deleted file mode 100644 index d9cae9c0..00000000 --- a/style.css +++ /dev/null @@ -1,433 +0,0 @@ -body { - font-family: arial, helvetica, sans-serif; - font-size: 10pt; - background: #EEF2FF; - flex: 1; - display: flex; - flex-direction: column; - min-height: 100vh; - margin: 0; -} - -.code { - border-left: 10px solid #B7C5D9; - display: block; - padding-left: 5px; - font-family: monospace; - margin: 0.5em 0; -} - -.pages a { - text-decoration: none; -} - -object { - object-fit: contain; -} - -.board-header { - display: flex; - flex-direction: column; - align-items: center; -} - -.catalog-tile-button { - width: 100%; - line-height: 30px; - float: left; - background: #B7C5D9; - text-decoration: none; - color: black; -} - -.catalog-tile-content { - padding: 5px; -} - -.catalog-tile { - margin: 2px; - text-align: center; - max-height: 300px; - width: 250px; - overflow: hidden; - overflow-y: auto; - border: 2px solid #B7C5D9; - box-sizing: border-box; -} - -.no-m-p { - margin: 0px; - padding: 0px; -} - -.catalog-thumb { - box-shadow: 0 0 3px black; - min-width: 64px; - min-height: 64px; - object-fit: cover; -} - -.catalog { - display:flex; - align-items:flex-start; - justify-content: space-evenly; - flex-flow: row wrap; -} - -.spoiler { - background: black; -} - -.spoiler:hover { - color: white; -} - -.mode { - background-color: red; - color: white; - font-weight: bold; - text-align: center; -} - -.reports { - background: #fca!important; - border-color: #c97!important; - border-width: 1px 0; - border-style: solid none; -} - -.redtext { - color: maroon; -} - -.greentext { - color: green; -} - -blockquote a { - color: #d00; -} - -blockquote { - word-break: break-all; - white-space: pre-wrap; -} - -span { - margin-right: 5px; -} - -section { - display: flex; - flex-direction: column; - align-items: flex-start; -} - -input, textarea { - font-family: arial, helvetica, sans-serif; - font-size: 10pt; - border-radius: 3px; - max-width:100%; - border: none; - margin: 2px; - padding: 5px; -} - -.form-wrapper { - align-items: center; - margin: 10px 0; -} - -.actions { - background: #D6DAF0; - border-color: #B7C5D9; - border-width: 0 1px 1px 0; - border-style: none solid solid none; - max-width: 100%; - display: flex; - flex-direction: column; - margin: 2px 0; - padding: 2px; -} - -.action-wrapper { - display: flex; - flex-direction: column; - align-items: flex-start; -} - -.actions label { - margin: 2px 0; -} - -.toggle-label:hover { - box-shadow: inset 0 0 100px 100px rgba(255,255,255,.25); -} - -.toggle-label { - background: #D6DAF0; - padding: 10px; - border-radius: 3px; - text-align: center; - border: 1px solid lightgray; - max-width: 100%; - box-sizing: border-box; - /*-webkit-appearance: button; - -moz-appearance: button; - appearance: button;*/ -} - -.toggle { - display: none; -} - -.toggle:checked + .form-post { - display: flex; -} - -.form-post { - display: flex; - flex-direction: column; - max-width: 100%; - margin-top: 10px; -} - -.togglable { - display: none; -} - -.user-id { - text-shadow: #000 0px 0px 1px, #000 0px 0px 1px, #000 0px 0px 1px, #000 0px 0px 1px, #000 0px 0px 1px, #000 0px 0px 1px; - color: white; - padding: 0px 2px; -} - -.post-check { - position: relative; - top: 3px; - margin: -3px 1px !important; -} - -.post-files { - float: left; - margin-right: 10px; -} - -.post-data { - margin-top: -10px; - padding-top: 10px; -} - -.post-file { - display: inline-flex; - flex-direction: column; - margin: 0 4px; - padding: 2px 0; -} - -.post-file-info { - text-align: center; - margin: 2px; - margin-top: 0px; - max-width: 128px; - word-break: break-all; -} - -.post-file-src { - margin: 0 auto; -} - -figure { -} - -input textarea { - padding: 8px; -} - -.container { - padding: 10px; -} - -.board-title { - color: #af0a0f; - font: bolder 28px Tahoma; - letter-spacing: -2px; - text-align: center; - margin: 0; -} - -.no-decoration { - text-decoration: none; - color: white; -} - -.banner-check { - display: flex; - align-items: center; -} - -.board-banner { - margin: 10px; - max-width: 100%; -} - -.board-description { - text-align:center; - margin: 0; -} - -.post-message { - /*overflow-y: auto;*/ - /*float: left;*/ -} - -.post-container, .ban { - box-sizing: border-box; - margin: 2px 0; - padding: 2px; - background: #D6DAF0; - border-color: #B7C5D9; - border-width: 0 1px 1px 0; - border-style: none solid solid none; - max-width: 100%; -} - -.post-container:target { - background-color: #d6bad0!important; - border-color: #ba9dbf; -} - -.post-container.op { - background: none; - border: none; - width: 100%; -} - -.post-subject { - color: #0F0C5D; - font-weight: bold; -} - -.post-capcode { - font-weight: bold; - color: red; -} - -.post-name { - color: #117743; - font-weight: bold; -} - -.post-container.op .post-info, .catalog-tile-content .post-info { - background: none; -} - - -.post-info { - margin: -2px; - /*margin-left: -3px;*/ - padding: 2px; - padding-left: 1px; - /*background-color: #B7C5D9;*/ -} - -.post-info * { - margin-bottom: 0; - margin-top: -2px; -} - -.navbar { - border-bottom: 1px solid lightgray; -} - -.nav-item { - line-height: 50px; - text-decoration: none; - float: left; - background: #D6DAF0; - padding-left: 10px; - padding-right: 10px; - border-right: 1px solid lightgray; -} - -.right { - float: right; -} - -.nav-item:hover { - box-shadow: inset 0 0 100px 100px rgba(255,255,255,.25); -} - -.footer { - border-top: 1px solid lightgray; - text-align: center; - flex-shrink: 0; - margin-top: auto; - line-height: 50px; -} - -table, th, td { - border-bottom: 1px solid lightgray; - border-collapse: collapse; -} - -.boards-table { - margin: 0 auto; -} - -th { - background: #D6DAF0; -} - -th, td { - padding: 5px; -} - -hr { - color: lightgray; - /*border-top: 1px solid black; - background: lightgray;*/ -} - -@media only screen and (max-width: 800px) { - - input { - height: 30px; - } - - .form-post { - width: 100%; - } - - .form-login { - width: 100%; - } - - blockquote { - margin: 1em; - } - - .post-check { - top: 2px; - margin-left: 2px!important; - height: 8px; - } - - .post-container { - width: 100%; - border: none; - } - - .catalog-tile { - overflow-y: hidden; - } - - .boards-table { - width: 100%; - } - - .post-info { - background-color: #B7C5D9; - } - -}