From 95cfa9ae52b4e09e6a623e5135b10bc2fb0fa085 Mon Sep 17 00:00:00 2001
From: Choom
Date: Mon, 9 Jan 2023 23:29:31 -0300
Subject: Arreglando borrado
---
cgi/api.py | 3 +-
cgi/post.py | 71 ++++++++++++++++++++++++++++++----
cgi/templates/mobile/base_top.html | 2 +-
cgi/templates/txt_board.en.html | 8 ++--
cgi/templates/txt_board.html | 6 +--
cgi/templates/txt_thread.html | 4 +-
cgi/weabot.py | 78 ++++----------------------------------
static/css/txt/bbs.css | 1 -
static/js/mobile.js | 19 +++-------
static/js/weabotxt.js | 4 +-
10 files changed, 89 insertions(+), 107 deletions(-)
diff --git a/cgi/api.py b/cgi/api.py
index 7b8b6bd..871e88f 100644
--- a/cgi/api.py
+++ b/cgi/api.py
@@ -6,7 +6,6 @@ from framework import *
from database import *
from post import *
-
def api(self, path_split):
if len(path_split) > 2:
try:
@@ -356,7 +355,7 @@ def api_process(self, path_split):
if data_imageonly and data_imageonly == 1:
imageonly = True
- deletePost(postid, data_password, board['recyclebin'], imageonly)
+ deletePosts(board['dir'], postid, imageonly, data_password)
elif method == 'post':
boarddir = formdata.get('board')
diff --git a/cgi/post.py b/cgi/post.py
index b7efef1..c53e8a1 100644
--- a/cgi/post.py
+++ b/cgi/post.py
@@ -56,7 +56,7 @@ class Post(object):
return self.post
def insert(self):
- logging.info("Insertando Post")
+ logging.info("Insertando post")
post_keys = []
post_templates = []
post_values = []
@@ -694,7 +694,63 @@ def regenerateBoard(everything=False):
for post in op_posts:
regenerateThreadPage(post["id"])
-def deletePost(postid, password, deltype=0, imageonly=False, quick=False):
+def deletePosts(boarddir, postid, imageonly, password):
+ board = setBoard(boarddir)
+
+ # validate posts
+ if not postid:
+ raise UserError("Selecciona uno o más mensajes a eliminar.")
+
+ to_delete = []
+ if isinstance(postid, list):
+ to_delete = [int(n.value) for n in postid]
+ else:
+ to_delete = [int(postid)]
+
+ if not password:
+ raise UserError(_("Please enter a password."))
+
+ # delete posts
+ if board['board_type'] == 1 and len(to_delete) == 1:
+ # only delete a single post on textboards
+ # check if it's the last post and delete permanently if so
+ deltype = 0
+
+ post = FetchOne("SELECT id, timestamp, parentid FROM posts WHERE boardid = %s AND id = %s LIMIT 1", (board["id"], to_delete[0]) )
+ if not post:
+ raise UserError(_("There isn't a post with this ID. It was probably deleted."))
+
+ if post['parentid']:
+ op = get_parent_post(post['parentid'], board['id'])
+ if op['last'] != post['timestamp']:
+ deltype = 1
+
+ deletePost(to_delete[0], password, deltype, imageonly)
+ regenerateHome()
+ else:
+ # delete all checked posts on imageboards
+ deleted = 0
+ errors = 0
+ msgs = []
+
+ for pid in to_delete:
+ try:
+ deletePost(pid, password, board['recyclebin'], imageonly)
+ deleted += 1
+ msgs.append('No.%d: Eliminado' % pid)
+ except UserError as message:
+ errors += 1
+ msgs.append('No.%d: %s' % (pid, message))
+
+ # regenerate home
+ if deleted:
+ regenerateHome()
+
+ # show errors, if any
+ if errors:
+ raise UserError('No se pudieron eliminar todos los posts.
' + '
'.join(msgs))
+
+def deletePost(postid, password, deltype=0, imageonly=False):
"""
Remove post from database and unlink file (if present), along with all replies
if supplied post is a thread
@@ -705,7 +761,7 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False):
postid = int(postid)
# get post
- post = FetchOne("SELECT `id`, `timestamp`, `parentid`, `file`, `thumb`, `password`, `length` FROM `posts` WHERE `boardid` = %s AND `id` = %s LIMIT 1", (board["id"], postid))
+ post = FetchOne("SELECT `id`, `timestamp`, `parentid`, `file`, `thumb`, `password`, `length` FROM `posts` WHERE `boardid` = %s AND `id` = %s LIMIT 1", (board["id"], postid) )
# abort if the post doesn't exist
if not post:
@@ -713,13 +769,12 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False):
if password:
if password != post['password']:
- raise UserError("No tienes permiso para eliminar este mensaje.")
+ raise UserError("No tienes permiso para eliminar este post.")
elif not post["parentid"] and post["length"] >= Settings.DELETE_FORBID_LENGTH:
raise UserError("No puedes eliminar un hilo con tantas respuestas.")
elif (int(time.time()) - post["timestamp"]) > 86400:
raise UserError("No puedes eliminar un post tan viejo.")
- # just update the DB if deleting only the image, otherwise delete whole post
if imageonly:
if post["file"]:
deleteFile(post)
@@ -729,14 +784,14 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False):
if not post["parentid"]:
deleteReplies(post)
- logging.info("Deleting post %d - parentid: %d" % (post["id"], post["parentid"]))
+ logging.debug("Deleting post %d - parentid: %d" % (post["id"], post["parentid"]))
if deltype != 0 and post["parentid"]:
# Soft delete (recycle bin)
- logging.info("Soft delete")
+ logging.debug("Soft delete")
UpdateDb("UPDATE `posts` SET `IS_DELETED` = %s WHERE `boardid` = %s AND `id` = %s LIMIT 1", (deltype, board["id"], post["id"]))
else:
# Hard delete
- logging.info("Hard delete")
+ logging.debug("Hard delete")
if post["file"]:
deleteFile(post)
diff --git a/cgi/templates/mobile/base_top.html b/cgi/templates/mobile/base_top.html
index aa016a4..bc4e680 100644
--- a/cgi/templates/mobile/base_top.html
+++ b/cgi/templates/mobile/base_top.html
@@ -10,5 +10,5 @@
-
+
diff --git a/cgi/templates/txt_board.en.html b/cgi/templates/txt_board.en.html
index 9327c77..ff101b5 100644
--- a/cgi/templates/txt_board.en.html
+++ b/cgi/templates/txt_board.en.html
@@ -86,10 +86,10 @@