2023-11-23 06:05:17 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2023-11-23 08:49:27 +00:00
|
|
|
if (post->reblog) {
|
|
|
|
serve_redirect(req, res, get_origin(req) + '/' + server + "/@" + post->reblog->account.acct(false) + '/' + post->reblog->id, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-23 06:05:17 +00:00
|
|
|
Element body("body", {
|
|
|
|
serialize_post(req, server, *post),
|
|
|
|
});
|
|
|
|
serve(req, res, "", std::move(body));
|
|
|
|
}
|