Add delete actions

This commit is contained in:
Mikei386
2026-06-23 20:18:49 +02:00
parent 522b9f4665
commit 59cdfd975f
8 changed files with 44 additions and 4 deletions
@@ -6,7 +6,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
$action = $_GET['action'] ?? '';
if (!in_array($action, ['move', 'copy', 'size', 'permissions'], true)) {
if (!in_array($action, ['move', 'copy', 'delete', 'size', 'permissions'], true)) {
unav_error(404, 'Unknown job action');
}
@@ -18,6 +18,8 @@ if (in_array($action, ['move', 'copy'], true)) {
unav_assert_writable();
$destination = unav_destination_path($data['destination'] ?? null);
unav_guard_destination($source['path'], $destination['path']);
} elseif ($action === 'delete') {
unav_assert_writable();
} elseif ($action === 'permissions') {
unav_assert_writable();
$permissions = unav_permission_options($data);
@@ -16,6 +16,8 @@ function unav_run_job(string $id): void {
} elseif ($job['type'] === 'copy') {
unav_worker_guard($job['source'], $job['destination']);
unav_worker_copy($job['source'], $job['destination'], $job);
} elseif ($job['type'] === 'delete') {
unav_worker_delete_job($job['source'], $job);
} elseif ($job['type'] === 'size') {
$result = unav_worker_size($job['source'], $job);
$job['result'] = $result;
@@ -90,6 +92,12 @@ function unav_worker_move(string $source, string $destination, array &$job): voi
unav_worker_delete($source);
}
function unav_worker_delete_job(string $source, array &$job): void {
$sourceReal = unav_worker_guard_source($source);
unav_worker_update($job, 'running', 15, 'Deleting');
unav_worker_delete($sourceReal);
}
function unav_worker_size(string $source, array &$job): array {
$sourceReal = unav_worker_guard_source($source);
unav_worker_update($job, 'running', 10, 'Calculating size');