57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
"""Contrôleur pour obtenir les informations d'un fichier/dossier"""
|
|
from fastapi import APIRouter, HTTPException, Path
|
|
from fastapi.responses import JSONResponse
|
|
from nc_py_api import NextcloudException
|
|
from utils import get_nextcloud_client, format_file_info
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/info/{path:path}")
|
|
async def file_info(
|
|
path: str = Path(
|
|
...,
|
|
description="Chemin du fichier/dossier",
|
|
examples=["Documents/fichier.txt"]
|
|
)
|
|
):
|
|
"""
|
|
Obtient les informations détaillées d'un fichier ou dossier
|
|
|
|
Args:
|
|
path: Chemin du fichier/dossier
|
|
|
|
Returns:
|
|
JSON contenant les informations du fichier
|
|
"""
|
|
try:
|
|
nc = get_nextcloud_client()
|
|
|
|
# Normaliser le chemin
|
|
file_path = "/" + path.strip("/")
|
|
|
|
try:
|
|
file_info_data = nc.files.by_path(file_path)
|
|
except NextcloudException as e:
|
|
if "404" in str(e):
|
|
raise HTTPException(
|
|
status_code=404,
|
|
detail=f"Le fichier/dossier '{file_path}' n'existe pas"
|
|
)
|
|
else:
|
|
raise HTTPException(
|
|
status_code=500,
|
|
detail=f"Erreur Nextcloud: {str(e)}"
|
|
)
|
|
|
|
return JSONResponse(content=format_file_info(file_info_data))
|
|
|
|
except HTTPException:
|
|
raise
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=500,
|
|
detail=f"Erreur interne: {str(e)}"
|
|
)
|
|
|