From 2c51a000a9f2f51f54b761e4975086f9db3780a4 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 3 May 2025 16:50:50 +0500 Subject: upd: big changes in database.sql + .webp is now default image format --- public/emotes/upload.php | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'public/emotes/upload.php') diff --git a/public/emotes/upload.php b/public/emotes/upload.php index 137e29b..89abf44 100644 --- a/public/emotes/upload.php +++ b/public/emotes/upload.php @@ -225,6 +225,11 @@ if (is_null(list($mime, $ext) = get_mime_and_ext($image["tmp_name"]))) { exit; } +$notes = str_safe($_POST["notes"] ?? "", EMOTE_COMMENT_MAX_LENGTH); +if (empty($notes)) { + $notes = null; +} + $visibility = clamp(intval($_POST["visibility"], EMOTE_VISIBILITY_DEFAULT), 0, 2); if (MOD_EMOTES_APPROVE && $visibility == 1 && EMOTE_VISIBILITY_DEFAULT != 1) { @@ -234,21 +239,9 @@ if (MOD_EMOTES_APPROVE && $visibility == 1 && EMOTE_VISIBILITY_DEFAULT != 1) { // creating a new emote record $db = new PDO(DB_URL, DB_USER, DB_PASS); -$stmt = $db->prepare("INSERT INTO emotes(code, mime, ext, uploaded_by, visibility) VALUES (?, ?, ?, ?, ?)"); -$stmt->execute([$code, $mime, $ext, $uploaded_by, $visibility]); - -$id = $db->lastInsertId(); - -if ($id == 0) { - $db = null; - http_response_code(500); - echo json_encode([ - "status_code" => 500, - "message" => "Failed to create an emote record", - "data" => null - ]); - exit; -} +$id = bin2hex(random_bytes(16)); +$stmt = $db->prepare("INSERT INTO emotes(id, code, notes, uploaded_by, visibility) VALUES (?, ?, ?, ?, ?)"); +$stmt->execute([$id, $code, $notes, $uploaded_by, $visibility]); $path = "../static/userdata/emotes/$id"; -- cgit v1.2.3