日常更新
This commit is contained in:
parent
e616007326
commit
9b56e84a6f
@ -1,27 +1,38 @@
|
|||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
output = True
|
import config
|
||||||
|
|
||||||
|
output = config.debug
|
||||||
|
|
||||||
|
waring = "waring"
|
||||||
|
error = "error"
|
||||||
|
info = "info"
|
||||||
|
|
||||||
class Logger:
|
class Logger:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.log_file = 'log.log'
|
self.log_file = 'log.log'
|
||||||
self._ensure_log_file_exists()
|
self._ensure_log_file_exists()
|
||||||
|
|
||||||
|
def _color(self, log_type):
|
||||||
|
a = ""
|
||||||
|
if log_type == "waring":
|
||||||
|
a = "\033[33m[waring]\033[0m ->"
|
||||||
|
elif log_type == "error":
|
||||||
|
a = "\033[31m[error] \033[0m ->"
|
||||||
|
elif log_type == "info":
|
||||||
|
a = "\033[36m[info] \033[0m ->"
|
||||||
|
else:
|
||||||
|
a = "\033[38m"
|
||||||
|
return a
|
||||||
|
|
||||||
def _ensure_log_file_exists(self):
|
def _ensure_log_file_exists(self):
|
||||||
if not os.path.exists(self.log_file):
|
if not os.path.exists(self.log_file):
|
||||||
with open(self.log_file, 'w'): pass
|
with open(self.log_file, 'w'):
|
||||||
|
pass
|
||||||
|
|
||||||
def _get_color_code(self, log_type):
|
|
||||||
colors = {
|
|
||||||
'info ': '\033[36m', # 蓝色
|
|
||||||
'waring': '\033[33m', # 黄色
|
|
||||||
'error ': '\033[31m' # 红色
|
|
||||||
}
|
|
||||||
return colors.get(log_type, '\033[0m')
|
|
||||||
|
|
||||||
def log(self, content, log_type='info'):
|
def log(self, content, log_type):
|
||||||
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||||
log_entry = f"{timestamp} [{log_type}] : {content}\n"
|
log_entry = f"{timestamp} [{log_type}] : {content}\n"
|
||||||
|
|
||||||
@ -31,18 +42,13 @@ class Logger:
|
|||||||
|
|
||||||
# 控制台输出
|
# 控制台输出
|
||||||
if output:
|
if output:
|
||||||
color = self._get_color_code(log_type)
|
color = self._color(log_type)
|
||||||
reset = '\033[0m'
|
print(f"{timestamp} {color} {content}")
|
||||||
print(f"{timestamp} {color}[{log_type}] {content}") # <<< ------------------------------
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 外部调用接口
|
# 外部调用接口
|
||||||
def write_log(content, log_type='info'):
|
def write_log(content, log_type='info'):
|
||||||
logger = Logger()
|
logger = Logger()
|
||||||
return logger.log(content, log_type)
|
return logger.log(content, log_type)
|
||||||
|
|
||||||
|
|
||||||
write_log('ddddasdaw')
|
|
||||||
write_log('waddddddddd', 'waring')
|
|
||||||
write_log('awdaaaaaargtsssssssss', 'error')
|
|
16
file.py
16
file.py
@ -4,20 +4,8 @@ from typing import Any
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_file_list(dir_path: str) -> None | list[dict[str, str | int | None | Any] | dict[str, str | int]] | list[
|
def get_file_list(dir_path: str) -> None | list[dict[str, str | int | None | Any] | dict[str, str | int]] | list[Any] | int:
|
||||||
Any] | int:
|
|
||||||
"""
|
|
||||||
获取目录内容列表(包含文件/文件夹信息)
|
|
||||||
返回格式: [
|
|
||||||
{
|
|
||||||
'name': 名称,
|
|
||||||
'type': '<dir>'或'<file>',
|
|
||||||
'size': 文件大小(字节),文件夹为None,
|
|
||||||
'create_time': 创建时间
|
|
||||||
},
|
|
||||||
...
|
|
||||||
]
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
if os.path.isfile(dir_path):
|
if os.path.isfile(dir_path):
|
||||||
return 1
|
return 1
|
||||||
|
17
main.py
17
main.py
@ -1,14 +1,17 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import config
|
||||||
|
|
||||||
|
|
||||||
from flask import Flask, render_template, request, send_file, jsonify, abort
|
from flask import Flask, render_template, request, send_file, jsonify, abort
|
||||||
import make_html
|
import make_html
|
||||||
import return_api
|
import return_api
|
||||||
import config
|
|
||||||
import log
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
application = app
|
||||||
|
root = config.root
|
||||||
|
|
||||||
|
|
||||||
root = config.getroot()
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def home():
|
def home():
|
||||||
@ -22,7 +25,7 @@ def webs(subpath=None):
|
|||||||
request_time = datetime.now()
|
request_time = datetime.now()
|
||||||
formatted_time = request_time.strftime('%Y-%m-%d %H:%M:%S')
|
formatted_time = request_time.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
if subpath == "serviceworker.js":
|
if subpath == "serviceworker.js":
|
||||||
abort(204)
|
abort(404)
|
||||||
|
|
||||||
if subpath is None:
|
if subpath is None:
|
||||||
p = root
|
p = root
|
||||||
@ -42,6 +45,7 @@ def webs(subpath=None):
|
|||||||
|
|
||||||
return return_p
|
return return_p
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/<path:subpath>")
|
@app.route("/api/<path:subpath>")
|
||||||
@app.route('/api')
|
@app.route('/api')
|
||||||
@app.route('/api/')
|
@app.route('/api/')
|
||||||
@ -49,7 +53,7 @@ def api(subpath=None):
|
|||||||
request_time = datetime.now()
|
request_time = datetime.now()
|
||||||
formatted_time = request_time.strftime('%Y-%m-%d %H:%M:%S')
|
formatted_time = request_time.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
if subpath == "serviceworker.js":
|
if subpath == "serviceworker.js":
|
||||||
abort(204)
|
abort(404)
|
||||||
|
|
||||||
if subpath is None:
|
if subpath is None:
|
||||||
p = root
|
p = root
|
||||||
@ -71,4 +75,5 @@ def api(subpath=None):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=config.getdebug(), port=config.getport())
|
app.run(debug=config.debug, port=config.port)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<p>  api 请求: <a href="api">api</a> </p>
|
<p>  api 请求: <a href="api">api</a> </p>
|
||||||
<hr>
|
<hr>
|
||||||
<center>
|
<center>
|
||||||
<p> by Da_nuo & branulf | 2025
|
<p>Powered by Da_nuo | 2025</p>
|
||||||
</center>
|
</center>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -20,9 +20,9 @@
|
|||||||
|
|
||||||
<h3>当前路径: {h3}</h3>
|
<h3>当前路径: {h3}</h3>
|
||||||
<hr>
|
<hr>
|
||||||
<p>请求开始时间: {time}</p> <!-- 开始时间 -->
|
<p>请求开始时间: {time}</p>
|
||||||
<p>文件(夹)数量: {file_var}</p> <!-- 文件,夹数量 -->
|
<p>文件(夹)数量: {file_var}</p>
|
||||||
<p>服务器内部路径: {server_path}</p> <!-- 服务器内部路径 -->
|
<p>服务器内部路径: {server_path}</p>
|
||||||
<a href="#" id="backLink" class="back-link">返回上一级目录</a>
|
<a href="#" id="backLink" class="back-link">返回上一级目录</a>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -50,7 +50,7 @@
|
|||||||
</table>
|
</table>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p align="center">Powered by Da_nuo & Branulf</p>
|
<p align="center">Powered by Da_nuo</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user