change filename stripping, make browser hash files and send hash of file to strip name instead of sending names to prevent duplicate both getting stripped or filename filters on backend breaking them.

also need the hashes for another feature later on too.
merge-requests/208/head
Thomas Lynch 4 years ago
parent 3402061767
commit 55778c8570
  1. 15
      gulp/res/js/forms.js
  2. 5
      gulp/res/js/uploaditem.js
  3. 2
      models/forms/makepost.js
  4. 4
      views/mixins/catalogtile.pug
  5. 7
      views/mixins/uploaditem.pug

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