This commit is contained in:
parent
24d9a945b3
commit
c2bcc86527
12 changed files with 252 additions and 83 deletions
|
|
@ -818,7 +818,8 @@ void RealmController::getLiveRealms(const HttpRequestPtr &,
|
|||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
auto dbClient = app().getDbClient();
|
||||
// SECURITY: Do NOT expose stream_key in public API - it allows stream hijacking
|
||||
*dbClient << "SELECT r.name, r.viewer_count, r.viewer_multiplier, u.username, u.avatar_url "
|
||||
*dbClient << "SELECT r.name, r.viewer_count, r.viewer_multiplier, r.offline_image_url, r.title_color, "
|
||||
"u.username, u.avatar_url "
|
||||
"FROM realms r JOIN users u ON r.user_id = u.id "
|
||||
"WHERE r.is_live = true AND r.is_active = true "
|
||||
"ORDER BY (r.viewer_count * COALESCE(r.viewer_multiplier, 1)) DESC"
|
||||
|
|
@ -842,6 +843,8 @@ void RealmController::getLiveRealms(const HttpRequestPtr &,
|
|||
realm["viewerCount"] = static_cast<Json::Int64>(displayCount);
|
||||
realm["username"] = row["username"].as<std::string>();
|
||||
realm["avatarUrl"] = row["avatar_url"].isNull() ? "" : row["avatar_url"].as<std::string>();
|
||||
realm["offlineImageUrl"] = row["offline_image_url"].isNull() ? "" : row["offline_image_url"].as<std::string>();
|
||||
realm["titleColor"] = row["title_color"].isNull() ? "#ffffff" : row["title_color"].as<std::string>();
|
||||
resp.append(realm);
|
||||
}
|
||||
|
||||
|
|
@ -1435,4 +1438,25 @@ void RealmController::updateTitleColor(const HttpRequestPtr &req,
|
|||
>> DB_ERROR(callback, "update title color");
|
||||
}
|
||||
>> DB_ERROR(callback, "check realm ownership");
|
||||
}
|
||||
|
||||
// Internal endpoint for Lua thumbnail generator to lookup stream key by realm name
|
||||
void RealmController::getStreamKeyByRealmName(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &realmName) {
|
||||
auto dbClient = app().getDbClient();
|
||||
|
||||
*dbClient << "SELECT stream_key FROM realms WHERE name = $1 AND is_live = true AND is_active = true"
|
||||
<< realmName
|
||||
>> [callback](const Result& r) {
|
||||
if (r.empty()) {
|
||||
callback(jsonError("Realm not found or not live", k404NotFound));
|
||||
return;
|
||||
}
|
||||
|
||||
Json::Value resp;
|
||||
resp["streamKey"] = r[0]["stream_key"].as<std::string>();
|
||||
callback(jsonResp(resp));
|
||||
}
|
||||
>> DB_ERROR(callback, "get stream key by realm name");
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ public:
|
|||
ADD_METHOD_TO(RealmController::addRealmModerator, "/api/realms/{1}/moderators", Post);
|
||||
ADD_METHOD_TO(RealmController::removeRealmModerator, "/api/realms/{1}/moderators/{2}", Delete);
|
||||
ADD_METHOD_TO(RealmController::updateTitleColor, "/api/realms/{1}/title-color", Put);
|
||||
ADD_METHOD_TO(RealmController::getStreamKeyByRealmName, "/internal/realm-stream-key/{1}", Get);
|
||||
METHOD_LIST_END
|
||||
|
||||
void getUserRealms(const HttpRequestPtr &req,
|
||||
|
|
@ -105,4 +106,8 @@ public:
|
|||
void updateTitleColor(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &realmId);
|
||||
|
||||
void getStreamKeyByRealmName(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &realmName);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue