feat(project): 初始化项目结构和配置
- 添加.gitignore和.flaskenv环境配置文件 - 创建Flask应用基础架构,包括models、services、utils模块 - 配置数据库模型User和Setting,集成SQLAlchemy和Alembic迁移 - 添加前端Vue项目结构,包含Element Plus组件库 - 配置前后端API路由和蓝prints模块 - 实现书籍下载服务BookService功能模块 - 添加代码规范配置.editorconfig、.oxfmtrc.json、.oxlintrc.json - 配置VSCode推荐插件和前端构建工具链 - 实现文件服务FileService和相关业务逻辑
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from app.services import FolderService
|
||||
from app.constants import IMAGE_EXTENSIONS, IGNORE_DIRS
|
||||
|
||||
|
||||
class ImageService:
|
||||
def __init__(self):
|
||||
self.prefix_pattern = re.compile(r'(?i)[A-Z]+\.')
|
||||
self.paths = ["C:\\Users\\Localhost\\Desktop\\images"]
|
||||
self.image_root_folder = "C:\\Users\\Localhost\\Desktop\\images"
|
||||
self.done_image = "C:\\Users\\Localhost\\Desktop\\BT\\done_images"
|
||||
|
||||
def export_callback(self, entry: os.DirEntry[str]) -> None:
|
||||
name, ext = os.path.splitext(entry.name)
|
||||
ext = ext.lower()
|
||||
if ext in IMAGE_EXTENSIONS:
|
||||
file_parent_dir = os.path.basename(os.path.dirname(entry.path))
|
||||
dest_dir = os.path.join(self.image_root_folder, file_parent_dir)
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
|
||||
dest_file = os.path.join(dest_dir, entry.name)
|
||||
if os.path.exists(dest_file):
|
||||
yield f"data: {entry.name} 已存在\n\n"
|
||||
return
|
||||
|
||||
try:
|
||||
shutil.move(entry.path, dest_file)
|
||||
except shutil.Error as e:
|
||||
yield f"data: 移动失败: {e}\n\n"
|
||||
|
||||
def export(self):
|
||||
FolderService(self.paths, ignore_dirs=IGNORE_DIRS, file_callback=self.export_callback).process_folder()
|
||||
|
||||
# 去结尾字母,已使用过了
|
||||
def remove_last_letter(self, entry: os.DirEntry[str]):
|
||||
without_modifier_file_name = self.prefix_pattern.sub('.', entry.name)
|
||||
os.rename(entry.path, os.path.join(os.path.dirname(entry.path), without_modifier_file_name))
|
||||
Reference in New Issue
Block a user