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.
This commit is contained in:
Whispering Wind
2025-05-17 23:55:01 +03:30
committed by GitHub
parent eaef80b80e
commit 3cb8022c7c
2 changed files with 18 additions and 3 deletions

View File

@ -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)}')
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)}')

View File

@ -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.")
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.")