From 4da453ba7cd09849d7c3c1229188e1ee3b3866be Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 31 May 2025 22:57:28 +0400 Subject: fix: redirect to the file if it's not a JSON request --- public/upload.php | 13 +++++++++++-- 1 file 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 -- cgit v1.2.3