aboutsummaryrefslogtreecommitdiff
path: root/cgi
diff options
context:
space:
mode:
authorLibravatar Renard 2020-08-08 13:58:37 -0400
committerLibravatar Renard 2020-08-08 13:58:37 -0400
commit07eca7f8eadaa3e2cae64d810be40efafbe80768 (patch)
tree41edb9b18f9142a6a3c6dd0a835c6fa8810ae2d1 /cgi
parentf70b47226f07d430ba67d0ff3d8583c10c2ecad6 (diff)
downloadweabot-07eca7f8eadaa3e2cae64d810be40efafbe80768.tar.gz
weabot-07eca7f8eadaa3e2cae64d810be40efafbe80768.tar.xz
weabot-07eca7f8eadaa3e2cae64d810be40efafbe80768.zip
Mod API: threadlist
Diffstat (limited to 'cgi')
-rw-r--r--cgi/modapi.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/cgi/modapi.py b/cgi/modapi.py
index c6fca39..44c1746 100644
--- a/cgi/modapi.py
+++ b/cgi/modapi.py
@@ -88,6 +88,7 @@ def api_process(self, path_split):
post['locked'] = int(post['locked'])
post['parentid'] = int(post['parentid'])
post['timestamp'] = int(post['timestamp'])
+ post['boardid'] = int(post['boardid'])
values['post'] = post
if 'parentid' in formdata.keys():
id = formdata.get('parentid')
@@ -101,7 +102,92 @@ def api_process(self, path_split):
post['locked'] = int(post['locked'])
post['parentid'] = int(post['parentid'])
post['timestamp'] = int(post['timestamp'])
+ post['boardid'] = int(post['boardid'])
values['posts'] = posts
+ elif method == 'threadlist':
+ data_board = formdata.get('dir')
+ data_offset = formdata.get('offset')
+ data_limit = formdata.get('limit')
+ data_replies = formdata.get('replies')
+ offset = 0
+ limit = 50
+ numreplies = 2
+
+ if not data_board:
+ raise APIError, "Missing parameters"
+
+ if data_limit:
+ try:
+ limit = int(data_limit)
+ except ValueError:
+ raise APIError, "Limit must be numeric"
+
+ if data_offset:
+ try:
+ offset = int(data_offset)
+ except ValueError:
+ raise APIError, "Offset must be numeric"
+
+ if data_replies:
+ try:
+ numreplies = int(data_replies)
+ except ValueError:
+ raise APIError, "Replies must be numeric"
+
+ if data_replies and limit > 30:
+ raise APIError, "Maximum limit is 30"
+
+ board = setBoard(data_board)
+
+ #sql = "SELECT id, timestamp, bumped, timestamp_formatted, name, tripcode, email, subject, message, file, thumb FROM posts WHERE boardid = %s AND parentid = 0 AND IS_DELETED = 0 ORDER BY bumped DESC LIMIT %d" % (board['id'], limit)
+ sql = "SELECT INET6_NTOA(p.ip) AS p.ip, p.IS_DELETED AS p.deleted, p.id, p.timestamp, p.bumped, p.expires, p.expires_formatted, p.timestamp_formatted, p.name, p.tripcode, p.email, p.subject, p.message, p.file, p.file_size, p.image_width, p.image_height, p.thumb, p.thumb_height, p.thumb_width, p.locked, coalesce(x.count,0) AS total_replies, coalesce(x.files,0) AS total_files FROM `posts` AS p LEFT JOIN (SELECT parentid, count(1) as count, count(nullif(file, '')) as files FROM `posts` WHERE boardid = %(board)s GROUP BY parentid) AS x ON p.id=x.parentid WHERE p.parentid = 0 AND p.boardid = %(board)s ORDER BY `bumped` DESC LIMIT %(limit)d OFFSET %(offset)d" % {
+ 'board': board["id"], 'limit': limit, 'offset': offset}
+
+ threads = FetchAll(sql)
+
+ if numreplies:
+ for thread in threads:
+ lastreplies = FetchAll("SELECT INET6_NTOA(ip) AS ip, id, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, IS_DELETED AS deleted FROM `posts` WHERE parentid = %s AND boardid = %s ORDER BY `timestamp` DESC LIMIT %d" % (
+ thread['id'], board['id'], numreplies))
+ lastreplies = lastreplies[::-1]
+ thread['id'] = int(thread['id'])
+ thread['timestamp'] = int(thread['timestamp'])
+ thread['bumped'] = int(thread['bumped'])
+ thread['expires'] = int(thread['expires'])
+ thread['total_replies'] = int(thread['total_replies'])
+ thread['total_files'] = int(thread['total_files'])
+ thread['file_size'] = int(thread['file_size'])
+ thread['image_width'] = int(thread['image_width'])
+ thread['image_height'] = int(thread['image_height'])
+ thread['thumb_width'] = int(thread['thumb_width'])
+ thread['thumb_height'] = int(thread['thumb_height'])
+ thread['locked'] = int(thread['locked'])
+
+ thread['replies'] = []
+
+ for post in lastreplies:
+ post['deleted'] = int(post['IS_DELETED'])
+ post['id'] = int(post['id'])
+ post['timestamp'] = int(post['timestamp'])
+
+ if post['deleted']:
+ empty_post = {'id': post['id'],
+ 'deleted': post['deleted'],
+ 'timestamp': post['timestamp'],
+ }
+ thread['replies'].append(empty_post)
+ else:
+ post['file_size'] = int(post['file_size'])
+ post['image_width'] = int(post['image_width'])
+ post['image_height'] = int(post['image_height'])
+ post['thumb_width'] = int(post['thumb_width'])
+ post['thumb_height'] = int(post['thumb_height'])
+ post['message'] = post['message'].decode(
+ 'utf-8', 'replace')
+
+ thread['replies'].append(post)
+
+ values['threads'] = threads
elif method == 'reports':
if len(path_split) > 3:
if path_split[3] == 'ignore':