More sample exposed api's

FossilOrigin-Name: fe08857971fcd1f3c48db6f7b464327c977134b938a600963328b04a6f624b83
This commit is contained in:
nekobit 2022-10-11 01:14:49 +00:00
parent 2a06ffa86c
commit 6b047d9160
2 changed files with 67 additions and 0 deletions

View file

@ -95,6 +95,69 @@ HTTP::Response Route::ActivityPub::user_outbox(std::any& args, const HTTP::Reque
return HTTP::Response( rjson::to_string(root), HTTP::MIME::JSON );
}
HTTP::Response Route::ActivityPub::user_followers(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg)
{
using namespace std::string_literals;
DESTRUCT_WORMHOLE_ARGS(args);
rjson::Document root(rjson::kObjectType);
rjson::Document::AllocatorType& a = root.GetAllocator();
// Stored result of account string, stripped from resource
User user;
try
{
user = db->get_user(arg.at(0));
}
catch (...) {
return HTTP::Error::make_json_error_response("Couldn't find user", HTTP::Code::NOT_FOUND);
}
root.AddMember("@context", "https://www.w3.org/ns/activitystreams", a);
const std::string outbox_url = Instance::instance_host_https(true) + "users/" + user.acct + "/followers";
root.AddMember("id", outbox_url, a);
root.AddMember("first", outbox_url + "?page=1", a);
root.AddMember("totalItems", 0, a);
root.AddMember("type", "OrderedCollection", a);
return HTTP::Response( rjson::to_string(root), HTTP::MIME::JSON );
}
HTTP::Response Route::ActivityPub::user_following(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg)
{
using namespace std::string_literals;
DESTRUCT_WORMHOLE_ARGS(args);
rjson::Document root(rjson::kObjectType);
rjson::Document::AllocatorType& a = root.GetAllocator();
// Stored result of account string, stripped from resource
User user;
try
{
user = db->get_user(arg.at(0));
}
catch (...) {
return HTTP::Error::make_json_error_response("Couldn't find user", HTTP::Code::NOT_FOUND);
}
root.AddMember("@context", "https://www.w3.org/ns/activitystreams", a);
const std::string outbox_url = Instance::instance_host_https(true) + "users/" + user.acct + "/following";
root.AddMember("id", outbox_url, a);
root.AddMember("first", outbox_url + "?page=1", a);
root.AddMember("totalItems", 0, a);
root.AddMember("type", "OrderedCollection", a);
return HTTP::Response( rjson::to_string(root), HTTP::MIME::JSON );
}
HTTP::Response Route::ActivityPub::user(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg)
{
using namespace std::string_literals;
@ -135,5 +198,7 @@ void ActivityPub::init_activitypub(HTTP::Server* server)
{
server->add_route({{HTTP::Request::Type::GET, "/users/:/inbox"}, Route::ActivityPub::user_inbox});
server->add_route({{HTTP::Request::Type::GET, "/users/:/outbox"}, Route::ActivityPub::user_outbox});
server->add_route({{HTTP::Request::Type::GET, "/users/:/following"}, Route::ActivityPub::user_following});
server->add_route({{HTTP::Request::Type::GET, "/users/:/followers"}, Route::ActivityPub::user_followers});
server->add_route({{HTTP::Request::Type::GET, "/users/:"}, Route::ActivityPub::user});
}

View file

@ -31,6 +31,8 @@ namespace Route
{
HTTP::Response user_inbox(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg);
HTTP::Response user_outbox(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg);
HTTP::Response user_following(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg);
HTTP::Response user_followers(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg);
HTTP::Response user(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg);
}
}