diff --git a/core/scripts/webpanel/routers/api/v1/config/normalsub.py b/core/scripts/webpanel/routers/api/v1/config/normalsub.py index 93e933f..3a97165 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 +from ..schema.config.normalsub import StartInputBody, EditSubPathInputBody import cli_api router = APIRouter() @@ -51,4 +51,27 @@ async def normal_sub_stop_api(): except Exception as e: raise HTTPException(status_code=400, detail=f'Error: {str(e)}') -# TODO: Maybe would be nice to have a status endpoint + +@router.put('/edit_subpath', response_model=DetailResponse, summary='Edit NormalSub Subpath') +async def normal_sub_edit_subpath_api(body: EditSubPathInputBody): + """ + Edits the subpath for the NormalSub service. + + Args: + body (EditSubPathInputBody): The request body containing the new subpath. + + Returns: + DetailResponse: A response object containing a success message indicating + that the NormalSub subpath has been updated successfully. + + Raises: + HTTPException: If there is an error editing the NormalSub subpath, an + HTTPException with status code 400 and error details will be raised. + """ + try: + cli_api.edit_normalsub_subpath(body.subpath) + return DetailResponse(detail=f'Normalsub subpath updated to {body.subpath} successfully.') + 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 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 10933a9..7f791bf 100644 --- a/core/scripts/webpanel/routers/api/v1/schema/config/normalsub.py +++ b/core/scripts/webpanel/routers/api/v1/schema/config/normalsub.py @@ -1,9 +1,8 @@ -from pydantic import BaseModel - -# The StartInputBody is the same as in /hysteria/core/scripts/webpanel/routers/api/v1/schema/config/singbox.py but for /normalsub endpoint -# I'm defining it separately because highly likely it'll be different - +from pydantic import BaseModel, Field 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