refactor(torrent): 优化种子文件服务和相关配置
- 修改文件重命名逻辑,移除空格和连字符处理 - 更新UI端口依赖从 sass-embedded 到 sass - 调整请求基础URL配置为局域网地址 - 重构后端运行配置以支持外部访问 - 添加种子列表路由和提取名称功能 - 移除按名称查询单个种子的路由 - 实现标准化名称提取算法 - 添加批量获取所有种子的功能
This commit is contained in:
@@ -1,10 +1,16 @@
|
|||||||
from flask import Blueprint, jsonify
|
from flask import Blueprint, jsonify, request
|
||||||
|
|
||||||
from app.services.torrent_service import TorrentService
|
from app.services.torrent_service import TorrentService
|
||||||
|
|
||||||
bp = Blueprint("torrent", __name__)
|
bp = Blueprint("torrent", __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/')
|
||||||
|
def torrent_list():
|
||||||
|
torrent_object = TorrentService(["C:\\Users\\Localhost\\Desktop\\BT"])
|
||||||
|
return jsonify({"code": 200, "message": torrent_object.get_all()})
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/deduplication')
|
@bp.route('/deduplication')
|
||||||
def torrent_deduplication():
|
def torrent_deduplication():
|
||||||
torrent_object = TorrentService(["C:\\Users\\Localhost\\Desktop\\BT"])
|
torrent_object = TorrentService(["C:\\Users\\Localhost\\Desktop\\BT"])
|
||||||
@@ -15,14 +21,3 @@ def torrent_deduplication():
|
|||||||
def torrent_statistics():
|
def torrent_statistics():
|
||||||
torrent_object = TorrentService(["C:\\Users\\Localhost\\Desktop\\BT"])
|
torrent_object = TorrentService(["C:\\Users\\Localhost\\Desktop\\BT"])
|
||||||
return jsonify({"code": 200, "message": torrent_object.statistics()})
|
return jsonify({"code": 200, "message": torrent_object.statistics()})
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/<name>")
|
|
||||||
def torrent_by_name(name):
|
|
||||||
torrent_object = TorrentService(["C:\\Users\\Localhost\\Desktop\\BT"])
|
|
||||||
return jsonify({"code": 200, "message": torrent_object.get_by_name(name)})
|
|
||||||
|
|
||||||
# @bp.route("/extract/name")
|
|
||||||
# def torrent_extract_name():
|
|
||||||
# torrent_object = TorrentService([])
|
|
||||||
# return jsonify({"code": 200, "message": torrent_object.extract_name("AVSA-429.torrent")})
|
|
||||||
@@ -50,6 +50,7 @@ class FileService:
|
|||||||
return self.perform_rename(entry, f"{name}{ext}")
|
return self.perform_rename(entry, f"{name}{ext}")
|
||||||
|
|
||||||
name = name.replace("-", "")
|
name = name.replace("-", "")
|
||||||
|
name = name.replace(" ", "")
|
||||||
|
|
||||||
# 处理特殊前缀
|
# 处理特殊前缀
|
||||||
for prefix in SPECIAL_PREFIXES:
|
for prefix in SPECIAL_PREFIXES:
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class TorrentService:
|
|||||||
name, ext = os.path.splitext(filename)
|
name, ext = os.path.splitext(filename)
|
||||||
ext = ext.lower()
|
ext = ext.lower()
|
||||||
name = name.upper()
|
name = name.upper()
|
||||||
name = name.replace("-", "")
|
name.maketrans({"-": "", " ":""})
|
||||||
# 处理特殊前缀
|
# 处理特殊前缀
|
||||||
for prefix in SPECIAL_PREFIXES:
|
for prefix in SPECIAL_PREFIXES:
|
||||||
if name.startswith(prefix):
|
if name.startswith(prefix):
|
||||||
@@ -120,3 +120,38 @@ class TorrentService:
|
|||||||
FolderService(paths=self.paths, ignore_dirs=IGNORE_DIRS,
|
FolderService(paths=self.paths, ignore_dirs=IGNORE_DIRS,
|
||||||
file_callback=self.get_by_name_file_callback).process_folder()
|
file_callback=self.get_by_name_file_callback).process_folder()
|
||||||
return to_json_serializable(self.torrent_name)
|
return to_json_serializable(self.torrent_name)
|
||||||
|
|
||||||
|
def extract_name_from_filename(self, filename: str) -> str:
|
||||||
|
"""根据torrent文件名提取标准化名称"""
|
||||||
|
temp_name = filename.replace("-4K", "")
|
||||||
|
without_modifier_file_name = self.prefix_pattern.sub('.', temp_name)
|
||||||
|
name, ext = os.path.splitext(without_modifier_file_name)
|
||||||
|
name = name.upper()
|
||||||
|
name = name.replace("-", "")
|
||||||
|
# print(name.translate(str.maketrans({"-": "", " ":""})))
|
||||||
|
|
||||||
|
for prefix in SPECIAL_PREFIXES:
|
||||||
|
if name.startswith(prefix):
|
||||||
|
return f"{prefix}-{name[len(prefix):]}"
|
||||||
|
|
||||||
|
# print(name)
|
||||||
|
new_name = []
|
||||||
|
for i, char in enumerate(name):
|
||||||
|
# print(i, char, not name[i - 1].isnumeric())
|
||||||
|
if i > 0 and not name[i - 1].isnumeric() and char.isnumeric():
|
||||||
|
new_name.append(f"-{char}")
|
||||||
|
else:
|
||||||
|
new_name.append(char)
|
||||||
|
|
||||||
|
return f"{''.join(new_name)}"
|
||||||
|
|
||||||
|
def get_all_file_callback(self, entry: os.DirEntry):
|
||||||
|
# path_arr = entry.path.split(os.sep)
|
||||||
|
new_name = self.extract_name_from_filename(entry.name)
|
||||||
|
self.result_list.append(new_name)
|
||||||
|
|
||||||
|
|
||||||
|
def get_all(self):
|
||||||
|
FolderService(paths=self.paths, ignore_dirs=IGNORE_DIRS,
|
||||||
|
file_callback=self.get_all_file_callback).process_folder()
|
||||||
|
return self.result_list
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
"npm-run-all2": "^8.0.4",
|
"npm-run-all2": "^8.0.4",
|
||||||
"oxfmt": "^0.45.0",
|
"oxfmt": "^0.45.0",
|
||||||
"oxlint": "~1.60.0",
|
"oxlint": "~1.60.0",
|
||||||
"sass-embedded": "^1.98.0",
|
"sass": "^1.99.0",
|
||||||
"typescript": "~6.0.0",
|
"typescript": "~6.0.0",
|
||||||
"unplugin-auto-import": "^21.0.0",
|
"unplugin-auto-import": "^21.0.0",
|
||||||
"unplugin-vue-components": "^31.0.0",
|
"unplugin-vue-components": "^31.0.0",
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export let isRelogin: { show: boolean } = {show: false}
|
|||||||
axios.defaults.headers["Content-Type"] = "application/json; charset=UTF-8"
|
axios.defaults.headers["Content-Type"] = "application/json; charset=UTF-8"
|
||||||
|
|
||||||
const service: AxiosInstance = axios.create({
|
const service: AxiosInstance = axios.create({
|
||||||
baseURL: "http://localhost:5000/api/",
|
baseURL: "http://192.168.1.32:5000/api/",
|
||||||
// baseURL: "/api",
|
// baseURL: "/api",
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
})
|
})
|
||||||
|
|||||||
Binary file not shown.
@@ -3,4 +3,4 @@ from app import create_app
|
|||||||
app = create_app("development")
|
app = create_app("development")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, use_reloader=True, threading=True)
|
app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=True, threaded=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user