summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-05-31 22:57:28 +0400
committerilotterytea <iltsu@alright.party>2025-05-31 22:57:28 +0400
commit4da453ba7cd09849d7c3c1229188e1ee3b3866be (patch)
treef7e28b16d7b1d194904489d5d2248282e0ef7d5c /public
parentf3a8aa77b1c9a6918ec3630e990b6e3bf1bb7b67 (diff)
fix: redirect to the file if it's not a JSON request
Diffstat (limited to 'public')
-rw-r--r--public/upload.php13
1 files changed, 11 insertions, 2 deletions
diff --git a/public/upload.php b/public/upload.php
index 9eecf30..3ef0a0c 100644
--- a/public/upload.php
+++ b/public/upload.php
@@ -118,7 +118,16 @@ try {
throw new RuntimeException("Failed to save the file. Try again later.");
}
- json_response($file_data, null, 201);
+ if ($_SERVER['HTTP_ACCEPT'] == 'application/json') {
+ json_response($file_data, null, 201);
+ } else {
+ header("Location: /{$file_data['id']}.{$file_data['extension']}");
+ }
} catch (RuntimeException $e) {
- json_response(null, $e->getMessage(), 400);
+ if ($_SERVER['HTTP_ACCEPT'] == 'application/json') {
+ json_response(null, $e->getMessage(), 400);
+ } else {
+ http_response_code(400);
+ echo $e->getMessage();
+ }
} \ No newline at end of file