From 3aee8f4033a760ce0422d75f74c47967fd4dc3c3 Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Fri, 6 Jun 2025 22:32:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=9B=BE=E5=83=8F?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E6=8E=A5=E5=8F=A3=E4=BB=A5=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E6=88=AA=E5=9B=BE=E8=AE=BF=E9=97=AE=E5=8A=9F=E8=83=BD=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8A=A5=E5=91=8A=E7=8A=B6=E6=80=81=E9=93=BE?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- report.py | 2 +- screenshots_flask.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/report.py b/report.py index 4b5397c..b0b1e5c 100644 --- a/report.py +++ b/report.py @@ -16,7 +16,7 @@ while True: logger.logger.info(f"name:{li['name_title']},link:{li['link']} ") try: info = d.process_ticket(li['name_title'], li['link']) - db.update_fight_record_status(li['id'], 2, info) + db.update_fight_record_status(li['id'], 2, f"http://123.58.197.91:5000/image/{info}") db.flush() time.sleep(5 * 60) except Exception as e: diff --git a/screenshots_flask.py b/screenshots_flask.py index e69de29..4406630 100644 --- a/screenshots_flask.py +++ b/screenshots_flask.py @@ -0,0 +1,28 @@ +from flask import Flask, send_file, abort +from pathlib import Path + +app = Flask(__name__) + +# 固定 screenshots 目录 +PROJECT_ROOT = Path(__file__).parent.resolve() +SCREENSHOTS_DIR = PROJECT_ROOT / "screenshots" + + +@app.route('/image/') +def serve_image(filename): + file_path = SCREENSHOTS_DIR / filename + + # 防止路径越界访问 + try: + file_path.resolve().relative_to(SCREENSHOTS_DIR.resolve()) + except ValueError: + abort(403, "禁止访问目录外文件") + + if not file_path.exists(): + abort(404, "文件不存在") + + return send_file(file_path, as_attachment=False) + + +if __name__ == '__main__': + app.run(host='0.0.0.0', debug=False, port=5000)