coyote/routes/status.cpp

35 lines
974 B
C++

#include "routes.h"
#include "../servehelper.h"
#include "../client.h"
#include "../models.h"
void status_route(const httplib::Request& req, httplib::Response& res) {
std::string server = req.matches.str(1);
std::string id = req.matches.str(2);
std::optional<Post> post;
try {
post = mastodon_client.get_post(server, id);
} catch (const std::exception& e) {
res.status = 500;
serve_error(req, res, "500: Internal server error", "Failed to fetch post information", e.what());
return;
}
if (!post) {
res.status = 404;
serve_error(req, res, "404: Post not found");
return;
}
if (post->reblog) {
serve_redirect(req, res, get_origin(req) + '/' + server + "/@" + post->reblog->account.acct(false) + '/' + post->reblog->id, true);
return;
}
Element body("body", {
serialize_post(req, server, *post),
});
serve(req, res, "", std::move(body));
}