Fix specifically getting posts from Akkoma instances

social.kernel.org
This commit is contained in:
blankie 2023-11-29 15:31:26 +11:00
parent 6130e92114
commit 57202de5e8
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
5 changed files with 10 additions and 20 deletions

View File

@ -121,7 +121,7 @@ std::vector<Post> MastodonClient::get_posts(const std::string& host, const std::
query += '&';
}
query += "max_id=";
query += std::move(*max_id);
query += url_encode(std::move(*max_id));
}
std::string url = "https://"s + host + "/api/v1/accounts/" + account_id + "/statuses";
@ -138,11 +138,11 @@ std::vector<Post> MastodonClient::get_posts(const std::string& host, const std::
return posts;
}
std::optional<Post> MastodonClient::get_post(const std::string& host, const std::string& id) {
std::optional<Post> MastodonClient::get_post(const std::string& host, std::string id) {
using namespace std::string_literals;
try {
Post post = this->_send_request(std::nullopt, "https://"s + host + "/api/v1/statuses/" + id);
Post post = this->_send_request(std::nullopt, "https://"s + host + "/api/v1/statuses/" + url_encode(std::move(id)));
handle_post_server(post, host);
return post;
} catch (const MastodonException& e) {
@ -154,10 +154,10 @@ std::optional<Post> MastodonClient::get_post(const std::string& host, const std:
}
}
PostContext MastodonClient::get_post_context(const std::string& host, const std::string& id) {
PostContext MastodonClient::get_post_context(const std::string& host, std::string id) {
using namespace std::string_literals;
PostContext context = this->_send_request(std::nullopt, "https://"s + host + "/api/v1/statuses/" + id + "/context");
PostContext context = this->_send_request(std::nullopt, "https://"s + host + "/api/v1/statuses/" + url_encode(std::move(id)) + "/context");
for (Post& post : context.ancestors) {
handle_post_server(post, host);
@ -175,7 +175,7 @@ std::vector<Post> MastodonClient::get_tag_timeline(const std::string& host, cons
std::string url = "https://"s + host + "/api/v1/timelines/tag/" + url_encode(tag);
if (max_id) {
url += "?max_id=";
url += std::move(*max_id);
url += url_encode(std::move(*max_id));
}
std::vector<Post> posts = this->_send_request(std::nullopt, url);

View File

@ -68,8 +68,8 @@ public:
std::vector<Post> get_pinned_posts(std::string host, const std::string& account_id);
std::vector<Post> get_posts(const std::string& host, const std::string& account_id, PostSortingMethod sorting_method, std::optional<std::string> max_id);
std::optional<Post> get_post(const std::string& host, const std::string& id);
PostContext get_post_context(const std::string& host, const std::string& id);
std::optional<Post> get_post(const std::string& host, std::string id);
PostContext get_post_context(const std::string& host, std::string id);
std::vector<Post> get_tag_timeline(const std::string& host, const std::string& tag, std::optional<std::string> max_id);

View File

@ -48,8 +48,8 @@ int main(int argc, char** argv) {
serve_redirect(req, res, get_origin(req) + '/' + req.matches.str(1) + "/@" + req.matches.str(2) + req.matches.str(3), true);
});
server.Get("/(" DOMAIN_RE ")/@" ACCT_RE "/(\\d+)", status_route);
server.Get("/(" DOMAIN_RE ")/users/(" ACCT_RE ")/statuses/(\\d+)", [](const httplib::Request& req, httplib::Response& res) {
server.Get("/(" DOMAIN_RE ")/@" ACCT_RE "/([a-zA-Z0-9]+)", status_route);
server.Get("/(" DOMAIN_RE ")/users/(" ACCT_RE ")/statuses/([a-zA-Z0-9]+)", [](const httplib::Request& req, httplib::Response& res) {
serve_redirect(req, res, get_origin(req) + '/' + req.matches.str(1) + "/@" + req.matches.str(2) + '/' + req.matches.str(3), true);
});

View File

@ -11,11 +11,6 @@ void tags_route(const httplib::Request& req, httplib::Response& res) {
std::optional<std::string> max_id;
if (req.has_param("max_id")) {
max_id = req.get_param_value("max_id");
if (max_id->empty() || max_id->find_first_not_of("0123456789") != std::string::npos) {
res.status = 400;
serve_error(req, res, "400: Bad Request", "Invalid max_id query paramter");
return;
}
}
std::vector<Post> posts;

View File

@ -22,11 +22,6 @@ void user_route(const httplib::Request& req, httplib::Response& res) {
std::optional<std::string> max_id;
if (req.has_param("max_id")) {
max_id = req.get_param_value("max_id");
if (max_id->empty() || max_id->find_first_not_of("0123456789") != std::string::npos) {
res.status = 400;
serve_error(req, res, "400: Bad Request", "Invalid max_id query paramter");
return;
}
}
std::optional<Account> account;