Add: previous commit APIs
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from ..schema.config.hysteria import ConfigFile
|
from ..schema.config.hysteria import ConfigFile, GetPortResponse, GetSniResponse
|
||||||
from ..schema.response import DetailResponse
|
from ..schema.response import DetailResponse
|
||||||
# from ..schema.config.hysteria import InstallInputBody
|
# from ..schema.config.hysteria import InstallInputBody
|
||||||
import cli_api
|
import cli_api
|
||||||
@ -65,6 +65,26 @@ async def update():
|
|||||||
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
|
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
|
||||||
|
|
||||||
|
|
||||||
|
@router.get('/get-port', response_model=GetPortResponse, summary='Get Hysteria2 port')
|
||||||
|
async def get_port():
|
||||||
|
"""
|
||||||
|
Retrieves the port for Hysteria2.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A GetPortResponse containing the Hysteria2 port.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
HTTPException: if an error occurs while getting the Hysteria2 port.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if port := cli_api.get_hysteria2_port():
|
||||||
|
return GetPortResponse(port=port)
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=404, detail='Hysteria2 port not found.')
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
|
||||||
|
|
||||||
|
|
||||||
@router.get('/set-port/{port}', response_model=DetailResponse, summary='Set Hysteria2 port')
|
@router.get('/set-port/{port}', response_model=DetailResponse, summary='Set Hysteria2 port')
|
||||||
async def set_port(port: int):
|
async def set_port(port: int):
|
||||||
"""
|
"""
|
||||||
@ -86,6 +106,26 @@ async def set_port(port: int):
|
|||||||
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
|
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
|
||||||
|
|
||||||
|
|
||||||
|
@router.get('/get-sni', response_model=GetSniResponse, summary='Get Hysteria2 SNI')
|
||||||
|
async def get_sni():
|
||||||
|
'''
|
||||||
|
Retrieves the SNI for Hysteria2.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A GetSniResponse containing the Hysteria2 SNI.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
HTTPException: if an error occurs while getting the Hysteria2 SNI.
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
if sni := cli_api.get_hysteria2_sni():
|
||||||
|
return GetSniResponse(sni=sni)
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=404, detail='Hysteria2 SNI not found.')
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
|
||||||
|
|
||||||
|
|
||||||
@router.get('/set-sni/{sni}', response_model=DetailResponse, summary='Set Hysteria2 SNI')
|
@router.get('/set-sni/{sni}', response_model=DetailResponse, summary='Set Hysteria2 SNI')
|
||||||
async def set_sni(sni: str):
|
async def set_sni(sni: str):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from pydantic import RootModel
|
from pydantic import BaseModel, RootModel
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
# Change: Installing and uninstalling Hysteria2 is possible only through the CLI
|
# Change: Installing and uninstalling Hysteria2 is possible only through the CLI
|
||||||
@ -10,3 +10,11 @@ from typing import Any
|
|||||||
# TODO: Define supported fields of the config file
|
# TODO: Define supported fields of the config file
|
||||||
class ConfigFile(RootModel): # type: ignore
|
class ConfigFile(RootModel): # type: ignore
|
||||||
root: dict[str, Any]
|
root: dict[str, Any]
|
||||||
|
|
||||||
|
|
||||||
|
class GetPortResponse(BaseModel):
|
||||||
|
port: int
|
||||||
|
|
||||||
|
|
||||||
|
class GetSniResponse(BaseModel):
|
||||||
|
sni: str
|
||||||
|
|||||||
Reference in New Issue
Block a user