Mark illegal functionality

This commit is contained in:
towards-a-new-leftypol 2023-08-24 18:09:08 -04:00
parent 30fecd588f
commit 1a1f039be5
3 changed files with 64 additions and 33 deletions

View File

@ -464,9 +464,9 @@ function mkSpamImgElement(img_description) {
console.log('img_description.illegal', img_description.illegal);
if (illegal) {
thumb_url = `/bin/?path=${GlobalVars.settings.redacted_thumbnail_path}&mimetype=image/jpeg`
thumb_url = "/static/redacted.jpg";
} else if (mime == "audio/mpeg") {
thumb_url = `/bin/?path=${GlobalVars.settings.audio_mpeg_thumbnail_path}&mimetype=image/jpeg`
thumb_url = '/static/mpg.png';
} else {
thumb_url = `/bin/?path=${GlobalVars.settings.content_directory}/${img_description.md5_hash}_thumbnail.jpg&mimetype=image/jpeg`
}
@ -538,28 +538,51 @@ function isIllegal(post) {
return result;
}
async function onClickMarkIllegal(phashes, e) {
console.log('CLICK', phashes);
function onClickMarkIllegal(phashes, e) {
e.stopPropagation();
e.preventDefault();
const url = new URL('/illegal', window.location.origin);
phashes.forEach(function(p) {
console.log('onClickMarkIllegal', typeof p, p);
url.searchParams.append('phash', p);
console.log('CLICK', phashes, e.target.hash);
// Get the whole post div (parent of the anchor tag)
const postDiv = e.target.closest('.post');
const img_elems = postDiv.querySelectorAll('.post--image_container img');
window.requestAnimationFrame(function() {
img_elems.forEach(function(elem) {
elem.classList.add('censored');
});
window.requestAnimationFrame(async function() {
const alert_result = confirm("Warning! This action deletes all image file data for images similar to the ones you selected. This action is irreversible. Image fingerprints will be kept for matching in the future. Do you want to proceed?");
if (alert_result) {
const url = new URL('/illegal', window.location.origin);
phashes.forEach(function(p) {
console.log('onClickMarkIllegal', typeof p, p);
url.searchParams.append('phash', p);
});
await post(url.toString(), null, cancel)
.then(function() {
location.hash = e.target.hash;
location.reload();
})
.catch(caught.bind(this, "Failed to mark post illegal because:"));
} else {
img_elems.forEach(function(elem) {
elem.classList.remove('censored');
});
}
});
});
await post(url.toString(), null, cancel)
.then(function() {
location.reload();
})
.catch(caught.bind(this, "Failed to mark post illegal because:"));
}
function renderPostElem(post) {
const postContainer = div();
postContainer.classList.add('post');
const identifier = "text_post_" + post.text_post_id;
postContainer.id = identifier;
// Header with timestamp, link to the thread
const postHeader = div();
@ -593,7 +616,7 @@ function renderPostElem(post) {
mark_illegal_a.appendChild(text('Mark Illegal'));
mark_illegal_a.setAttribute('href', '#');
mark_illegal_a.setAttribute('href', '#' + identifier);
mark_illegal_a.setAttribute('title', 'Permanently delete associated pictures and thumbnails but keep metadata for future matching');
mark_illegal.appendChild(text('['));
mark_illegal.appendChild(mark_illegal_a);
@ -687,6 +710,7 @@ function renderReasons(post) {
var container = div(h3(text('Reasons for being considered spam:')));
container.appendChild(renderReasonsUl(post));
var reasonDetails = post.reason_details;
var illegal = isIllegal(post);
if (reasonDetails) {
var reasonDetailsContainer = div();
@ -695,6 +719,8 @@ function renderReasons(post) {
if (reasonDetails.frequent_attachment_details) {
reasonDetailsContainer.appendChild(h4(text('Previously posted matching attachments:')));
reasonDetails.frequent_attachment_details.forEach(function (attachment) {
attachment.illegal = illegal;
reasonDetailsContainer.appendChild(
renderAttachmentReason(attachment, post.known_spam_post_attachment)
);
@ -720,14 +746,17 @@ function renderReasons(post) {
}
var REASONS = {
RECENTLY_POSTED_ATTACHMENT_ABOVE_RATE: 1 << 0,
LEXICAL_ANALYSIS_SHOWS_NONSENSE: 1 << 1,
SEGMENTED_AVG_ENTROPY_TOO_HIGH: 1 << 2,
TEXT_MATCHES_KNOWN_SPAM: 1 << 3,
RECENTLY_POSTED_TEXT_ABOVE_RATE: 1 << 4,
TEXT_IS_URL: 1 << 5,
TEXT_IS_ONE_LONG_WORD: 1 << 6,
TEXT_IS_RANDOM_WORDS: 1 << 7
RECENTLY_POSTED_ATTACHMENT_ABOVE_RATE : 1 << 0,
LEXICAL_ANALYSIS_SHOWS_NONSENSE : 1 << 1,
SEGMENTED_AVG_ENTROPY_TOO_HIGH : 1 << 2,
TEXT_MATCHES_KNOWN_SPAM : 1 << 3,
RECENTLY_POSTED_TEXT_ABOVE_RATE : 1 << 4,
TEXT_IS_URL : 1 << 5,
TEXT_IS_ONE_LONG_WORD : 1 << 6,
TEXT_IS_RANDOM_WORDS : 1 << 7,
ATTACHMENT_MATCHES_KNOWN_SPAM : 1 << 8,
TEXT_MANUALLY_MARKED_AS_SPAM : 1 << 9,
ATTACHMENT_MANUALLY_MARKED_AS_SPAM : 1 << 10
};
function reasonsFromBitmap(n) {
@ -794,6 +823,13 @@ function loadKnownSpamPosts(params) {
});
mainElem.appendChild(controlsB);
if (window.location.hash) {
const elem = document.querySelector(window.location.hash);
if (elem) {
elem.scrollIntoView();
}
}
}
createPagination(pageNum, url, pageName, 25, renderContent);
@ -898,14 +934,6 @@ function onUrlChange(e) {
resolvePath(ROUTES, path, e.detail.query);
}
function aClickNav(e) {
e.preventDefault();
e.stopPropagation();
console.log(this, this.href);
window.history.pushState(null, "", this.href);
onRealUrlChange();
}
function bindEventHandlers() {
window.addEventListener('urlchange', onUrlChange);
window.addEventListener('popstate', onRealUrlChange);

View File

@ -2,7 +2,6 @@
"postgrest_url": "http://192.168.4.6:3000",
"postgrest_url": "http://10.4.0.96:3000",
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic3BhbV9ub3RpY2VyIn0.j6-6HSBh-Wf5eQovT9cF1ZCNuxkQOqzBFtE3C8aTG3A",
"audio_mpeg_thumbnail_path": "/var/www/static/mpg.png",
"website_urls": {
"leftychan.net": "https://leftychan.net"
},

View File

@ -82,3 +82,7 @@ nav a {
margin: 1rem;
font-size: 1.5em;
}
img.censored {
opacity: 0;
}