mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-12-16 13:40:53 +08:00
✨ Web UI
增加执行命令
This commit is contained in:
parent
38af604db0
commit
fa286d3bba
@ -31,7 +31,7 @@ logger.add(record_debug_log, level='DEBUG', colorize=True, filter=default_filter
|
||||
route = APIRouter()
|
||||
|
||||
|
||||
@route.get('/log', response_class=StreamingResponse)
|
||||
@route.get('/log', response_class=StreamingResponse, dependencies=[authentication()])
|
||||
async def get_log(level: str = 'info', num: Union[int, str] = 100):
|
||||
show_logs = info_logs[-(num or 1):] if level == 'info' else debug_logs[-(num or 1):]
|
||||
|
||||
@ -43,6 +43,12 @@ async def get_log(level: str = 'info', num: Union[int, str] = 100):
|
||||
return StreamingResponse(streaming_logs())
|
||||
|
||||
|
||||
@route.get('/run_cmd', response_class=StreamingResponse, dependencies=[authentication()])
|
||||
async def run_cmd(cmd: str):
|
||||
p = await asyncio.create_subprocess_shell(cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
||||
return StreamingResponse(p.stdout or p.stderr)
|
||||
|
||||
|
||||
@route.get('/status', response_class=JSONResponse, dependencies=[authentication()])
|
||||
async def status():
|
||||
return await get_status()
|
||||
|
@ -1,5 +1,6 @@
|
||||
from LittlePaimon.utils import __version__
|
||||
from amis import Page, PageSchema, Html, Property, Service, Flex, ActionType, LevelEnum, Divider, ButtonGroupSelect, Log, Alert, Form, Dialog, Select, Group
|
||||
from amis import Page, PageSchema, Html, Property, Service, Flex, ActionType, LevelEnum, Divider, ButtonGroupSelect, \
|
||||
Log, Alert, Form, Dialog, Select, Group, InputText, DisplayModeEnum, Horizontal
|
||||
|
||||
logo = Html(html=f'''
|
||||
<p align="center">
|
||||
@ -70,6 +71,27 @@ log_page = Log(
|
||||
source='/LittlePaimon/api/log?level=${log_level | raw}&num=${log_num | raw}'
|
||||
)
|
||||
|
||||
cmd_input = Form(
|
||||
mode=DisplayModeEnum.horizontal,
|
||||
horizontal=Horizontal(left=0),
|
||||
wrapWithPanel=False,
|
||||
body=[
|
||||
InputText(name='command', required=True, clearable=True, addOn=ActionType.Dialog(
|
||||
label='执行',
|
||||
level=LevelEnum.primary,
|
||||
dialog=Dialog(
|
||||
title='命令执行结果',
|
||||
size='xl',
|
||||
body=Log(
|
||||
autoScroll=True,
|
||||
placeholder='执行命令中,请稍候...',
|
||||
operation=['stop', 'showLineNumber', 'filter'],
|
||||
source='/LittlePaimon/api/run_cmd?cmd=${command | raw}'),
|
||||
)
|
||||
))
|
||||
]
|
||||
)
|
||||
|
||||
operation_button = Flex(justify='center', items=[
|
||||
ActionType.Ajax(
|
||||
label='更新',
|
||||
@ -97,6 +119,15 @@ operation_button = Flex(justify='center', items=[
|
||||
Form(
|
||||
body=[Group(body=[select_log_num, select_log_level]), log_page]
|
||||
)])
|
||||
),
|
||||
ActionType.Dialog(
|
||||
label='执行命令',
|
||||
className='m-l',
|
||||
level=LevelEnum.warning,
|
||||
dialog=Dialog(title='执行命令',
|
||||
size='lg',
|
||||
actions=[],
|
||||
body=[cmd_input])
|
||||
)
|
||||
])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user