feat: menu contextuel Déplacer/Dupliquer sidebar + réparation drag & drop interne #201 #BUG-117
This commit is contained in:
@@ -34,6 +34,8 @@ from backend.schemas import (
|
||||
FileCreateRequest,
|
||||
FileCreateResponse,
|
||||
FileDeleteResponse,
|
||||
FileDuplicateRequest,
|
||||
FileDuplicateResponse,
|
||||
FileMoveRequest,
|
||||
FileMoveResponse,
|
||||
FileRenameRequest,
|
||||
@@ -55,6 +57,9 @@ from backend.services.mutations import (
|
||||
from backend.services.mutations import (
|
||||
delete_file as service_delete_file,
|
||||
)
|
||||
from backend.services.mutations import (
|
||||
duplicate_path as service_duplicate_path,
|
||||
)
|
||||
from backend.services.mutations import (
|
||||
edit_file as service_edit_file,
|
||||
)
|
||||
@@ -743,3 +748,41 @@ async def api_file_move(
|
||||
await dispatch_webhooks("item_moved", {"vault": vault_name, "old_path": old_path_str, "new_path": new_path_str, "item_type": item_type})
|
||||
|
||||
return {"success": True, "old_path": old_path_str, "new_path": new_path_str, "item_type": item_type}
|
||||
|
||||
@router.post("/api/duplicate/{vault_name}", response_model=FileDuplicateResponse)
|
||||
async def api_file_duplicate(
|
||||
vault_name: str,
|
||||
body: FileDuplicateRequest,
|
||||
current_user=Depends(require_auth),
|
||||
):
|
||||
"""Duplicate (copy) a file or directory within the same vault."""
|
||||
if not check_vault_access(vault_name, current_user):
|
||||
raise HTTPException(status_code=403, detail=f"Accès refusé à la vault '{vault_name}'")
|
||||
|
||||
result = service_duplicate_path(vault_name, body.source_path, body.destination_dir)
|
||||
new_path_str = result["new_path"]
|
||||
item_type = result["item_type"]
|
||||
|
||||
# Index: incrémental pour chaque fichier copié (évite un reload complet).
|
||||
from backend.services.vaults import get_vault_root
|
||||
root = get_vault_root(vault_name)
|
||||
target = root / new_path_str
|
||||
if item_type == "directory":
|
||||
for fp in sorted(target.rglob("*")):
|
||||
if fp.is_file():
|
||||
await update_single_file(vault_name, str(fp.relative_to(root)).replace("\\", "/"))
|
||||
else:
|
||||
await update_single_file(vault_name, new_path_str)
|
||||
|
||||
await sse_manager.broadcast("item_duplicated", {
|
||||
"vault": vault_name,
|
||||
"source_path": result["source_path"],
|
||||
"new_path": new_path_str,
|
||||
"item_type": item_type,
|
||||
})
|
||||
await dispatch_webhooks(
|
||||
"file_created" if item_type == "file" else "directory_created",
|
||||
{"vault": vault_name, "path": new_path_str},
|
||||
)
|
||||
|
||||
return {"success": True, "source_path": result["source_path"], "new_path": new_path_str, "item_type": item_type}
|
||||
|
||||
Reference in New Issue
Block a user