diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-09-12 14:28:32 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-09-12 14:28:32 +0100 |
| commit | fd2cdacf49b101658de7e0a624c84897a398e62e (patch) | |
| tree | 6ced81a91b56e20182d5dff77a1e09cffb2a0e29 /rotord/src/rotord.cpp | |
| parent | 119dbdb43b859b529112d49dbeb3e05831372f68 (diff) | |
thumbnail function
Diffstat (limited to 'rotord/src/rotord.cpp')
| -rw-r--r-- | rotord/src/rotord.cpp | 78 |
1 files changed, 76 insertions, 2 deletions
diff --git a/rotord/src/rotord.cpp b/rotord/src/rotord.cpp index bae169f..49770a4 100644 --- a/rotord/src/rotord.cpp +++ b/rotord/src/rotord.cpp @@ -45,7 +45,61 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS //can tinyxml output to a string? is there any reason to use poco instead? if (command.size()) { - if (command[0]=="new") { + if (command[0]=="thumbnail") { + XML.pushTag("rotor"); + if (request.getMethod()=="POST") { + if (body.size()){ + int w=360; + int h=180; + if (command.size()>1){ + Poco::StringTokenizer t1(command[1],","); + if (t1.count()>1){ + int _w=toInt(t1[0]); + int _h=toInt(t1[1]); + if (_h>16&&_w>16){ + w=_w; + h=_h; + } + } + } + Thumbnailer thumb; + Poco::StringTokenizer t1(body,"."); + if (t1.count()>1){ + if (thumb.make(media_dir+body,w,h,thumbnail_dir+t1[0]+".jpg")){ + status=HTTPResponse::HTTP_OK; + XML.addValue("thumbnail",t1[0]+".jpg"); + } + else { + status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; + logger.error("ERROR: could not create thumbnail for "+media_dir+body); + XML.addValue("error","could not create thumbnail for "+media_dir+body); + } + } + else { + if (thumb.make(media_dir+body,w,h,thumbnail_dir+body+".jpg")){ + status=HTTPResponse::HTTP_OK; + XML.addValue("thumbnail",body+".jpg"); + } + else { + status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; + logger.error("ERROR: could not create thumbnail for "+media_dir+body); + XML.addValue("error","could not create thumbnail for "+media_dir+body); + } + } + } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Body missing"); + XML.addValue("error","Body missing"); + } + } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Invalid command combination"); + XML.addValue("error","Invalid command combination"); + } + } + else if (command[0]=="new") { XML.pushTag("rotor"); if (request.getMethod()=="GET") { string sID=idGen.createOne().toString(); //create() seems to cause problems @@ -59,7 +113,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS XML.addValue("sID",sID); status=HTTPResponse::HTTP_OK; } - if (request.getMethod()=="PUT") { //unofficial manual thread name + else if (request.getMethod()=="PUT") { //unofficial manual thread name if (body.size()) { string sID=body; bool found=false; @@ -78,6 +132,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } } } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Body missing"); + XML.addValue("error","Body missing"); + } } else if (command[0]=="list") { XML.pushTag("rotor"); @@ -98,6 +157,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } status=HTTPResponse::HTTP_OK; } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Invalid command combination"); + XML.addValue("error","Invalid command combination"); + } } else if (command[0]=="listnodes") { if (command.size()>1){ @@ -129,6 +193,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS Node_factory factory; if (factory.list_node(body,XML)) status=HTTPResponse::HTTP_OK; } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Invalid command combination"); + XML.addValue("error","Invalid command combination"); + } } else if (command[0]=="listrenders") { XML.pushTag("rotor"); @@ -168,6 +237,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } status=HTTPResponse::HTTP_OK; } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Invalid command combination"); + XML.addValue("error","Invalid command combination"); + } } else if (command[0]=="exit") { logger.information("exiting"); |
