Update sbx/b.py
Browse files
sbx/b.py
CHANGED
|
@@ -17,6 +17,27 @@ def greet():
|
|
| 17 |
name = data.get('name', 'Guest')
|
| 18 |
return jsonify({"greeting": f"Hello, {name}!"})
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
@app.route('/sub', methods=['GET'])
|
| 21 |
def get_sub_content():
|
| 22 |
try:
|
|
|
|
| 17 |
name = data.get('name', 'Guest')
|
| 18 |
return jsonify({"greeting": f"Hello, {name}!"})
|
| 19 |
|
| 20 |
+
@app.route('/log', methods=['GET'])
|
| 21 |
+
def get_sub_content():
|
| 22 |
+
try:
|
| 23 |
+
# 使用绝对路径读取文件
|
| 24 |
+
file_path = '/data/server10.log'
|
| 25 |
+
|
| 26 |
+
# 检查文件是否存在
|
| 27 |
+
if not os.path.exists(file_path):
|
| 28 |
+
return jsonify({"error": "File not found"}), 404
|
| 29 |
+
|
| 30 |
+
# 读取文件内容
|
| 31 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 32 |
+
content = file.read()
|
| 33 |
+
|
| 34 |
+
# return jsonify({"content": content})
|
| 35 |
+
return content
|
| 36 |
+
|
| 37 |
+
except PermissionError:
|
| 38 |
+
return jsonify({"error": "Permission denied to read the file"}), 403
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return jsonify({"error": str(e)}), 500
|
| 41 |
@app.route('/sub', methods=['GET'])
|
| 42 |
def get_sub_content():
|
| 43 |
try:
|