Экспорт конкретный подсетей. Обновление локалей учитывая жти изменения
This commit is contained in:
parent
b1306ff66f
commit
0c8533257d
8 changed files with 81 additions and 63 deletions
|
|
@ -1,11 +1,12 @@
|
|||
import os
|
||||
import logging
|
||||
from typing import Optional
|
||||
from fastapi import APIRouter, HTTPException, Depends, Response, Request
|
||||
from fastapi import APIRouter, HTTPException, Depends, Response, Request, Body
|
||||
from starlette.responses import FileResponse
|
||||
from services.settings_service import SettingsService
|
||||
from utils.i18n import get_translations
|
||||
from babel.support import Translations
|
||||
from models.subnet import SubnetScanRequest # Предполагается, что модель определена
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -96,13 +97,13 @@ def clear_all_data(translations: Translations = Depends(get_translations())):
|
|||
DEVICE_PATH = "storage/devices/devices.json"
|
||||
WIFI_PATH = "storage/wifi/wifi.json"
|
||||
|
||||
@router.get("/export_devices", response_class=FileResponse)
|
||||
async def export_devices(subnet: str, translations: Translations = Depends(get_translations())):
|
||||
@router.post("/export_devices", response_class=FileResponse)
|
||||
async def export_devices(request: SubnetScanRequest = Body(...), translations: Translations = Depends(get_translations())):
|
||||
"""
|
||||
Экспортирует файл с данными устройств в формате JSON для указанной подсети.
|
||||
|
||||
Args:
|
||||
subnet (str): Подсеть в формате CIDR (например, "10.1.1.0/24").
|
||||
request (SubnetScanRequest): Объект с полем subnet в формате CIDR.
|
||||
translations: Объект переводов для текущего языка.
|
||||
|
||||
Returns:
|
||||
|
|
@ -111,10 +112,11 @@ async def export_devices(subnet: str, translations: Translations = Depends(get_t
|
|||
Raises:
|
||||
HTTPException: Если файл не найден (status_code=404).
|
||||
"""
|
||||
subnet = request.subnet
|
||||
file_path = f"storage/subnets/{subnet.replace('/', '_')}.json"
|
||||
if not os.path.exists(file_path):
|
||||
logger.warning(f"Export file not found: {file_path}")
|
||||
raise HTTPException(status_code=404, detail=translations.gettext("Файл не найден"))
|
||||
raise HTTPException(status_code=404, detail=translations.gettext("Файл для подсети {subnet} не найден").format(subnet=subnet))
|
||||
logger.info(f"Exporting file: {file_path}")
|
||||
return FileResponse(
|
||||
path=file_path,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue