mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
fix: upgrade web dependencies and stabilize plugin routes (#6383)
This commit is contained in:
@@ -36,14 +36,20 @@ class FastAPIDynamicRouteRegistry:
|
||||
raise ValueError("Action must be 'add' or 'remove'")
|
||||
|
||||
modified = False
|
||||
existing_paths = {route.path: route for route in self._app.routes}
|
||||
existing_paths = {
|
||||
path: route
|
||||
for route in self._app.routes
|
||||
if (path := self._route_path(route)) is not None
|
||||
}
|
||||
plugin_ids = [plugin_id] if plugin_id else self._plugin_ids()
|
||||
for current_id in plugin_ids:
|
||||
if self.remove(current_id):
|
||||
modified = True
|
||||
if action != "add":
|
||||
continue
|
||||
for api in self._plugin_apis(current_id):
|
||||
for source_api in self._plugin_apis(current_id):
|
||||
api = dict(source_api)
|
||||
api["dependencies"] = list(source_api.get("dependencies") or ())
|
||||
api_path = f"{self._prefix}{api.get('path', '')}"
|
||||
try:
|
||||
api["path"] = api_path
|
||||
@@ -79,20 +85,27 @@ class FastAPIDynamicRouteRegistry:
|
||||
prefix = f"{self._prefix}/{plugin_id}/"
|
||||
routes = [
|
||||
route for route in self._app.routes
|
||||
if route.path.startswith(prefix)
|
||||
if (path := self._route_path(route)) is not None
|
||||
and path.startswith(prefix)
|
||||
]
|
||||
removed = False
|
||||
for route in routes:
|
||||
try:
|
||||
self._app.routes.remove(route)
|
||||
removed = True
|
||||
self._logger.debug(f"Removed plugin route: {route.path}")
|
||||
self._logger.debug(f"Removed plugin route: {self._route_path(route)}")
|
||||
except Exception as error:
|
||||
self._logger.error(
|
||||
f"Error removing plugin route {route.path}: {str(error)}"
|
||||
f"Error removing plugin route {self._route_path(route)}: {str(error)}"
|
||||
)
|
||||
return removed
|
||||
|
||||
@staticmethod
|
||||
def _route_path(route: Any) -> Optional[str]:
|
||||
"""返回公开路由路径,跳过 FastAPI 内部的无路径 include 包装器。"""
|
||||
path = getattr(route, "path", None)
|
||||
return path if isinstance(path, str) else None
|
||||
|
||||
def clean(self, existing_paths: dict) -> None:
|
||||
"""清理 FastAPI 重建时可能重复的受保护文档路由。"""
|
||||
for protected_route in self._protected_routes:
|
||||
|
||||
Reference in New Issue
Block a user