Do not hide WebSocket API when missing permission (#6186)
This commit is contained in:
@@ -221,16 +221,12 @@ void PluginController::initSol(sol::state_view &lua, Plugin *plugin)
|
||||
lua::api::ChannelRef::createUserType(c2);
|
||||
lua::api::HTTPResponse::createUserType(c2);
|
||||
lua::api::HTTPRequest::createUserType(c2);
|
||||
lua::api::WebSocket::createUserType(c2, plugin);
|
||||
c2["ChannelType"] = lua::createEnumTable<Channel::Type>(lua);
|
||||
c2["HTTPMethod"] = lua::createEnumTable<NetworkRequestType>(lua);
|
||||
c2["EventType"] = lua::createEnumTable<lua::api::EventType>(lua);
|
||||
c2["LogLevel"] = lua::createEnumTable<lua::api::LogLevel>(lua);
|
||||
|
||||
if (plugin->hasNetworkPermission())
|
||||
{
|
||||
lua::api::WebSocket::createUserType(c2, plugin);
|
||||
}
|
||||
|
||||
sol::table io = g["io"];
|
||||
io.set_function(
|
||||
"open", sol::overload(&lua::api::io_open, &lua::api::io_open_modeless));
|
||||
|
||||
@@ -31,6 +31,11 @@ void WebSocket::createUserType(sol::table &c2, Plugin *plugin)
|
||||
c2.new_usertype<WebSocket>(
|
||||
"WebSocket",
|
||||
sol::factories([plugin](const QString &spec, sol::variadic_args args) {
|
||||
if (!plugin->hasNetworkPermission())
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"Plugin does not have permission to use websockets");
|
||||
}
|
||||
QUrl url(spec);
|
||||
if (url.scheme() != "wss" && url.scheme() != "ws")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user