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:
parent
116fd3a6ae
commit
42c6a9a67e
2 changed files with 24 additions and 1 deletions
23
main.cpp
23
main.cpp
|
@ -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("./")
|
||||
|
|
2
qcommsy
2
qcommsy
|
@ -1 +1 @@
|
|||
Subproject commit 6f2c9286e2d33462c4f4c2edc62415c556c1714f
|
||||
Subproject commit b45564a40854b631fc086a8af917b48dbcb3a244
|
Loading…
Add table
Reference in a new issue