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:
@ -1,6 +1,6 @@
|
|||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from ..schema.response import DetailResponse
|
from ..schema.response import DetailResponse
|
||||||
from ..schema.config.normalsub import StartInputBody, EditSubPathInputBody
|
from ..schema.config.normalsub import StartInputBody, EditSubPathInputBody, GetSubPathResponse
|
||||||
import cli_api
|
import cli_api
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@ -75,3 +75,14 @@ async def normal_sub_edit_subpath_api(body: EditSubPathInputBody):
|
|||||||
raise HTTPException(status_code=422, detail=f'Validation Error: {str(e)}')
|
raise HTTPException(status_code=422, detail=f'Validation Error: {str(e)}')
|
||||||
except Exception as 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)}')
|
||||||
@ -1,4 +1,5 @@
|
|||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
class StartInputBody(BaseModel):
|
class StartInputBody(BaseModel):
|
||||||
domain: str
|
domain: str
|
||||||
@ -6,3 +7,6 @@ class StartInputBody(BaseModel):
|
|||||||
|
|
||||||
class EditSubPathInputBody(BaseModel):
|
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.")
|
||||||
Reference in New Issue
Block a user