feat(houseofrc): fetch driver names and brands by transponder (1.79.0)
This commit is contained in:
1 parent
0c54e8b58a
commit
3829ca1cab
17 files changed
+319
-7
No files matched your search
+23
-1
@@ -73,7 +73,29 @@ function createHouseOfRc({ dataDir, env = process.env, fetchImpl = globalThis.fe
|
||||
return { ok: true, status: result.status, user: body.user || null, rateLimit: body.rate_limit ?? null };
|
||||
}
|
||||
|
||||
return { status, setKey, get, testConnection };
|
||||
// Members owning these transponders (/timing/users, max 200 per call). The newest owner of a
|
||||
// transponder comes first, so the first hit per number wins.
|
||||
async function lookupTransponders(list) {
|
||||
const numbers = [...new Set((Array.isArray(list) ? list : []).map((value) => String(value || "").trim()).filter((value) => /^[A-Za-z0-9]{1,20}$/.test(value)))];
|
||||
const members = {};
|
||||
for (let index = 0; index < numbers.length; index += 200) {
|
||||
const result = await get("/timing/users", { transponders: numbers.slice(index, index + 200).join(",") });
|
||||
if (!result.ok) return result;
|
||||
(Array.isArray(result.data) ? result.data : []).forEach((user) => {
|
||||
const transponder = String(user?.transponder || "").trim();
|
||||
if (!transponder || members[transponder]) return;
|
||||
members[transponder] = {
|
||||
id: user.id ?? null,
|
||||
name: String(user.name || "").trim(),
|
||||
model: String(user.model?.name || "").trim(),
|
||||
brand: String(user.model?.brand?.name || "").trim(),
|
||||
};
|
||||
});
|
||||
}
|
||||
return { ok: true, status: 200, asked: numbers.length, members };
|
||||
}
|
||||
|
||||
return { status, setKey, get, testConnection, lookupTransponders };
|
||||
}
|
||||
|
||||
module.exports = { createHouseOfRc, DEFAULT_BASE_URL };
|
||||
Reference in new issue
Block a user