|
|
@@ -65,7 +65,7 @@ async def request_select_proxy_name(external_ctl: str, provider_name: str, proxy
|
|
|
else:
|
|
|
raise HTTPException(status_code=500, detail=f"Failed to select proxy after {max_retries} attempts: {str(e)}")
|
|
|
@mihomo_router.post("/start")
|
|
|
-async def post_start_mihomo(request: MihomoBatchRequest):
|
|
|
+async def post_start_mihomo(request: MihomoBatchRequest) -> MihomoMetaWithURL:
|
|
|
db = SubscriptionManager()
|
|
|
logger.info(f"{request}")
|
|
|
# 获取对应的订阅文件
|
|
|
@@ -135,27 +135,9 @@ async def post_start_mihomo(request: MihomoBatchRequest):
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
@mihomo_router.post("/startup")
|
|
|
-async def post_start_each_provider():
|
|
|
+async def post_start_each_provider() -> List[MihomoMetaWithURL]:
|
|
|
db = SubscriptionManager()
|
|
|
- with Session(db.engine) as session:
|
|
|
- # 子查询:获取每个 provider_name 的最小 id
|
|
|
- subquery = (
|
|
|
- select(
|
|
|
- MihomoMeta.provider_name,
|
|
|
- func.min(MihomoMeta.id).label("min_id")
|
|
|
- )
|
|
|
- .group_by(MihomoMeta.provider_name)
|
|
|
- .subquery()
|
|
|
- )
|
|
|
-
|
|
|
- # 主查询:通过联接到子查询获取每个 provider_name 的第一条记录
|
|
|
- stmt = (
|
|
|
- select(MihomoMeta)
|
|
|
- .join(subquery, MihomoMeta.id == subquery.c.min_id)
|
|
|
- )
|
|
|
-
|
|
|
- # 执行查询并获取结果
|
|
|
- results = session.exec(stmt).all()
|
|
|
+ results = db.get_each_provider_proxies()
|
|
|
ret = []
|
|
|
for provider_moho in results:
|
|
|
try:
|
|
|
@@ -195,12 +177,7 @@ async def post_stop_mihomo(request: MihomoBatchRequest):
|
|
|
@mihomo_router.get("/")
|
|
|
async def get_mihomo_running_status():
|
|
|
db = SubscriptionManager()
|
|
|
- with Session(db.engine) as session:
|
|
|
- all = session.exec(
|
|
|
- select(MihomoMeta)
|
|
|
- .where(MihomoMeta.pid.is_not(None))
|
|
|
- ).all()
|
|
|
-
|
|
|
+ all = db.get_running_proxies()
|
|
|
result = []
|
|
|
for mihomo_model in all:
|
|
|
mihomo_with_url = MihomoMetaWithURL(**mihomo_model.model_dump())
|
|
|
@@ -211,6 +188,14 @@ async def get_mihomo_running_status():
|
|
|
|
|
|
return result
|
|
|
|
|
|
+@mihomo_router.get("/proxies_reachability")
|
|
|
+async def get_proxies_reachability():
|
|
|
+ db = SubscriptionManager()
|
|
|
+ res = db.get_each_provider_running_proxies()
|
|
|
+ logger.info(f"get_each_provider_running_proxies {res}")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@mihomo_router.get("/external-controller")
|
|
|
async def get_controller_urls():
|
|
|
running_list = await get_mihomo_running_status()
|