Spaces:
Running
Running
File size: 1,029 Bytes
dd87944 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | """Traitement fichiers — conversion basique stub."""
from __future__ import annotations
from pathlib import Path
from typing import Any
from emo.desktop.actions._base import SkillResult
def run(args: dict) -> Any:
path = args.get("path") or args.get("query") or ""
p = Path(path).expanduser()
if not p.is_file():
return SkillResult.fail("Fichier requis")
suffix = p.suffix.lower()
if suffix == ".txt":
lines = p.read_text(encoding="utf-8", errors="replace").splitlines()
return SkillResult.ok(lines=len(lines), preview="\n".join(lines[:10]), message=f"{len(lines)} lignes")
if suffix == ".json":
import json
data = json.loads(p.read_text(encoding="utf-8"))
return SkillResult.ok(keys=list(data.keys()) if isinstance(data, dict) else type(data).__name__, message="JSON chargé")
return SkillResult.ok(
path=str(p),
size=p.stat().st_size,
message=f"Fichier {suffix or 'sans extension'} — traitement avancé Phase 2",
)
|