• R/O
  • SSH
  • HTTPS

switch: Commit


Commit MetaInfo

Revision914 (tree)
Time2013-07-06 21:41:03
Authorloopsketch

Log Message

add pause webAPI

Change Summary

Incremental Difference

--- switch/trunk/src/svvitch/WebAPI.cpp (revision 913)
+++ switch/trunk/src/svvitch/WebAPI.cpp (revision 914)
@@ -47,7 +47,7 @@
4747 string encoded;
4848 Poco::URI::encode(request().getURI(), "/", encoded);
4949 Poco::URI uri(encoded);
50- //_log.information(Poco::format("webAPI access uri [%s]", uri.getPath()));
50+ _log.information(Poco::format("webAPI access uri [%s]", uri.getPath()));
5151 //vector<string> params;
5252 //svvitch::split(uri.getPath().substr(1), '?', params, 2);
5353 vector<string> urls;
@@ -172,6 +172,14 @@
172172 sendJSONP(form().get("callback", ""), params);
173173 return;
174174
175+ } else if (command == "pause") {
176+ string pause = form().get("v");
177+ scene->setPause(pause == "true");
178+ map<string, string> params;
179+ params["pause"] = pause;
180+ sendJSONP(form().get("callback", ""), params);
181+ return;
182+
175183 } else if (command == "action") {
176184 string action = form().get("v");
177185 scene->setAction(action);
@@ -338,11 +346,11 @@
338346
339347 void SwitchRequestHandler::files() {
340348 string path = form().get("path", "");
349+ if (path.at(0) == '/' || path.at(0) == '\\') path = path.substr(1);
341350 //_log.information(Poco::format("files: %s", path));
342- if (path.at(0) == '/' || path.at(0) == '\\') path = path.substr(1);
343- Path dir(config().dataRoot, Path(path).toString());
344- //Path dir = config().dataRoot;
345351 try {
352+ Path dir(config().dataRoot, Path(path).toString());
353+ //Path dir = config().dataRoot;
346354 //if (!path.empty()) dir = dir.append(path);
347355 map<string, string> result;
348356 result["count"] = Poco::format("%d", svvitch::fileCount(dir));
@@ -359,40 +367,48 @@
359367 }
360368
361369 string SwitchRequestHandler::fileToJSON(const Path path) {
362- string name = path.getFileName();
363- if (name.length() > 1 && (name.at(0) == '.' || name.at(0) == '$')) return "";
370+ try {
371+ string name = path.getFileName();
372+ if (name.length() > 1 && (name.at(0) == '.' || name.at(0) == '$')) return "";
364373
365- if (path.isDirectory()) {
366- vector<string> files;
367- vector<File> list;
368- File(path).list(list);
369- for (vector<File>::iterator it = list.begin(); it != list.end(); it++) {
370-// string json = fileToJSON(*it);
371-// files.push_back(json);
372- File f = *it;
373- string subName = Path(f.path()).getFileName();
374- if (subName.length() > 1 && subName.at(0) != '.' && subName.at(0) != '$') {
375- if (f.isDirectory()) {
376- files.push_back(subName + "/");
377- } else {
378- files.push_back(subName);
374+ if (path.isDirectory()) {
375+ vector<string> files;
376+ vector<File> list;
377+ File(path).list(list);
378+ for (vector<File>::iterator it = list.begin(); it != list.end(); it++) {
379+ // string json = fileToJSON(*it);
380+ // files.push_back(json);
381+ File f = *it;
382+ string subName = Path(f.path()).getFileName();
383+ if (subName.length() > 1 && subName.at(0) != '.' && subName.at(0) != '$') {
384+ if (f.isDirectory()) {
385+ files.push_back(subName + "/");
386+ } else {
387+ files.push_back(subName);
388+ }
379389 }
380390 }
391+ return svvitch::formatJSONArray(files);
381392 }
382- return svvitch::formatJSONArray(files);
393+ map<string, string> params;
394+ params["name"] = svvitch::formatJSON(name);
395+ File f(path);
396+ Poco::DateTime modified(f.getLastModified());
397+ modified.makeLocal(Poco::Timezone::tzd());
398+ params["modified"] = "\"" + Poco::DateTimeFormatter::format(modified, Poco::DateTimeFormat::SORTABLE_FORMAT) + "\"";
399+ params["size"] = Poco::format("%Lu", f.getSize());
400+ //if (f.getSize() < 10485760) {
401+ // // 10MB以下ならmd5を計算
402+ // params["md5"] = "\"" + svvitch::md5(path) + "\"";
403+ //}
404+ return svvitch::formatJSON(params);
405+ } catch (Poco::FileException& ex) {
406+ _log.warning(ex.displayText());
407+ sendResponse(HTTPResponse::HTTP_NOT_FOUND, ex.displayText());
408+ } catch (Poco::PathSyntaxException& ex) {
409+ _log.warning(ex.displayText());
410+ sendResponse(HTTPResponse::HTTP_NOT_FOUND, ex.displayText());
383411 }
384- map<string, string> params;
385- params["name"] = svvitch::formatJSON(name);
386- File f(path);
387- Poco::DateTime modified(f.getLastModified());
388- modified.makeLocal(Poco::Timezone::tzd());
389- params["modified"] = "\"" + Poco::DateTimeFormatter::format(modified, Poco::DateTimeFormat::SORTABLE_FORMAT) + "\"";
390- params["size"] = Poco::format("%Lu", f.getSize());
391- //if (f.getSize() < 10485760) {
392- // // 10MB以下ならmd5を計算
393- // params["md5"] = "\"" + svvitch::md5(path) + "\"";
394- //}
395- return svvitch::formatJSON(params);
396412 }
397413
398414 void SwitchRequestHandler::download() {
Show on old repository browser