Update sbx/b.py
Browse files
sbx/b.py
CHANGED
|
@@ -88,17 +88,23 @@ def get_log_content():
|
|
| 88 |
if not os.path.exists(file_path):
|
| 89 |
return jsonify({"error": "File not found"}), 404
|
| 90 |
|
| 91 |
-
#
|
| 92 |
with open(file_path, 'r', encoding='utf-8') as file:
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
except PermissionError:
|
| 99 |
return jsonify({"error": "Permission denied to read the file"}), 403
|
| 100 |
except Exception as e:
|
| 101 |
return jsonify({"error": str(e)}), 500
|
|
|
|
| 102 |
@app.route('/sub', methods=['GET'])
|
| 103 |
def get_sub_content():
|
| 104 |
try:
|
|
|
|
| 88 |
if not os.path.exists(file_path):
|
| 89 |
return jsonify({"error": "File not found"}), 404
|
| 90 |
|
| 91 |
+
# 读取最近的日志内容,限制大小
|
| 92 |
with open(file_path, 'r', encoding='utf-8') as file:
|
| 93 |
+
# 读取最后1000行
|
| 94 |
+
lines = file.readlines()[-1000:]
|
| 95 |
+
content = ''.join(lines)
|
| 96 |
+
|
| 97 |
+
# 处理中文和换行
|
| 98 |
+
return Response(
|
| 99 |
+
content,
|
| 100 |
+
mimetype='text/plain; charset=utf-8'
|
| 101 |
+
)
|
| 102 |
|
| 103 |
except PermissionError:
|
| 104 |
return jsonify({"error": "Permission denied to read the file"}), 403
|
| 105 |
except Exception as e:
|
| 106 |
return jsonify({"error": str(e)}), 500
|
| 107 |
+
|
| 108 |
@app.route('/sub', methods=['GET'])
|
| 109 |
def get_sub_content():
|
| 110 |
try:
|