From d889e9297690f410679fe3fb749ccc7861ddd2eb Mon Sep 17 00:00:00 2001 From: MarkusJoe Date: Fri, 18 Feb 2022 20:18:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=95=BF=E5=BA=A6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 17 +++++++++-------- bin/utils/view.py | 6 +++++- db/count.db | Bin 12288 -> 12288 bytes 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index c22961f..8071500 100644 --- a/app.py +++ b/app.py @@ -37,13 +37,14 @@ def build_page(name: str, length: int, theme: str) -> list[bool or Response] or """ count = fetch_data(name) if len(str(count)) > length: # 判断在数据库内的长度是否超过了设定的(或预设的)长度 + print('sdadada') return [False, ErrorProcess().too_lang_to_count(name)] if 7 <= length <= 10: # 判断设定的长度是否超过阈值 zero_count = '0' * (length - len(str(count))) + str(count) status, template = view_template(theme, length, name, zero_count) - if status: + if status is True: return [True, template] - else: + elif status == 'BadTheme': return [False, 'BadTheme'] else: return [False, 'BadLength'] @@ -56,7 +57,7 @@ def requests_log() -> None: :return: """ if request.path != '/favicon.ico': # 不记录favicon.ico的请求记录 - logger.info(f'{request.host} {request.method} {request.path}') + logger.info(f'{request.host} {request.method} {request.full_path}') file_list = os.listdir('./static/cache') file_list.remove('.gitkeep') @@ -105,17 +106,17 @@ def main() -> Response or str: """ args = request.args name = str(args.get('name')).replace('None', 'null') - length = args.get('length') theme = args.get('theme') + length = args.get('length') + try: + length = int(length) + except ValueError: + return ErrorProcess().error_length(length) if theme == 'ls': return ErrorProcess().get_theme_list() if name and name != 'null': if not length: length = 7 - elif type(length) is not int: - return ErrorProcess().error_length(length) - else: - length = int(length) # 将类型转换为整型 if not theme: theme = 'lewd' build_page_result = build_page(name, length, theme) # 开始处理整体页面 diff --git a/bin/utils/view.py b/bin/utils/view.py index 8a68491..9c3cbde 100644 --- a/bin/utils/view.py +++ b/bin/utils/view.py @@ -7,11 +7,13 @@ import sqlite3 +from typing import Tuple from flask import render_template from db.sqlite import fetch_style_data +from db.sqlite import fetch_table -def view_template(style: str, length: int, name: str, count: str) -> tuple[bool, bool] or tuple[bool, str]: +def view_template(style: str, length: int, name: str, count: str) -> str or tuple[bool, bool] or tuple[bool, str]: """ 渲染模板 :param count: @@ -20,6 +22,8 @@ def view_template(style: str, length: int, name: str, count: str) -> tuple[bool, :param style: :return: """ + if style not in fetch_table(): + return 'BadLength' try: origin_data = fetch_style_data(style) # 获取数据库内的文件 except sqlite3.OperationalError: diff --git a/db/count.db b/db/count.db index d98248f4f5d40c58920f14949c1154e931667a9e..5d924c8ba299d63eb0618036f41c1fbbf901e174 100644 GIT binary patch delta 122 zcmZojXh@hK&A4Ntj5FhojR}kR#cnWg@GoWHf5`ud|0VxY{&W0C_;>QJ->fLm%P+#g z!Ys;|lUkm_#K8e%r4%QoNKD=-FE7adlYx^HB*DhWEXY`#;yU@IyfhaF{{aU6FZ`GI T4{YX9*u>8X)59_Oq`o--F-jz4 delta 97 zcmV-n0G|JVV1Qtd8v%5Y976$gv0$PP6!`!L54ivj;Scf;=?~Zs&JV;7xw9c4pAV5x z1e3WR9}x!x0~HBuWp`u-0Rs^Mb7UHm=^q;i2M@^r5A+YxvkoA#50Ov{lfW+olg%$P DEKeVb