summaryrefslogtreecommitdiff
path: root/public/delete.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-06-08 02:15:49 +0400
committerilotterytea <iltsu@alright.party>2025-06-08 02:15:49 +0400
commit738bc1f237923806902fa2755b85566a4a845717 (patch)
tree6d0762995522e42bdc6103ade1bc1f9ee07860e9 /public/delete.php
parent9a58eaae53bdd2a4fcdd66b1eb852c7db7970de9 (diff)
feat: display alert
Diffstat (limited to 'public/delete.php')
-rw-r--r--public/delete.php63
1 files changed, 51 insertions, 12 deletions
diff --git a/public/delete.php b/public/delete.php
index 453e0b3..2ca1d73 100644
--- a/public/delete.php
+++ b/public/delete.php
@@ -2,11 +2,16 @@
include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/utils.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/file.php';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/alert.php';
session_start();
if (!FILE_DELETION) {
- json_response(null, 'File deletion is not allowed!', 403);
+ generate_alert(
+ '/',
+ "File deletion is not allowed",
+ 403
+ );
exit();
}
@@ -14,7 +19,11 @@ $file_id = $_GET['f'] ?? null;
$password = $_GET['key'] ?? null;
if (!isset($file_id)) {
- json_response(null, "File ID must be set!", 400);
+ generate_alert(
+ '/',
+ "File ID must be set!",
+ 400
+ );
exit();
}
@@ -23,46 +32,76 @@ $file_ext = $file_id[1];
$file_id = $file_id[0];
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $file_id) || !preg_match('/^[a-zA-Z0-9]+$/', $file_ext)) {
- json_response(null, "Invalid file ID or extension", 400);
+ generate_alert(
+ '/',
+ "Invalid file ID or extension",
+ 400
+ );
exit();
}
if (!is_file(FILE_UPLOAD_DIRECTORY . "/{$file_id}.{$file_ext}")) {
- json_response(null, "File {$file_id} not found", 404);
+ generate_alert(
+ "/",
+ "File $file_id not found",
+ 404
+ );
exit();
}
if (!is_file(FILE_METADATA_DIRECTORY . "/{$file_id}.metadata.json")) {
- json_response(null, "File metadata {$file_id} not found", 404);
+ generate_alert(
+ "/$file_id.$file_ext",
+ "File metadata $file_id not found",
+ 404
+ );
exit();
}
$metadata = json_decode(file_get_contents(FILE_METADATA_DIRECTORY . "/{$file_id}.metadata.json"), true);
if (!array_key_exists('password', $metadata)) {
- json_response(null, "File {$file_id} does not have a password. File cannot be deleted!", 400);
+ generate_alert(
+ "/$file_id.$file_ext",
+ "File $file_id does not have a password. File cannot be deleted!",
+ 400
+ );
exit();
}
if (!isset($_SESSION['is_moderator']) && !isset($password)) {
- json_response(null, "Field 'key' must be set!", 400);
+ generate_alert(
+ "/$file_id.$file_ext",
+ "Field 'key' must be set!",
+ 400
+ );
exit();
}
if (!isset($_SESSION['is_moderator']) && !password_verify($password, $metadata['password'])) {
- json_response(null, "Bad password", 401);
+ generate_alert(
+ "/$file_id.$file_ext",
+ 'Unauthorized',
+ 401
+ );
exit();
}
if (!delete_file($file_id, $file_ext)) {
- json_response(null, 'Failed to remove files. Try again later.', 500);
+ generate_alert(
+ "/$file_id.$file_ext",
+ 'Failed to remove files. Try again later',
+ 500
+ );
exit();
}
-json_response(
+generate_alert(
+ $_GET['r'] ?? '/',
+ 'Successfully deleted the file',
+ 200,
[
'id' => $file_id,
'extension' => $file_ext
- ],
- 'Successfully deleted the file'
+ ]
); \ No newline at end of file