diff --git a/log.py b/#log.py similarity index 51% rename from log.py rename to #log.py index e5d8ef4..a60e836 100644 --- a/log.py +++ b/#log.py @@ -1,27 +1,38 @@ import os from datetime import datetime -output = True +import config +output = config.debug + +waring = "waring" +error = "error" +info = "info" class Logger: def __init__(self): self.log_file = 'log.log' 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): 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') log_entry = f"{timestamp} [{log_type}] : {content}\n" @@ -31,18 +42,13 @@ class Logger: # 控制台输出 if output: - color = self._get_color_code(log_type) - reset = '\033[0m' - print(f"{timestamp} {color}[{log_type}] {content}") # <<< ------------------------------ + color = self._color(log_type) + print(f"{timestamp} {color} {content}") return True + # 外部调用接口 def write_log(content, log_type='info'): logger = Logger() return logger.log(content, log_type) - - -write_log('ddddasdaw') -write_log('waddddddddd', 'waring') -write_log('awdaaaaaargtsssssssss', 'error') diff --git a/file.py b/file.py index c64bd89..be04311 100644 --- a/file.py +++ b/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[ - Any] | int: - """ - 获取目录内容列表(包含文件/文件夹信息) - 返回格式: [ - { - 'name': 名称, - 'type': ''或'', - 'size': 文件大小(字节),文件夹为None, - 'create_time': 创建时间 - }, - ... - ] - """ +def get_file_list(dir_path: str) -> None | list[dict[str, str | int | None | Any] | dict[str, str | int]] | list[Any] | int: + try: if os.path.isfile(dir_path): return 1 diff --git a/main.py b/main.py index e4135f5..f5414d4 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,17 @@ from datetime import datetime +import config + from flask import Flask, render_template, request, send_file, jsonify, abort import make_html import return_api -import config -import log + app = Flask(__name__) +application = app +root = config.root + -root = config.getroot() @app.route('/') def home(): @@ -22,7 +25,7 @@ def webs(subpath=None): request_time = datetime.now() formatted_time = request_time.strftime('%Y-%m-%d %H:%M:%S') if subpath == "serviceworker.js": - abort(204) + abort(404) if subpath is None: p = root @@ -42,6 +45,7 @@ def webs(subpath=None): return return_p + @app.route("/api/") @app.route('/api') @app.route('/api/') @@ -49,7 +53,7 @@ def api(subpath=None): request_time = datetime.now() formatted_time = request_time.strftime('%Y-%m-%d %H:%M:%S') if subpath == "serviceworker.js": - abort(204) + abort(404) if subpath is None: p = root @@ -71,4 +75,5 @@ def api(subpath=None): if __name__ == '__main__': - app.run(debug=config.getdebug(), port=config.getport()) + app.run(debug=config.debug, port=config.port) + diff --git a/templates/index.html b/templates/index.html index 7ecfd2e..07ad423 100644 --- a/templates/index.html +++ b/templates/index.html @@ -15,7 +15,7 @@

  api 请求: api


-

by Da_nuo & branulf | 2025 +

Powered by Da_nuo | 2025

\ No newline at end of file diff --git a/templates/zh_ch_moban.html b/templates/zh_ch_moban.html index daf2a47..ac2b3bc 100644 --- a/templates/zh_ch_moban.html +++ b/templates/zh_ch_moban.html @@ -20,9 +20,9 @@

当前路径: {h3}


-

请求开始时间: {time}

-

文件(夹)数量: {file_var}

-

服务器内部路径: {server_path}

+

请求开始时间: {time}

+

文件(夹)数量: {file_var}

+

服务器内部路径: {server_path}

返回上一级目录