diff options
Diffstat (limited to 'cgi/api.py')
-rw-r--r-- | cgi/api.py | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -75,7 +75,7 @@ def api_process(self, path_split): if limit > 50: raise APIError("Maximum limit is 50") - sql = "SELECT posts.id, boards.dir, timestamp, timestamp_formatted, posts.name, tripcode, email, posts.subject, posts.message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, parentid FROM posts INNER JOIN boards ON boardid = boards.id WHERE timestamp > %d AND IS_DELETED = 0 AND boards.secret = 0 ORDER BY timestamp DESC LIMIT %d" % ( + sql = "SELECT posts.id, boards.dir, timestamp, timestamp_formatted, posts.name, tripcode, email, posterid, posts.subject, posts.message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, parentid FROM posts INNER JOIN boards ON boardid = boards.id WHERE timestamp > %d AND IS_DELETED = 0 AND boards.secret = 0 ORDER BY timestamp DESC LIMIT %d" % ( since, limit) values['posts'] = FetchAll(sql) @@ -89,6 +89,7 @@ def api_process(self, path_split): post['thumb_width'] = post['thumb_width'] post['thumb_height'] = post['thumb_height'] post['message'] = post['message'] + elif method == 'lastage': data_limit = formdata.get('limit') data_time = formdata.get('time', 0) @@ -110,6 +111,7 @@ def api_process(self, path_split): values['threads'] = threads else: values['threads'] = [] + elif method == 'list': data_board = formdata.get('dir') data_offset = formdata.get('offset') @@ -146,15 +148,14 @@ def api_process(self, path_split): 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 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 AND p.IS_DELETED = 0 ORDER BY `bumped` DESC LIMIT %(limit)d OFFSET %(offset)d" % { + sql = "SELECT p.id, p.timestamp, p.bumped, p.expires, p.expires_formatted, p.timestamp_formatted, p.name, p.tripcode, p.email, p.posterid, 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 AND p.IS_DELETED = 0 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 id, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, IS_DELETED FROM `posts` WHERE parentid = %s AND boardid = %s ORDER BY `timestamp` DESC LIMIT %s", - (thread['id'], board['id'], numreplies)) + lastreplies = FetchAll("SELECT id, timestamp, timestamp_formatted, name, tripcode, email, posterid, subject, message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, IS_DELETED FROM `posts` WHERE parentid = %s AND boardid = %s ORDER BY `timestamp` DESC LIMIT %s", (thread['id'], board['id'], numreplies)) lastreplies = lastreplies[::-1] thread['id'] = thread['id'] thread['timestamp'] = thread['timestamp'] @@ -193,6 +194,7 @@ def api_process(self, path_split): thread['replies'].append(post) values['threads'] = threads + elif method == 'thread': data_board = formdata.get('dir') data_threadid = formdata.get('id') @@ -257,7 +259,7 @@ def api_process(self, path_split): values['total_replies'] = total_replies - sql = "SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE boardid = %s AND (parentid = %s OR id = %s) ORDER BY id ASC LIMIT %s OFFSET %s" + sql = "SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, posterid, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE boardid = %s AND (parentid = %s OR id = %s) ORDER BY id ASC LIMIT %s OFFSET %s" sqlv = (board['id'], values['id'], values['id'], limit, offset) posts = FetchAll(sql, sqlv) @@ -288,6 +290,7 @@ def api_process(self, path_split): post['message'] = re.compile( r"<[^>]*?>", re.DOTALL | re.IGNORECASE).sub("", post['message']) values['posts'].append(post) + elif method == 'get': data_board = formdata.get('dir') data_parentid = formdata.get('thread') @@ -308,7 +311,7 @@ def api_process(self, path_split): except ValueError: raise APIError("Post ID must be numeric") - post = FetchOne("SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE `id` = %s AND boardid = %s" + post = FetchOne("SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, posterid, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE `id` = %s AND boardid = %s" (postid, board["id"])) if not post: |