false, 'ERROR' => 'method_not_allowed'], 405); } $channelId = (int) ($_GET['ChannelID'] ?? 0); $limit = min(max((int) ($_GET['Limit'] ?? 50), 1), 200); $offset = max((int) ($_GET['Offset'] ?? 0), 0); if ($channelId <= 0) jsonResponse(['OK' => false, 'ERROR' => 'channel_id_required']); $total = (int) (queryOne( "SELECT COUNT(*) as cnt FROM Hub_Files WHERE ChannelID = ?", [$channelId] )['cnt'] ?? 0); $rows = queryTimed( "SELECT * FROM Hub_Files WHERE ChannelID = ? ORDER BY CreatedAt DESC LIMIT ? OFFSET ?", [$channelId, $limit, $offset] ); $files = []; foreach ($rows as $r) { $files[] = [ 'ID' => (int) $r['ID'], 'MessageID' => $r['MessageID'] ? (int) $r['MessageID'] : null, 'ChannelID' => (int) $r['ChannelID'], 'UploaderAddress' => $r['UploaderAddress'], 'FileName' => $r['FileName'], 'FileSize' => (int) $r['FileSize'], 'MimeType' => $r['MimeType'], 'DownloadURL' => baseUrl() . '/' . $r['StoragePath'], 'ThumbnailURL' => $r['ThumbnailPath'] ? baseUrl() . '/' . $r['ThumbnailPath'] : null, 'CreatedAt' => toISO8601($r['CreatedAt']), ]; } jsonResponse([ 'OK' => true, 'Files' => $files, 'Total' => $total, ]);