api update.
This commit is contained in:
@@ -5119,20 +5119,71 @@ function registerTssTeamRoutes(teamBasePath) {
|
|||||||
if (!name) return res.status(400).json({ error: 'name query parameter is required' });
|
if (!name) return res.status(400).json({ error: 'name query parameter is required' });
|
||||||
loadTssTeamLookupCached((lookup) => {
|
loadTssTeamLookupCached((lookup) => {
|
||||||
const team = resolveTssTeam(name, lookup);
|
const team = resolveTssTeam(name, lookup);
|
||||||
|
|
||||||
|
if (!team.row) {
|
||||||
|
return res.status(404).json({
|
||||||
|
query: String(name),
|
||||||
|
resolved: false,
|
||||||
|
error: 'TSS team not found',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
query: String(name),
|
query: String(name),
|
||||||
resolved: !!team.row,
|
resolved: true,
|
||||||
clan_id: team.clanId,
|
clan_id: team.clanId,
|
||||||
long_name: team.canonicalName,
|
long_name: team.canonicalName,
|
||||||
short_name: team.row ? team.row.short_name : null,
|
short_name: team.row.short_name || null,
|
||||||
tag_name: team.tagName,
|
tag_name: team.tagName,
|
||||||
members: team.row ? team.row.members : null,
|
members: team.row.members,
|
||||||
clanrating: team.row ? team.row.clanrating : null,
|
clanrating: team.row.clanrating,
|
||||||
source: 'tss_teams.db'
|
source: 'tss_teams.db'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get(`${teamBasePath}/search`, (req, res) => {
|
||||||
|
const query = String(req.query.q || req.query.name || '').trim().toLowerCase();
|
||||||
|
const limit = Math.max(1, Math.min(parseInt(req.query.limit, 10) || 10, 20));
|
||||||
|
|
||||||
|
if (query.length < 2) {
|
||||||
|
return res.status(400).json({ error: 'q must be at least 2 characters' });
|
||||||
|
}
|
||||||
|
|
||||||
|
loadTssTeamLookupCached((lookup) => {
|
||||||
|
const seen = new Set();
|
||||||
|
|
||||||
|
const teams = Object.values(lookup || {})
|
||||||
|
.filter((row) => {
|
||||||
|
if (!row || row.clan_id == null) return false;
|
||||||
|
|
||||||
|
const key = String(row.clan_id);
|
||||||
|
if (seen.has(key)) return false;
|
||||||
|
seen.add(key);
|
||||||
|
|
||||||
|
return [row.long_name, row.short_name, row.tag_name, String(row.clan_id)]
|
||||||
|
.filter(Boolean)
|
||||||
|
.some((value) => String(value).toLowerCase().includes(query));
|
||||||
|
})
|
||||||
|
.slice(0, limit)
|
||||||
|
.map((row) => ({
|
||||||
|
resolved: true,
|
||||||
|
clan_id: row.clan_id,
|
||||||
|
long_name: row.long_name,
|
||||||
|
short_name: row.short_name,
|
||||||
|
tag_name: row.tag_name || row.short_name || row.long_name,
|
||||||
|
members: row.members,
|
||||||
|
clanrating: row.clanrating,
|
||||||
|
}));
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
query,
|
||||||
|
total_found: teams.length,
|
||||||
|
teams,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
app.get(`${teamBasePath}/:teamname`, (req, res) => {
|
app.get(`${teamBasePath}/:teamname`, (req, res) => {
|
||||||
if (!tssDb) return tssDbUnavailable(res);
|
if (!tssDb) return tssDbUnavailable(res);
|
||||||
if (!hasTssTeamColumn) {
|
if (!hasTssTeamColumn) {
|
||||||
|
|||||||
Reference in New Issue
Block a user