From 3cb8022c7ce1e59a4e6f3f1298e447161d1bfe33 Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Sat, 17 May 2025 23:55:01 +0330 Subject: [PATCH] feat: Add API endpoint to get current NormalSub subpath - Created `GetSubPathResponse` Pydantic schema for the API response. - Added a new GET endpoint `/api/v1/config/normalsub/subpath` to fetch the current NormalSub subpath using `cli_api.get_normalsub_subpath()`. - Returns the subpath or null if not found/set. --- .../webpanel/routers/api/v1/config/normalsub.py | 15 +++++++++++++-- .../routers/api/v1/schema/config/normalsub.py | 6 +++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/core/scripts/webpanel/routers/api/v1/config/normalsub.py b/core/scripts/webpanel/routers/api/v1/config/normalsub.py index 3a97165..5f26569 100644 --- a/core/scripts/webpanel/routers/api/v1/config/normalsub.py +++ b/core/scripts/webpanel/routers/api/v1/config/normalsub.py @@ -1,6 +1,6 @@ from fastapi import APIRouter, HTTPException from ..schema.response import DetailResponse -from ..schema.config.normalsub import StartInputBody, EditSubPathInputBody +from ..schema.config.normalsub import StartInputBody, EditSubPathInputBody, GetSubPathResponse import cli_api router = APIRouter() @@ -74,4 +74,15 @@ async def normal_sub_edit_subpath_api(body: EditSubPathInputBody): except cli_api.InvalidInputError as e: raise HTTPException(status_code=422, detail=f'Validation Error: {str(e)}') except Exception as e: - raise HTTPException(status_code=400, detail=f'Error: {str(e)}') \ No newline at end of file + raise HTTPException(status_code=400, detail=f'Error: {str(e)}') + +@router.get('/subpath', response_model=GetSubPathResponse, summary='Get Current NormalSub Subpath') +async def normal_sub_get_subpath_api(): + """ + Retrieves the current subpath for the NormalSub service. + """ + try: + current_subpath = cli_api.get_normalsub_subpath() + return GetSubPathResponse(subpath=current_subpath) + except Exception as e: + raise HTTPException(status_code=500, detail=f'Error retrieving subpath: {str(e)}') \ No newline at end of file diff --git a/core/scripts/webpanel/routers/api/v1/schema/config/normalsub.py b/core/scripts/webpanel/routers/api/v1/schema/config/normalsub.py index 7f791bf..7f2af1f 100644 --- a/core/scripts/webpanel/routers/api/v1/schema/config/normalsub.py +++ b/core/scripts/webpanel/routers/api/v1/schema/config/normalsub.py @@ -1,8 +1,12 @@ from pydantic import BaseModel, Field +from typing import Optional class StartInputBody(BaseModel): domain: str port: int class EditSubPathInputBody(BaseModel): - subpath: str = Field(..., min_length=1, pattern=r"^[a-zA-Z0-9]+$", description="The new subpath, must be alphanumeric.") \ No newline at end of file + subpath: str = Field(..., min_length=1, pattern=r"^[a-zA-Z0-9]+$", description="The new subpath, must be alphanumeric.") + +class GetSubPathResponse(BaseModel): + subpath: Optional[str] = Field(None, description="The current NormalSub subpath, or null if not set/found.") \ No newline at end of file