diff --git a/db/files.js b/db/files.js index f1e71bb4..b91f2801 100644 --- a/db/files.js +++ b/db/files.js @@ -28,17 +28,34 @@ module.exports = { }, decrement: (fileNames) => { - return db.updateMany({ - '_id': { - '$in': fileNames - } - }, { - '$inc': { - 'count': -1 - } - }, { - 'upsert': true //probably not necessary - }); + const fileCounts = fileNames + .reduce((acc, f) => { + acc[f] = (acc[f] || 0) + 1; + return acc; + }, {}); + const commonCounts = Object.entries(fileCounts) + .reduce((acc, entry) => { + acc[entry[1]] = (acc[entry[1]] || []).concat(entry[0]); + return acc; + }, {}); + const bulkWrites = Object.entries(commonCounts) + .map(entry => { + return ({ + 'updateMany': { + 'filter': { + '_id': { + '$in': entry[1] + } + }, + 'update': { + '$inc': { + 'count': -entry[0] + } + } + } + }) + }); + return db.bulkWrite(bulkWrites); }, activeContent: () => { diff --git a/gulp/res/css/themes/army-green.css b/gulp/res/css/themes/army-green.css index 488e8ed8..425e25bf 100644 --- a/gulp/res/css/themes/army-green.css +++ b/gulp/res/css/themes/army-green.css @@ -1,6 +1,6 @@ :root { --icon-color:invert(17%) sepia(89%) saturate(7057%) hue-rotate(2deg) brightness(93%) contrast(120%); - --alt-label-color:#98E; + --alt-label-color:#6e7e46; --alt-font-color:black; --background-top:#2a401b; --background-rest:#5b7744; diff --git a/gulp/res/js/forms.js b/gulp/res/js/forms.js index fbfadbaa..2eeb5772 100644 --- a/gulp/res/js/forms.js +++ b/gulp/res/js/forms.js @@ -294,14 +294,25 @@ class formHandler { this.updateFilesText(); } - addFile(file) { + async addFile(file) { if (this.fileRequired) { //prevent drag+drop issues by removing required this.fileInput.removeAttribute('required'); } this.files.push(file); + console.log('got file', file.name, ); + let fileHash; + if (window.crypto.subtle) { + const fileBuffer = await file.arrayBuffer(); + const fileDigest = await window.crypto.subtle.digest('SHA-256', fileBuffer); + fileHash = Array.from(new Uint8Array(fileDigest)) + .map(c => c.toString(16).padStart(2, '0')) + .join(''); + console.log('file hash', fileHash); + } const item = { spoilers: this.fileUploadList.dataset.spoilers === 'true', - name: file.name + name: file.name, + hash: fileHash, } switch (file.type.split('/')[0]) { case 'image': diff --git a/gulp/res/js/uploaditem.js b/gulp/res/js/uploaditem.js index a6b81e81..457d00bb 100644 --- a/gulp/res/js/uploaditem.js +++ b/gulp/res/js/uploaditem.js @@ -10,7 +10,10 @@ pug_html = pug_html + "\u003Cdiv\u003E\u003Cdiv class=\"upload-item\"\u003E\u003 if (item.spoilers) { pug_html = pug_html + "\u003Clabel\u003E\u003Cinput" + (" type=\"checkbox\" name=\"spoiler\""+pug_attr("value", item.name, true, false)) + "\u002F\u003ESpoiler\u003C\u002Flabel\u003E"; } -pug_html = pug_html + "\u003Clabel\u003E\u003Cinput" + (" type=\"checkbox\" name=\"strip_filename\""+pug_attr("value", item.name, true, false)) + "\u002F\u003EStrip Filename\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u003E"; +if (item.hash) { +pug_html = pug_html + "\u003Clabel\u003E\u003Cinput" + (" type=\"checkbox\" name=\"strip_filename\""+pug_attr("value", item.hash, true, false)) + "\u002F\u003EStrip Filename\u003C\u002Flabel\u003E"; +} +pug_html = pug_html + "\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u003E"; }; pug_mixins["uploaditem"](uploaditem); }.call(this, "uploaditem" in locals_for_with ? diff --git a/models/forms/makepost.js b/models/forms/makepost.js index 268dbdbc..362e9d35 100644 --- a/models/forms/makepost.js +++ b/models/forms/makepost.js @@ -234,7 +234,7 @@ ${res.locals.numFiles > 0 ? req.files.file.map(f => f.name+'|'+(f.phash || '')). spoiler: (res.locals.permLevel >= 4 || userPostSpoiler) && req.body.spoiler && req.body.spoiler.includes(file.name), hash: file.sha256, filename: file.filename, //could probably remove since we have hash and extension - originalFilename: req.body.strip_filename && req.body.strip_filename.includes(file.name) ? file.filename : file.name, + originalFilename: req.body.strip_filename && req.body.strip_filename.includes(file.sha256) ? file.filename : file.name, mimetype: file.mimetype, size: file.size, extension, diff --git a/views/mixins/catalogtile.pug b/views/mixins/catalogtile.pug index 89d9baa2..36fb1472 100644 --- a/views/mixins/catalogtile.pug +++ b/views/mixins/catalogtile.pug @@ -15,7 +15,7 @@ mixin catalogtile(post, index) data-date=post.date data-replies=post.replyposts data-bump=post.bumped) - - const postURL = `/${post.board}/${modview ? 'manage/' : ''}thread/${post.postId}.html#${post.postId}` + - const postURL = `/${post.board}/${modview ? 'manage/' : ''}thread/${post.postId}.html` .post-info if !index div @@ -36,7 +36,7 @@ mixin catalogtile(post, index) span(title='Page') P: #{Math.ceil(index/10)} if post.files.length > 0 .post-file-src - a(href=postURL) + a(href=`${postURL}#${post.postId}`) - const file = post.files[0] if post.spoiler || file.spoiler div.spoilerimg.catalog-thumb diff --git a/views/mixins/uploaditem.pug b/views/mixins/uploaditem.pug index 2c298198..0b89d7f2 100644 --- a/views/mixins/uploaditem.pug +++ b/views/mixins/uploaditem.pug @@ -9,6 +9,7 @@ mixin uploaditem(item) label input(type='checkbox', name='spoiler', value=item.name) | Spoiler - label - input(type='checkbox', name='strip_filename', value=item.name) - | Strip Filename + if item.hash + label + input(type='checkbox', name='strip_filename', value=item.hash) + | Strip Filename