Complete backend for SprintChat Hub migration: - Messages: send, edit, delete, list (paginated cursor), thread, search - Files: upload (multipart), download, thumbnail, info, list - Users: get, getByIds, search, status (online detection) - Reactions: add, remove, list (grouped by emoji) - Pins: pin, unpin, list (with message content) - Channel stats: member/message/pinned/unread counts 4 new DB tables: Hub_Messages, Hub_Files, Hub_Reactions, Hub_PinnedPosts 21 new endpoints added to PUBLIC_ROUTES Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* POST /api/hub/users/getByIds.php
|
|
*
|
|
* Get multiple agents by their IDs or addresses.
|
|
*
|
|
* Body:
|
|
* IDs int[] optional list of agent IDs
|
|
* Addresses string[] optional list of agent addresses
|
|
* (provide one or both)
|
|
*
|
|
* Response: { OK: true, Users: [...] }
|
|
*/
|
|
|
|
require_once __DIR__ . '/../../helpers.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
jsonResponse(['OK' => false, 'ERROR' => 'method_not_allowed'], 405);
|
|
}
|
|
|
|
$body = readJsonBody();
|
|
$ids = $body['IDs'] ?? [];
|
|
$addresses = $body['Addresses'] ?? [];
|
|
|
|
if (empty($ids) && empty($addresses)) {
|
|
jsonResponse(['OK' => false, 'ERROR' => 'ids_or_addresses_required']);
|
|
}
|
|
|
|
// Cap at 100
|
|
$ids = array_slice(array_map('intval', $ids), 0, 100);
|
|
$addresses = array_slice(array_map('trim', $addresses), 0, 100);
|
|
|
|
$users = [];
|
|
|
|
if (!empty($ids)) {
|
|
$placeholders = implode(',', array_fill(0, count($ids), '?'));
|
|
$rows = queryTimed("SELECT * FROM Sprinter_Agents WHERE ID IN ($placeholders)", $ids);
|
|
foreach ($rows as $a) $users[(int) $a['ID']] = $a;
|
|
}
|
|
|
|
if (!empty($addresses)) {
|
|
$placeholders = implode(',', array_fill(0, count($addresses), '?'));
|
|
$rows = queryTimed("SELECT * FROM Sprinter_Agents WHERE FullAddress IN ($placeholders)", $addresses);
|
|
foreach ($rows as $a) $users[(int) $a['ID']] = $a;
|
|
}
|
|
|
|
$formatted = [];
|
|
foreach ($users as $a) {
|
|
$formatted[] = [
|
|
'ID' => (int) $a['ID'],
|
|
'AgentName' => $a['AgentName'],
|
|
'FullAddress' => $a['FullAddress'],
|
|
'ProjectName' => $a['ProjectName'],
|
|
'AgentType' => $a['AgentType'],
|
|
'Role' => $a['Role'],
|
|
'ServerHost' => $a['ServerHost'],
|
|
'IsActive' => (bool) $a['IsActive'],
|
|
'CreatedAt' => toISO8601($a['CreatedAt']),
|
|
];
|
|
}
|
|
|
|
jsonResponse(['OK' => true, 'Users' => $formatted]);
|