diff options
Diffstat (limited to 'cgi/api.py')
-rw-r--r-- | cgi/api.py | 147 |
1 files changed, 72 insertions, 75 deletions
@@ -1,6 +1,5 @@ # coding=utf-8 import json -import _mysql import time from framework import * @@ -50,10 +49,10 @@ def api_process(self, path_split): 'SELECT dir, name, board_type, allow_images, allow_image_replies, maxsize FROM `boards` WHERE `secret`=0 ORDER BY `sort` ASC') values['boards'] = boards for board in values['boards']: - board['board_type'] = int(board['board_type']) - board['allow_images'] = int(board['allow_images']) - board['allow_image_replies'] = int(board['allow_image_replies']) - board['maxsize'] = int(board['maxsize']) + board['board_type'] = board['board_type'] + board['allow_images'] = board['allow_images'] + board['allow_image_replies'] = board['allow_image_replies'] + board['maxsize'] = board['maxsize'] elif method == 'last': data_limit = formdata.get('limit') @@ -82,15 +81,15 @@ def api_process(self, path_split): values['posts'] = FetchAll(sql) for post in values['posts']: - post['id'] = int(post['id']) - post['timestamp'] = int(post['timestamp']) - post['parentid'] = int(post['parentid']) - 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') + post['id'] = post['id'] + post['timestamp'] = post['timestamp'] + post['parentid'] = post['parentid'] + post['file_size'] = post['file_size'] + post['image_width'] = post['image_width'] + post['image_height'] = post['image_height'] + 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) @@ -154,28 +153,28 @@ def api_process(self, path_split): 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 %d" % ( - thread['id'], board['id'], numreplies)) + 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 = 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['id'] = thread['id'] + thread['timestamp'] = thread['timestamp'] + thread['bumped'] = thread['bumped'] + thread['expires'] = thread['expires'] + thread['total_replies'] = thread['total_replies'] + thread['total_files'] = thread['total_files'] + thread['file_size'] = thread['file_size'] + thread['image_width'] = thread['image_width'] + thread['image_height'] = thread['image_height'] + thread['thumb_width'] = thread['thumb_width'] + thread['thumb_height'] = thread['thumb_height'] + thread['locked'] = thread['locked'] thread['replies'] = [] for post in lastreplies: - post['IS_DELETED'] = int(post['IS_DELETED']) - post['id'] = int(post['id']) - post['timestamp'] = int(post['timestamp']) + post['IS_DELETED'] = post['IS_DELETED'] + post['id'] = post['id'] + post['timestamp'] = post['timestamp'] if post['IS_DELETED']: empty_post = {'id': post['id'], @@ -184,13 +183,12 @@ def api_process(self, path_split): } 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') + post['file_size'] = post['file_size'] + post['image_width'] = post['image_width'] + post['image_height'] = post['image_height'] + post['thumb_width'] = post['thumb_width'] + post['thumb_height'] = post['thumb_height'] + post['message'] = post['message'] thread['replies'].append(post) @@ -249,19 +247,19 @@ def api_process(self, path_split): if not op_post: raise APIError("Not a thread") - values['id'] = int(op_post['id']) - values['timestamp'] = int(op_post['timestamp']) + values['id'] = op_post['id'] + values['timestamp'] = op_post['timestamp'] values['subject'] = op_post['subject'] - values['locked'] = int(op_post['locked']) + values['locked'] = op_post['locked'] - total_replies = int(FetchOne("SELECT COUNT(1) FROM posts WHERE boardid = '%s' AND parentid = '%d'" % ( - board["id"], values['id']), 0)[0]) + total_replies = FetchOne("SELECT COUNT(1) AS count FROM posts WHERE boardid = %s AND parentid = %s", + (board["id"], values['id']))["count"] 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 %d OFFSET %d" % ( - _mysql.escape_string(board['id']), values['id'], values['id'], limit, offset) - posts = FetchAll(sql) + 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" + sqlv = (board['id'], values['id'], values['id'], limit, offset) + posts = FetchAll(sql, sqlv) values['posts'] = [] @@ -279,12 +277,12 @@ def api_process(self, path_split): } values['posts'].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') + post['file_size'] = post['file_size'] + post['image_width'] = post['image_width'] + post['image_height'] = post['image_height'] + post['thumb_width'] = post['thumb_width'] + post['thumb_height'] = post['thumb_height'] + post['message'] = post['message'] if striphtml: post['message'] = post['message'].replace("<br />", " ") post['message'] = re.compile( @@ -310,18 +308,18 @@ 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`='%d' AND boardid='%s'" % ( - postid, board["id"])) + 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" + (postid, board["id"])) if not post: raise APIError("Post ID cannot be found") values['posts'] = [] - post['IS_DELETED'] = int(post['IS_DELETED']) - post['id'] = int(post['id']) - post['parentid'] = int(post['parentid']) - post['timestamp'] = int(post['timestamp']) + post['IS_DELETED'] = post['IS_DELETED'] + post['id'] = post['id'] + post['parentid'] = post['parentid'] + post['timestamp'] = post['timestamp'] if post['IS_DELETED']: empty_post = {'id': post['id'], @@ -331,12 +329,12 @@ def api_process(self, path_split): } values['posts'].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') + post['file_size'] = post['file_size'] + post['image_width'] = post['image_width'] + post['image_height'] = post['image_height'] + post['thumb_width'] = post['thumb_width'] + post['thumb_height'] = post['thumb_height'] + post['message'] = post['message'] values['posts'].append(post) elif method == 'delete': data_board = formdata.get('dir') @@ -402,22 +400,21 @@ def api_process(self, path_split): threads = getNewThreads(limit) values['threads'] = threads elif method == "blotter": - latest_news = FetchAll( - "SELECT `timestamp`, `message`, `timestamp_formatted` FROM `news` WHERE `type` = '2' ORDER BY `timestamp` DESC LIMIT " + str(Settings.HOME_NEWS)) + latest_news = FetchAll("SELECT `timestamp`, `message`, `timestamp_formatted` FROM `news` WHERE `type` = '2' ORDER BY `timestamp` DESC LIMIT %s", (Settings.HOME_NEWS,)) values["news"] = latest_news elif method == 'boardsExtra': boards = FetchAll('SELECT dir, name, longname, subname, postarea_desc, postarea_extra, anonymous, subject, message, disable_name, disable_subject, allow_spoilers, allow_oekaki, numthreads, board_type, allow_images, allow_image_replies, maxsize FROM `boards` WHERE `secret`=0 ORDER BY `sort` ASC') values['boards'] = boards for board in values['boards']: - board['board_type'] = int(board['board_type']) - board['allow_images'] = int(board['allow_images']) - board['allow_image_replies'] = int(board['allow_image_replies']) - board['disable_name'] = int(board['disable_name']) - board['disable_subject'] = int(board['disable_subject']) - board['allow_spoilers'] = int(board['allow_spoilers']) - board['allow_oekaki'] = int(board['allow_oekaki']) - board['numthreads'] = int(board['numthreads']) - board['maxsize'] = int(board['maxsize']) + board['board_type'] = board['board_type'] + board['allow_images'] = board['allow_images'] + board['allow_image_replies'] = board['allow_image_replies'] + board['disable_name'] = board['disable_name'] + board['disable_subject'] = board['disable_subject'] + board['allow_spoilers'] = board['allow_spoilers'] + board['allow_oekaki'] = board['allow_oekaki'] + board['numthreads'] = board['numthreads'] + board['maxsize'] = board['maxsize'] else: raise APIError("Invalid method") |