diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-22 18:19:49 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-22 18:19:49 +0500 |
| commit | 0e261a67be8f770d7a3d4ca8d9bc12c02dd2b93a (patch) | |
| tree | fe40e26b642e950beba3296788567bb23eea28e1 /public/emotes | |
| parent | 4e6193e82532967ff7159c91050a6bf33dceab1a (diff) | |
feat: return json response in emotes.php
Diffstat (limited to 'public/emotes')
| -rw-r--r-- | public/emotes/index.php | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/public/emotes/index.php b/public/emotes/index.php index 475e119..b3834c3 100644 --- a/public/emotes/index.php +++ b/public/emotes/index.php @@ -29,7 +29,7 @@ function display_list_emotes(PDO &$db, int $page, int $limit): array FROM emote_set_contents ec INNER JOIN emote_sets es ON es.id = ec.emote_set_id WHERE ec.emote_id = e.id AND es.owner_id = ? - ) THEN 1 ELSE 0 END AS is_in_user_set, COALESCE(SUM(r.rate), 0) AS rating + ) THEN 1 ELSE 0 END AS is_in_user_set, COALESCE(COUNT(r.rate), 0) AS rating FROM emotes e LEFT JOIN ratings AS r ON r.emote_id = e.id WHERE e.code LIKE ? @@ -89,6 +89,15 @@ function display_emote(PDO &$db, int $id) } if ($emote == null) { + if (CLIENT_REQUIRES_JSON) { + json_response([ + "status_code" => 404, + "message" => "Emote ID $id does not exist", + "data" => null + ], 404); + exit; + } + header("Location: /404.php"); exit; } @@ -110,6 +119,15 @@ if ($id == "" || !is_numeric($id)) { } else { $emote = display_emote($db, intval($id)); } + +if (CLIENT_REQUIRES_JSON) { + json_response([ + "status_code" => 200, + "message" => null, + "data" => $emotes ?? $emote + ]); + exit; +} ?> <html> |
