1
0
Fork 0
mirror of https://gitlab.com/niansa/commsy-rest.git synced 2025-03-06 20:48:27 +01:00

Added fetchDescription endpoint

This commit is contained in:
niansa 2020-11-11 16:52:47 +00:00
parent 116fd3a6ae
commit 42c6a9a67e
No known key found for this signature in database
GPG key ID: 77CD5505A61493C8
2 changed files with 24 additions and 1 deletions

View file

@ -78,6 +78,29 @@ int main() {
}, {Get}
);
app().registerHandler("/fetchDescription?url={postUrl}&sid={sid}",
[](const HttpRequestPtr& /*req*/, std::function<void (const HttpResponsePtr &)> &&callback,
const std::string &postUrl, const std::string &sid)
{
// Load data from server
std::string resStr = "unknown";
auto resCode = HttpStatusCode::k500InternalServerError;
try {
resStr = libCommsyLowlevel::get_post_desc(postUrl, sid);
resCode = HttpStatusCode::k200OK;
} catch (libCommsy::descDownloadError&) {
resStr = "invalidPost";
resCode = HttpStatusCode::k404NotFound;
}
// Repond
auto resp = HttpResponse::newHttpResponse();
resp->setBody(resStr);
resp->setStatusCode(resCode);
callback(resp);
}, {Get}
);
// Start server
app().setLogPath("./")

@ -1 +1 @@
Subproject commit 6f2c9286e2d33462c4f4c2edc62415c556c1714f
Subproject commit b45564a40854b631fc086a8af917b48dbcb3a244