refactor(api): 重构API蓝图结构按功能模块拆分
- 将原有的单一api蓝图拆分为多个独立蓝图(torrent、book、music、file、video、image) - 每个蓝图负责对应的功能模块,实现更好的代码组织和维护性 - 更新应用初始化文件中的蓝图注册方式,使用新的模块化结构 - 修改前端API调用路径,将/files/rename调整为/file/rename - 在torrent服务中新增按名称查询功能和相关处理逻辑
This commit is contained in:
@@ -1,91 +0,0 @@
|
||||
from typing import List
|
||||
from flask import Blueprint, jsonify, Response, current_app
|
||||
from app.services import FileService, VideoService, TorrentService, BookService, ImageService, MusicService
|
||||
|
||||
bp = Blueprint("api", __name__)
|
||||
|
||||
|
||||
@bp.route("/book/download")
|
||||
def book_download():
|
||||
book_object = BookService()
|
||||
app = current_app._get_current_object()
|
||||
|
||||
def generate():
|
||||
with app.app_context():
|
||||
yield from book_object.book_download()
|
||||
|
||||
return Response(generate(), mimetype='text/event-stream')
|
||||
|
||||
@bp.route("/video/findDeduplication")
|
||||
def video_find_deduplication():
|
||||
video_object = VideoService(paths=[
|
||||
"C:\\迅雷下载\\0_done",
|
||||
"D:\\",
|
||||
"E:\\",
|
||||
"F:\\"
|
||||
])
|
||||
|
||||
return jsonify({"code": 200, "message": video_object.find_deduplication()})
|
||||
|
||||
|
||||
@bp.route('/video/deduplication')
|
||||
def video_deduplication():
|
||||
video_object = VideoService(paths=[
|
||||
"C:\\迅雷下载\\0_done",
|
||||
"D:\\",
|
||||
"E:\\",
|
||||
"F:\\"
|
||||
])
|
||||
|
||||
return jsonify({"code": 200, "message": video_object.deduplication()})
|
||||
|
||||
|
||||
@bp.route("/video/hasTorrent")
|
||||
def video_has_torrent():
|
||||
torrent_obj = TorrentService(["E:\\"])
|
||||
return jsonify({"code": 200, "message": torrent_obj.has_torrent()})
|
||||
|
||||
|
||||
@bp.route('/files/rename')
|
||||
def files_rename():
|
||||
paths: List[str] = [
|
||||
"C:\\迅雷下载\\0_done",
|
||||
"C:\\Users\\Localhost\\Desktop\\BT",
|
||||
]
|
||||
|
||||
file_object = FileService(paths)
|
||||
return jsonify({"code": 200, "message": file_object.rename()})
|
||||
|
||||
|
||||
@bp.route('/torrent/deduplication')
|
||||
def torrent_deduplication():
|
||||
torrent_object = TorrentService(["C:\\Users\\Localhost\\Desktop\\BT"])
|
||||
return jsonify({"code": 200, "message": torrent_object.deduplication()})
|
||||
|
||||
|
||||
@bp.route("/image/export")
|
||||
def image_export():
|
||||
image_object = ImageService()
|
||||
|
||||
def generate():
|
||||
yield from image_object.export()
|
||||
|
||||
return Response(generate(), mimetype='text/event-stream')
|
||||
|
||||
|
||||
@bp.route("/image/hasTorrent")
|
||||
def image_has_torrent():
|
||||
torrent_obj = TorrentService(["C:\\Users\\Localhost\\Desktop\\Images"])
|
||||
return jsonify({"code": 200, "message": torrent_obj.has_torrent()})
|
||||
|
||||
|
||||
@bp.route("/music/rename")
|
||||
def music_rename():
|
||||
music_object = MusicService()
|
||||
return jsonify({"code": 200, "message": music_object.rename()})
|
||||
|
||||
@bp.route("/torrent/statistics")
|
||||
def torrent_statistics():
|
||||
torrent_object = TorrentService(["C:\\Users\\Localhost\\Desktop\\BT"])
|
||||
return jsonify({"code": 200, "message": torrent_object.statistics()})
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
from flask import Blueprint, current_app, Response
|
||||
|
||||
from app.services import BookService
|
||||
|
||||
bp = Blueprint("book", __name__)
|
||||
|
||||
|
||||
@bp.route("/download")
|
||||
def book_download():
|
||||
book_object = BookService()
|
||||
app = current_app._get_current_object()
|
||||
|
||||
def generate():
|
||||
with app.app_context():
|
||||
yield from book_object.book_download()
|
||||
|
||||
return Response(generate(), mimetype='text/event-stream')
|
||||
@@ -0,0 +1,17 @@
|
||||
from typing import List
|
||||
from flask import Blueprint, jsonify
|
||||
|
||||
from app.services import FileService
|
||||
|
||||
bp = Blueprint("file", __name__)
|
||||
|
||||
|
||||
@bp.route('/rename')
|
||||
def files_rename():
|
||||
paths: List[str] = [
|
||||
"C:\\迅雷下载\\0_done",
|
||||
"C:\\Users\\Localhost\\Desktop\\BT",
|
||||
]
|
||||
|
||||
file_object = FileService(paths)
|
||||
return jsonify({"code": 200, "message": file_object.rename()})
|
||||
@@ -0,0 +1,21 @@
|
||||
from flask import Blueprint, Response, jsonify
|
||||
|
||||
from app.services import ImageService, TorrentService
|
||||
|
||||
bp = Blueprint("image", __name__)
|
||||
|
||||
|
||||
@bp.route("/export")
|
||||
def image_export():
|
||||
image_object = ImageService()
|
||||
|
||||
def generate():
|
||||
yield from image_object.export()
|
||||
|
||||
return Response(generate(), mimetype='text/event-stream')
|
||||
|
||||
|
||||
@bp.route("/hasTorrent")
|
||||
def image_has_torrent():
|
||||
torrent_obj = TorrentService(["C:\\Users\\Localhost\\Desktop\\Images"])
|
||||
return jsonify({"code": 200, "message": torrent_obj.has_torrent()})
|
||||
@@ -0,0 +1,11 @@
|
||||
from flask import Blueprint, jsonify
|
||||
|
||||
from app.services import MusicService
|
||||
|
||||
bp = Blueprint("music", __name__)
|
||||
|
||||
|
||||
@bp.route("/rename")
|
||||
def music_rename():
|
||||
music_object = MusicService()
|
||||
return jsonify({"code": 200, "message": music_object.rename()})
|
||||
@@ -0,0 +1,23 @@
|
||||
from flask import Blueprint, jsonify
|
||||
|
||||
from app.services import TorrentService
|
||||
|
||||
bp = Blueprint("torrent", __name__)
|
||||
|
||||
|
||||
@bp.route('/deduplication')
|
||||
def torrent_deduplication():
|
||||
torrent_object = TorrentService(["C:\\Users\\Localhost\\Desktop\\BT"])
|
||||
return jsonify({"code": 200, "message": torrent_object.deduplication()})
|
||||
|
||||
|
||||
@bp.route("/statistics")
|
||||
def torrent_statistics():
|
||||
torrent_object = TorrentService(["C:\\Users\\Localhost\\Desktop\\BT"])
|
||||
return jsonify({"code": 200, "message": torrent_object.statistics()})
|
||||
|
||||
|
||||
@bp.route("/s/<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)})
|
||||
@@ -0,0 +1,34 @@
|
||||
from flask import Blueprint, jsonify
|
||||
|
||||
from app.services import VideoService, TorrentService
|
||||
|
||||
bp = Blueprint("video", __name__)
|
||||
|
||||
@bp.route("/findDeduplication")
|
||||
def video_find_deduplication():
|
||||
video_object = VideoService(paths=[
|
||||
"C:\\迅雷下载\\0_done",
|
||||
"D:\\",
|
||||
"E:\\",
|
||||
"F:\\"
|
||||
])
|
||||
|
||||
return jsonify({"code": 200, "message": video_object.find_deduplication()})
|
||||
|
||||
|
||||
@bp.route('/deduplication')
|
||||
def video_deduplication():
|
||||
video_object = VideoService(paths=[
|
||||
"C:\\迅雷下载\\0_done",
|
||||
"D:\\",
|
||||
"E:\\",
|
||||
"F:\\"
|
||||
])
|
||||
|
||||
return jsonify({"code": 200, "message": video_object.deduplication()})
|
||||
|
||||
|
||||
@bp.route("/hasTorrent")
|
||||
def video_has_torrent():
|
||||
torrent_obj = TorrentService(["E:\\"])
|
||||
return jsonify({"code": 200, "message": torrent_obj.has_torrent()})
|
||||
Reference in New Issue
Block a user