Merge branch 'new-dev'

merge-requests/208/head
Thomas Lynch 4 years ago
commit 5c0789f823
  1. 39
      db/files.js
  2. 2
      gulp/res/css/themes/army-green.css
  3. 15
      gulp/res/js/forms.js
  4. 5
      gulp/res/js/uploaditem.js
  5. 2
      models/forms/makepost.js
  6. 4
      views/mixins/catalogtile.pug
  7. 7
      views/mixins/uploaditem.pug

@ -28,17 +28,34 @@ module.exports = {
}, },
decrement: (fileNames) => { decrement: (fileNames) => {
return db.updateMany({ const fileCounts = fileNames
'_id': { .reduce((acc, f) => {
'$in': fileNames acc[f] = (acc[f] || 0) + 1;
} return acc;
}, { }, {});
'$inc': { const commonCounts = Object.entries(fileCounts)
'count': -1 .reduce((acc, entry) => {
} acc[entry[1]] = (acc[entry[1]] || []).concat(entry[0]);
}, { return acc;
'upsert': true //probably not necessary }, {});
}); const bulkWrites = Object.entries(commonCounts)
.map(entry => {
return ({
'updateMany': {
'filter': {
'_id': {
'$in': entry[1]
}
},
'update': {
'$inc': {
'count': -entry[0]
}
}
}
})
});
return db.bulkWrite(bulkWrites);
}, },
activeContent: () => { activeContent: () => {

@ -1,6 +1,6 @@
:root { :root {
--icon-color:invert(17%) sepia(89%) saturate(7057%) hue-rotate(2deg) brightness(93%) contrast(120%); --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; --alt-font-color:black;
--background-top:#2a401b; --background-top:#2a401b;
--background-rest:#5b7744; --background-rest:#5b7744;

@ -294,14 +294,25 @@ class formHandler {
this.updateFilesText(); this.updateFilesText();
} }
addFile(file) { async addFile(file) {
if (this.fileRequired) { //prevent drag+drop issues by removing required if (this.fileRequired) { //prevent drag+drop issues by removing required
this.fileInput.removeAttribute('required'); this.fileInput.removeAttribute('required');
} }
this.files.push(file); 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 = { const item = {
spoilers: this.fileUploadList.dataset.spoilers === 'true', spoilers: this.fileUploadList.dataset.spoilers === 'true',
name: file.name name: file.name,
hash: fileHash,
} }
switch (file.type.split('/')[0]) { switch (file.type.split('/')[0]) {
case 'image': case 'image':

@ -10,7 +10,10 @@ pug_html = pug_html + "\u003Cdiv\u003E\u003Cdiv class=\"upload-item\"\u003E\u003
if (item.spoilers) { 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=\"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); pug_mixins["uploaditem"](uploaditem);
}.call(this, "uploaditem" in locals_for_with ? }.call(this, "uploaditem" in locals_for_with ?

@ -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), spoiler: (res.locals.permLevel >= 4 || userPostSpoiler) && req.body.spoiler && req.body.spoiler.includes(file.name),
hash: file.sha256, hash: file.sha256,
filename: file.filename, //could probably remove since we have hash and extension 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, mimetype: file.mimetype,
size: file.size, size: file.size,
extension, extension,

@ -15,7 +15,7 @@ mixin catalogtile(post, index)
data-date=post.date data-date=post.date
data-replies=post.replyposts data-replies=post.replyposts
data-bump=post.bumped) 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 .post-info
if !index if !index
div div
@ -36,7 +36,7 @@ mixin catalogtile(post, index)
span(title='Page') P: #{Math.ceil(index/10)} span(title='Page') P: #{Math.ceil(index/10)}
if post.files.length > 0 if post.files.length > 0
.post-file-src .post-file-src
a(href=postURL) a(href=`${postURL}#${post.postId}`)
- const file = post.files[0] - const file = post.files[0]
if post.spoiler || file.spoiler if post.spoiler || file.spoiler
div.spoilerimg.catalog-thumb div.spoilerimg.catalog-thumb

@ -9,6 +9,7 @@ mixin uploaditem(item)
label label
input(type='checkbox', name='spoiler', value=item.name) input(type='checkbox', name='spoiler', value=item.name)
| Spoiler | Spoiler
label if item.hash
input(type='checkbox', name='strip_filename', value=item.name) label
| Strip Filename input(type='checkbox', name='strip_filename', value=item.hash)
| Strip Filename

Loading…
Cancel
Save