feat: auto-refresh AJAX, bouton transfert entre comptes, webhook par compte

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jules
2026-05-05 15:39:49 +02:00
parent 1ef093f5ec
commit 0d4998e129
6 changed files with 281 additions and 69 deletions

60
web/api/transfer.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
require_once __DIR__ . '/../includes/db.php';
require_once __DIR__ . '/../includes/auth.php';
auth_check();
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405); echo json_encode(['error' => 'Method not allowed']); exit;
}
$sourceId = (int)($_POST['source_id'] ?? 0);
$targetId = (int)($_POST['target_id'] ?? 0);
if (!$sourceId || !$targetId) {
http_response_code(400); echo json_encode(['error' => 'Paramètres manquants']); exit;
}
// Récupère le compte destination
$target = db()->prepare('SELECT * FROM accounts WHERE id = ? AND active = 1');
$target->execute([$targetId]);
$targetAccount = $target->fetch();
if (!$targetAccount) {
http_response_code(404); echo json_encode(['error' => 'Compte destination introuvable']); exit;
}
// Récupère les fichiers à transférer
$files = db()->prepare('SELECT * FROM files WHERE source_file_id = ?');
$files->execute([$sourceId]);
$fileList = $files->fetchAll();
$destDir = $targetAccount['smb_path'];
if (!is_dir($destDir)) mkdir($destDir, 0750, true);
$moved = 0;
foreach ($fileList as $file) {
$newPath = $destDir . '/' . basename($file['path']);
// Évite collision
if (file_exists($newPath)) {
$ext = pathinfo($newPath, PATHINFO_EXTENSION);
$base = pathinfo($newPath, PATHINFO_FILENAME);
$newPath = $destDir . '/' . $base . '_' . time() . '.' . $ext;
}
if (file_exists($file['path'])) {
rename($file['path'], $newPath);
db()->prepare('UPDATE files SET path = ? WHERE id = ?')
->execute([$newPath, $file['id']]);
$moved++;
}
}
// Met à jour le compte source_file
db()->prepare('UPDATE source_file SET account_id = ? WHERE id = ?')
->execute([$targetId, $sourceId]);
echo json_encode([
'success' => true,
'moved' => $moved,
'target' => $targetAccount['username'],
]);