refactor(api): 重构API蓝图结构按功能模块拆分
- 将原有的单一api蓝图拆分为多个独立蓝图(torrent、book、music、file、video、image) - 每个蓝图负责对应的功能模块,实现更好的代码组织和维护性 - 更新应用初始化文件中的蓝图注册方式,使用新的模块化结构 - 修改前端API调用路径,将/files/rename调整为/file/rename - 在torrent服务中新增按名称查询功能和相关处理逻辑
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import os
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from app.constants import IGNORE_DIRS
|
||||
from app.constants import IGNORE_DIRS, SEPARATORS, SPECIAL_PREFIXES, SPECIAL_DIRS
|
||||
from app.services import FolderService
|
||||
from app.utils import to_json_serializable
|
||||
|
||||
@@ -17,6 +17,7 @@ class TorrentService:
|
||||
self.list_of_duplicate_torrent: List[str] = []
|
||||
self.result_list = []
|
||||
self.torrent_name = defaultdict(lambda: defaultdict(set))
|
||||
self.search_name = ""
|
||||
|
||||
def process_torrent_file(self, entry: os.DirEntry[str]) -> None:
|
||||
temp_name = entry.name.replace("-4K", "")
|
||||
@@ -75,7 +76,47 @@ class TorrentService:
|
||||
print(f"有奇怪的东西混入2{path_arr}")
|
||||
|
||||
def statistics(self):
|
||||
FolderService(paths=self.paths,
|
||||
ignore_dirs=IGNORE_DIRS,
|
||||
FolderService(paths=self.paths, ignore_dirs=IGNORE_DIRS,
|
||||
file_callback=self.statistics_file_callback).process_folder()
|
||||
return to_json_serializable(self.torrent_name)
|
||||
|
||||
def process_file_name(self, filename: str) -> Optional[str]:
|
||||
name, ext = os.path.splitext(filename)
|
||||
ext = ext.lower()
|
||||
name = name.upper()
|
||||
name = name.replace("-", "")
|
||||
# 处理特殊前缀
|
||||
for prefix in SPECIAL_PREFIXES:
|
||||
if name.startswith(prefix):
|
||||
# name = name.replace(prefix, "")
|
||||
return f"{prefix}-{name[len(prefix):]}{ext}"
|
||||
return name
|
||||
|
||||
def get_by_name_file_callback(self, entry: os.DirEntry):
|
||||
path_arr = entry.path.split(os.sep)
|
||||
torrent_sub_type = {"0_多人", "FWAY", "0_女同", "_temp"}
|
||||
torrent_type = {"4k2", "4K原版", "456k", "1024", "2048", "done", "FC2", "hhd800", "other", "高清中文字幕",
|
||||
"三级写真", "无码流出", "亚洲有码原创"}
|
||||
if path_arr[-2] not in torrent_type and path_arr[-2] not in torrent_sub_type:
|
||||
if path_arr[-3] in torrent_sub_type:
|
||||
# print(path_arr[-3])
|
||||
if path_arr[-4] in torrent_type:
|
||||
# print(path_arr[-4])
|
||||
pass
|
||||
else:
|
||||
print(f"有奇怪的东西混入{path_arr}")
|
||||
pass
|
||||
elif path_arr[-3] in torrent_type:
|
||||
if self.search_name in path_arr[-2]:
|
||||
print(entry.name)
|
||||
# self.result_list.insert(0, entry.path)
|
||||
self.torrent_name[path_arr[-2]][path_arr[-3]].add(entry.name)
|
||||
pass
|
||||
else:
|
||||
print(f"有奇怪的东西混入2{path_arr}")
|
||||
|
||||
def get_by_name(self, name):
|
||||
self.search_name = name
|
||||
FolderService(paths=self.paths, ignore_dirs=IGNORE_DIRS,
|
||||
file_callback=self.get_by_name_file_callback).process_folder()
|
||||
return to_json_serializable(self.torrent_name)
|
||||
|
||||
Reference in New Issue
Block a user