Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alicealys committed Jun 14, 2022
1 parent c177f16 commit b81928d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
33 changes: 5 additions & 28 deletions src/component/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,25 @@ namespace io
scripting::script_value http_get(const gsc::function_args& args)
{
const auto url = args[0].as<std::string>();
const auto object = scripting::entity(scripting::make_object());
const scripting::object object{};
const auto object_id = object.get_entity_id();

scheduler::once([object, url]()
scheduler::once([object_id, url]()
{
const auto result = utils::http::get_data(url.data());
scheduler::once([object, result]()
scheduler::once([object_id, result]()
{
const auto value = result.has_value()
? result.value().substr(0, 0x5000)
: "";
scripting::notify(object, "done", {value});
scripting::notify(object_id, "done", {value});
});
}, scheduler::pipeline::async);

return object;
}
}

std::string execute_command(const std::string& cmd)
{
const auto handle = _popen(cmd.data(), "r");
char* buffer = (char*)calloc(256, sizeof(char));
std::string result;

if (!handle)
{
return "";
}

while (!feof(handle))
{
if (fgets(buffer, 256, handle))
{
result += buffer;
}
}

_pclose(handle);

return result;
}

class component final : public component_interface
{
public:
Expand Down
2 changes: 1 addition & 1 deletion src/component/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace io
{
std::string execute_command(const std::string& cmd);

}

0 comments on commit b81928d

Please sign in to comment.