($r['created_at'] ?? '') > $since)); } json_response(['success' => true, 'replies' => array_slice($all, -100)]); } if ($method !== 'POST') { error_response('Method not allowed', 405); } $raw = file_get_contents('php://input'); if (!$raw) error_response('Empty request body'); if (strlen($raw) > 16384) error_response('Payload too large (max 16KB)', 413); $p = json_decode($raw, true); if (!is_array($p)) error_response('Invalid JSON'); $body = trim((string)($p['body'] ?? '')); if ($body === '') error_response('body is required'); if (mb_strlen($body) > 2000) $body = mb_substr($body, 0, 2000); $list = load_json(REPLIES_FILE); if (!is_array($list)) $list = []; $author = (($p['author'] ?? 'hermes') === 'newos4') ? 'newos4' : 'hermes'; $entry = [ 'id' => 'REP-' . gmdate('Ymd-His') . '-' . substr(bin2hex(random_bytes(3)), 0, 6), 'created_at' => gmdate('c'), 'author' => $author, 'body' => $body, ]; $list[] = $entry; save_json(REPLIES_FILE, array_slice($list, -200)); json_response(['success' => true, 'id' => $entry['id']], 201);