Reduce log spam in case of invalid token
Some checks failed
debian-build / build (push) Has been cancelled
Check locale / ubuntu64 (push) Has been cancelled
Push to master / Check Formatting 🔍 (push) Has been cancelled
Push to master / Build Project 🧱 (push) Has been cancelled
Push to master / Create Release 🛫 (push) Has been cancelled

The caching mechanism for the token validity checks did not have the
desired effect, and the Twitch channel to user id mapping function was
attempting to resolve names even with an invalid token.
This commit is contained in:
WarmUpTill
2025-05-05 21:55:38 +02:00
committed by WarmUpTill
parent 13dba6527d
commit f13beaead2
4 changed files with 65 additions and 29 deletions

View File

@@ -31,6 +31,11 @@ void TwitchChannel::Save(obs_data_t *obj) const
std::string TwitchChannel::GetUserID(const TwitchToken &token) const
{
static std::map<std::string, std::string> userIDCache;
if (!token.IsValid()) {
vblog(LOG_INFO, "%s() failed: token invalid", __func__);
return "invalid";
}
auto it = userIDCache.find(std::string(_name));
if (it != userIDCache.end()) {
return it->second;
@@ -47,7 +52,7 @@ std::string TwitchChannel::GetUserID(const TwitchToken &token) const
}
if (res.status != 200) {
blog(LOG_INFO, "failed to get Twitch user id from token! (%d)",
blog(LOG_INFO, "failed to get Twitch user id for channel! (%d)",
res.status);
return "invalid";
}
@@ -90,7 +95,7 @@ getStringArrayHelper(const OBSDataAutoRelease &data, const std::string &value)
}
try {
auto json = nlohmann::json::parse(jsonStr);
auto array = json[value];
auto &array = json[value];
if (!array.is_array()) {
return result;
}
@@ -104,7 +109,7 @@ getStringArrayHelper(const OBSDataAutoRelease &data, const std::string &value)
}
std::optional<ChannelLiveInfo>
TwitchChannel::GetLiveInfo(const TwitchToken &token)
TwitchChannel::GetLiveInfo(const TwitchToken &token) const
{
auto id = GetUserID(token);
if (!IsValid(id)) {
@@ -146,7 +151,8 @@ TwitchChannel::GetLiveInfo(const TwitchToken &token)
return info;
}
std::optional<ChannelInfo> TwitchChannel::GetInfo(const TwitchToken &token)
std::optional<ChannelInfo>
TwitchChannel::GetInfo(const TwitchToken &token) const
{
auto id = GetUserID(token);
if (!IsValid(id)) {