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:
34
web/api/mails.php
Normal file
34
web/api/mails.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../includes/db.php';
|
||||
require_once __DIR__ . '/../includes/auth.php';
|
||||
|
||||
auth_check();
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$rows = db()->query(
|
||||
'SELECT sf.id, sf.title, sf.sender, sf.date_processing, a.username,
|
||||
GROUP_CONCAT(f.id, ":", f.file_name, ":", f.path ORDER BY f.id SEPARATOR "|") as files
|
||||
FROM source_file sf
|
||||
LEFT JOIN accounts a ON sf.account_id = a.id
|
||||
LEFT JOIN files f ON sf.id = f.source_file_id
|
||||
GROUP BY sf.id
|
||||
ORDER BY sf.date_processing DESC'
|
||||
)->fetchAll();
|
||||
|
||||
// Vérifie l'existence physique des fichiers
|
||||
foreach ($rows as &$r) {
|
||||
$r['files_list'] = [];
|
||||
if ($r['files']) {
|
||||
foreach (explode('|', $r['files']) as $f) {
|
||||
[$fid, $fname, $fpath] = array_pad(explode(':', $f, 3), 3, '');
|
||||
$r['files_list'][] = [
|
||||
'id' => (int)$fid,
|
||||
'name' => $fname,
|
||||
'exists' => file_exists($fpath),
|
||||
];
|
||||
}
|
||||
}
|
||||
unset($r['files']);
|
||||
}
|
||||
|
||||
echo json_encode($rows);
|
||||
60
web/api/transfer.php
Normal file
60
web/api/transfer.php
Normal 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'],
|
||||
]);
|
||||
Reference in New Issue
Block a user