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) => {
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: () => {

@ -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;

@ -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':

@ -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 ?

@ -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,

@ -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

@ -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

Loading…
Cancel
Save