Archived
修改了返回静态文件方式, 修改前的状态码为302 修改后为200
This commit is contained in:
5 files changed
+216
-217
No files matched your search
@@ -12,14 +12,13 @@ from flask import Flask
|
|||||||
from flask import request
|
from flask import request
|
||||||
from flask import Response
|
from flask import Response
|
||||||
from flask import make_response
|
from flask import make_response
|
||||||
from flask import send_from_directory
|
|
||||||
from flask import jsonify
|
from flask import jsonify
|
||||||
from bin.core.error import ErrorProcess
|
from bin.utils.error import ErrorProcess
|
||||||
from bin.core.render_ import render_temp_
|
from bin.utils.render_ import render_temp_
|
||||||
from bin.core.b64img import re_sort_number_image
|
from bin.utils.b64img import re_sort_number_image
|
||||||
from db.db import fetch_data
|
from db.db import fetch_data
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__, static_url_path='')
|
||||||
app.config['JSON_SORT_KEYS'] = False # 设置JSON消息不根据字母顺序重新排序
|
app.config['JSON_SORT_KEYS'] = False # 设置JSON消息不根据字母顺序重新排序
|
||||||
app.config['JSON_AS_ASCII'] = False # 设置JSON消息显示中文
|
app.config['JSON_AS_ASCII'] = False # 设置JSON消息显示中文
|
||||||
|
|
||||||
@@ -31,7 +30,7 @@ def miss(reason) -> Response:
|
|||||||
:param reason:
|
:param reason:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
return jsonify({'code': 404, 'msg': f'{reason}', 'data': []})
|
return jsonify({'code': 404, 'msg': f'{reason}', 'data': None})
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(500)
|
@app.errorhandler(500)
|
||||||
@@ -41,16 +40,7 @@ def error(reason) -> Response:
|
|||||||
:param reason:
|
:param reason:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
return jsonify({'code': 500, 'msg': f'{reason}', 'data': []})
|
return jsonify({'code': 500, 'msg': f'{reason}', 'data': None})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/favicon.ico', methods=['GET', 'POST'])
|
|
||||||
def favicon() -> Response:
|
|
||||||
"""
|
|
||||||
主页图标
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
return app.send_static_file('favicon.ico')
|
|
||||||
|
|
||||||
|
|
||||||
def build_page(name: str, length: int, theme: str) -> list[bool or Response] or list[bool or str] or bool:
|
def build_page(name: str, length: int, theme: str) -> list[bool or Response] or list[bool or str] or bool:
|
||||||
@@ -111,13 +101,22 @@ def api_page() -> Response or str:
|
|||||||
return ErrorProcess().arg_not_be_full()
|
return ErrorProcess().arg_not_be_full()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/favicon.ico', methods=['GET', 'POST'])
|
||||||
|
def favicon() -> Response:
|
||||||
|
"""
|
||||||
|
主页图标
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return app.send_static_file('favicon.ico')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def index() -> Response:
|
def index() -> Response:
|
||||||
"""
|
"""
|
||||||
索引页面
|
索引页面
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
return send_from_directory('./static', 'index.html')
|
return app.send_static_file('index.html')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -- coding:utf-8 --
|
# -- coding:utf-8 --
|
||||||
# @Author: markushammered@gmail.com
|
# @Author: markushammered@gmail.com
|
||||||
# @Development Tool: PyCharm
|
# @Development Tool: PyCharm
|
||||||
# @Create Time: 2022/2/5
|
# @Create Time: 2022/2/5
|
||||||
# @File Name: __init__.py.py
|
# @File Name: __init__.py.py
|
||||||
|
|
||||||
@@ -1,70 +1,70 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -- coding:utf-8 --
|
# -- coding:utf-8 --
|
||||||
# @Author: markushammered@gmail.com
|
# @Author: markushammered@gmail.com
|
||||||
# @Development Tool: PyCharm
|
# @Development Tool: PyCharm
|
||||||
# @Create Time: 2022/2/3
|
# @Create Time: 2022/2/3
|
||||||
# @File Name: b64img.py
|
# @File Name: b64img.py
|
||||||
|
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from db.db import fetch_table
|
from db.db import fetch_table
|
||||||
|
|
||||||
|
|
||||||
def re_sort_number_image(origin_number: str, theme: str) -> tuple[bool, bool, bool, bool] or list[
|
def re_sort_number_image(origin_number: str, theme: str) -> tuple[bool, bool, bool, bool] or list[
|
||||||
bool or list[Any] or Any]:
|
bool or list[Any] or Any]:
|
||||||
"""
|
"""
|
||||||
返回一个排列好的svg base64代码列表
|
返回一个排列好的svg base64代码列表
|
||||||
:param theme:
|
:param theme:
|
||||||
:param origin_number:
|
:param origin_number:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
table_list = fetch_table()
|
table_list = fetch_table()
|
||||||
if theme not in table_list:
|
if theme not in table_list:
|
||||||
return False, False, False, False
|
return False, False, False, False
|
||||||
|
|
||||||
width_list = []
|
width_list = []
|
||||||
height_list = []
|
height_list = []
|
||||||
b_64_list = []
|
b_64_list = []
|
||||||
cursor.execute('select * from %(name)s' % {'name': theme})
|
cursor.execute('select * from %(name)s' % {'name': theme})
|
||||||
data = cursor.fetchall()
|
data = cursor.fetchall()
|
||||||
for i in data:
|
for i in data:
|
||||||
width_list.append(i[2])
|
width_list.append(i[2])
|
||||||
height_list.append(i[3])
|
height_list.append(i[3])
|
||||||
b_64_list.append(i[1])
|
b_64_list.append(i[1])
|
||||||
|
|
||||||
final_b64_img_code = []
|
final_b64_img_code = []
|
||||||
if origin_number != '0000000000':
|
if origin_number != '0000000000':
|
||||||
for i in origin_number:
|
for i in origin_number:
|
||||||
if i == '0':
|
if i == '0':
|
||||||
final_b64_img_code.append(b_64_list[0])
|
final_b64_img_code.append(b_64_list[0])
|
||||||
elif i == '1':
|
elif i == '1':
|
||||||
final_b64_img_code.append(b_64_list[1])
|
final_b64_img_code.append(b_64_list[1])
|
||||||
elif i == '2':
|
elif i == '2':
|
||||||
final_b64_img_code.append(b_64_list[2])
|
final_b64_img_code.append(b_64_list[2])
|
||||||
elif i == '3':
|
elif i == '3':
|
||||||
final_b64_img_code.append(b_64_list[3])
|
final_b64_img_code.append(b_64_list[3])
|
||||||
elif i == '4':
|
elif i == '4':
|
||||||
final_b64_img_code.append(b_64_list[4])
|
final_b64_img_code.append(b_64_list[4])
|
||||||
elif i == '5':
|
elif i == '5':
|
||||||
final_b64_img_code.append(b_64_list[5])
|
final_b64_img_code.append(b_64_list[5])
|
||||||
elif i == '6':
|
elif i == '6':
|
||||||
final_b64_img_code.append(b_64_list[6])
|
final_b64_img_code.append(b_64_list[6])
|
||||||
elif i == '7':
|
elif i == '7':
|
||||||
final_b64_img_code.append(b_64_list[7])
|
final_b64_img_code.append(b_64_list[7])
|
||||||
elif i == '8':
|
elif i == '8':
|
||||||
final_b64_img_code.append(b_64_list[8])
|
final_b64_img_code.append(b_64_list[8])
|
||||||
elif i == '9':
|
elif i == '9':
|
||||||
final_b64_img_code.append(b_64_list[9])
|
final_b64_img_code.append(b_64_list[9])
|
||||||
|
|
||||||
return [True, final_b64_img_code, width_list[0], height_list[0]]
|
return [True, final_b64_img_code, width_list[0], height_list[0]]
|
||||||
else:
|
else:
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
final_b64_img_code.append(b_64_list[0])
|
final_b64_img_code.append(b_64_list[0])
|
||||||
return [True, final_b64_img_code, width_list[0], height_list[0]]
|
return [True, final_b64_img_code, width_list[0], height_list[0]]
|
||||||
|
|
||||||
|
|
||||||
if __name__ != '__main__':
|
if __name__ != '__main__':
|
||||||
conn = sqlite3.connect('./bin/assets/theme.db', check_same_thread=False)
|
conn = sqlite3.connect('./bin/assets/theme.db', check_same_thread=False)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
File renamed without changes.
@@ -1,123 +1,123 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -- coding:utf-8 --
|
# -- coding:utf-8 --
|
||||||
# @Author: markushammered@gmail.com
|
# @Author: markushammered@gmail.com
|
||||||
# @Development Tool: PyCharm
|
# @Development Tool: PyCharm
|
||||||
# @Create Time: 2022/2/5
|
# @Create Time: 2022/2/5
|
||||||
# @File Name: render_.py
|
# @File Name: render_.py
|
||||||
|
|
||||||
|
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
|
|
||||||
|
|
||||||
def render_temp_(length: int, name: str, image_list: list, width: int, height: int) -> str:
|
def render_temp_(length: int, name: str, image_list: list, width: int, height: int) -> str:
|
||||||
"""
|
"""
|
||||||
代码很烂写到隐蔽的地方就看不见了
|
代码很烂写到隐蔽的地方就看不见了
|
||||||
:param height:
|
:param height:
|
||||||
:param width:
|
:param width:
|
||||||
:param length:
|
:param length:
|
||||||
:param name:
|
:param name:
|
||||||
:param image_list:
|
:param image_list:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
position_list = []
|
position_list = []
|
||||||
for i in range(0, length):
|
for i in range(0, length):
|
||||||
position_list.append(i * width)
|
position_list.append(i * width)
|
||||||
file_name = f'index{length}.html'
|
file_name = f'index{length}.html'
|
||||||
|
|
||||||
# 自己写的都看不下去了
|
# 自己写的都看不下去了
|
||||||
if length == 7:
|
if length == 7:
|
||||||
return render_template(file_name,
|
return render_template(file_name,
|
||||||
title=name,
|
title=name,
|
||||||
g_width=length * width,
|
g_width=length * width,
|
||||||
width=width,
|
width=width,
|
||||||
height=height,
|
height=height,
|
||||||
x_position_0=position_list[0],
|
x_position_0=position_list[0],
|
||||||
x_position_1=position_list[1],
|
x_position_1=position_list[1],
|
||||||
x_position_2=position_list[2],
|
x_position_2=position_list[2],
|
||||||
x_position_3=position_list[3],
|
x_position_3=position_list[3],
|
||||||
x_position_4=position_list[4],
|
x_position_4=position_list[4],
|
||||||
x_position_5=position_list[5],
|
x_position_5=position_list[5],
|
||||||
x_position_6=position_list[6],
|
x_position_6=position_list[6],
|
||||||
svg_img_0=f'{image_list[0]}',
|
svg_img_0=f'{image_list[0]}',
|
||||||
svg_img_1=f'{image_list[1]}',
|
svg_img_1=f'{image_list[1]}',
|
||||||
svg_img_2=f'{image_list[2]}',
|
svg_img_2=f'{image_list[2]}',
|
||||||
svg_img_3=f'{image_list[3]}',
|
svg_img_3=f'{image_list[3]}',
|
||||||
svg_img_4=f'{image_list[4]}',
|
svg_img_4=f'{image_list[4]}',
|
||||||
svg_img_5=f'{image_list[5]}',
|
svg_img_5=f'{image_list[5]}',
|
||||||
svg_img_6=f'{image_list[6]}'
|
svg_img_6=f'{image_list[6]}'
|
||||||
)
|
)
|
||||||
elif length == 8:
|
elif length == 8:
|
||||||
return render_template(file_name,
|
return render_template(file_name,
|
||||||
title=name,
|
title=name,
|
||||||
g_width=length * width,
|
g_width=length * width,
|
||||||
width=width,
|
width=width,
|
||||||
height=height,
|
height=height,
|
||||||
x_position_0=position_list[0],
|
x_position_0=position_list[0],
|
||||||
x_position_1=position_list[1],
|
x_position_1=position_list[1],
|
||||||
x_position_2=position_list[2],
|
x_position_2=position_list[2],
|
||||||
x_position_3=position_list[3],
|
x_position_3=position_list[3],
|
||||||
x_position_4=position_list[4],
|
x_position_4=position_list[4],
|
||||||
x_position_5=position_list[5],
|
x_position_5=position_list[5],
|
||||||
x_position_6=position_list[6],
|
x_position_6=position_list[6],
|
||||||
x_position_7=position_list[7],
|
x_position_7=position_list[7],
|
||||||
svg_img_0=f'{image_list[0]}',
|
svg_img_0=f'{image_list[0]}',
|
||||||
svg_img_1=f'{image_list[1]}',
|
svg_img_1=f'{image_list[1]}',
|
||||||
svg_img_2=f'{image_list[2]}',
|
svg_img_2=f'{image_list[2]}',
|
||||||
svg_img_3=f'{image_list[3]}',
|
svg_img_3=f'{image_list[3]}',
|
||||||
svg_img_4=f'{image_list[4]}',
|
svg_img_4=f'{image_list[4]}',
|
||||||
svg_img_5=f'{image_list[5]}',
|
svg_img_5=f'{image_list[5]}',
|
||||||
svg_img_6=f'{image_list[6]}',
|
svg_img_6=f'{image_list[6]}',
|
||||||
svg_img_7=f'{image_list[7]}'
|
svg_img_7=f'{image_list[7]}'
|
||||||
)
|
)
|
||||||
elif length == 9:
|
elif length == 9:
|
||||||
return render_template(file_name,
|
return render_template(file_name,
|
||||||
title=name,
|
title=name,
|
||||||
g_width=length * width,
|
g_width=length * width,
|
||||||
width=width,
|
width=width,
|
||||||
height=height,
|
height=height,
|
||||||
x_position_0=position_list[0],
|
x_position_0=position_list[0],
|
||||||
x_position_1=position_list[1],
|
x_position_1=position_list[1],
|
||||||
x_position_2=position_list[2],
|
x_position_2=position_list[2],
|
||||||
x_position_3=position_list[3],
|
x_position_3=position_list[3],
|
||||||
x_position_4=position_list[4],
|
x_position_4=position_list[4],
|
||||||
x_position_5=position_list[5],
|
x_position_5=position_list[5],
|
||||||
x_position_6=position_list[6],
|
x_position_6=position_list[6],
|
||||||
x_position_7=position_list[7],
|
x_position_7=position_list[7],
|
||||||
x_position_8=position_list[8],
|
x_position_8=position_list[8],
|
||||||
svg_img_0=f'{image_list[0]}',
|
svg_img_0=f'{image_list[0]}',
|
||||||
svg_img_1=f'{image_list[1]}',
|
svg_img_1=f'{image_list[1]}',
|
||||||
svg_img_2=f'{image_list[2]}',
|
svg_img_2=f'{image_list[2]}',
|
||||||
svg_img_3=f'{image_list[3]}',
|
svg_img_3=f'{image_list[3]}',
|
||||||
svg_img_4=f'{image_list[4]}',
|
svg_img_4=f'{image_list[4]}',
|
||||||
svg_img_5=f'{image_list[5]}',
|
svg_img_5=f'{image_list[5]}',
|
||||||
svg_img_6=f'{image_list[6]}',
|
svg_img_6=f'{image_list[6]}',
|
||||||
svg_img_7=f'{image_list[7]}',
|
svg_img_7=f'{image_list[7]}',
|
||||||
svg_img_8=f'{image_list[8]}',
|
svg_img_8=f'{image_list[8]}',
|
||||||
)
|
)
|
||||||
elif length == 10:
|
elif length == 10:
|
||||||
return render_template(file_name,
|
return render_template(file_name,
|
||||||
title=name,
|
title=name,
|
||||||
g_width=length * width,
|
g_width=length * width,
|
||||||
width=width,
|
width=width,
|
||||||
height=height,
|
height=height,
|
||||||
x_position_0=position_list[0],
|
x_position_0=position_list[0],
|
||||||
x_position_1=position_list[1],
|
x_position_1=position_list[1],
|
||||||
x_position_2=position_list[2],
|
x_position_2=position_list[2],
|
||||||
x_position_3=position_list[3],
|
x_position_3=position_list[3],
|
||||||
x_position_4=position_list[4],
|
x_position_4=position_list[4],
|
||||||
x_position_5=position_list[5],
|
x_position_5=position_list[5],
|
||||||
x_position_6=position_list[6],
|
x_position_6=position_list[6],
|
||||||
x_position_7=position_list[7],
|
x_position_7=position_list[7],
|
||||||
x_position_8=position_list[8],
|
x_position_8=position_list[8],
|
||||||
x_position_9=position_list[9],
|
x_position_9=position_list[9],
|
||||||
svg_img_0=f'{image_list[0]}',
|
svg_img_0=f'{image_list[0]}',
|
||||||
svg_img_1=f'{image_list[1]}',
|
svg_img_1=f'{image_list[1]}',
|
||||||
svg_img_2=f'{image_list[2]}',
|
svg_img_2=f'{image_list[2]}',
|
||||||
svg_img_3=f'{image_list[3]}',
|
svg_img_3=f'{image_list[3]}',
|
||||||
svg_img_4=f'{image_list[4]}',
|
svg_img_4=f'{image_list[4]}',
|
||||||
svg_img_5=f'{image_list[5]}',
|
svg_img_5=f'{image_list[5]}',
|
||||||
svg_img_6=f'{image_list[6]}',
|
svg_img_6=f'{image_list[6]}',
|
||||||
svg_img_7=f'{image_list[7]}',
|
svg_img_7=f'{image_list[7]}',
|
||||||
svg_img_8=f'{image_list[8]}',
|
svg_img_8=f'{image_list[8]}',
|
||||||
svg_img_9=f'{image_list[9]}'
|
svg_img_9=f'{image_list[9]}'
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user