diff options
Diffstat (limited to 'plugins/webbox/webbox.cpp')
-rw-r--r-- | plugins/webbox/webbox.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/webbox/webbox.cpp b/plugins/webbox/webbox.cpp index 12e62ef..4abb2bf 100644 --- a/plugins/webbox/webbox.cpp +++ b/plugins/webbox/webbox.cpp @@ -576,6 +576,58 @@ protected: } }; +class CopyCommand: public PostCommand +{ +public: + CopyCommand() + { + m_commandName = "copy"; + m_isWriteCommand = true; + } + +protected: + virtual std::string start(CommandParameters& p) + { + std::string result{}; + fs::path targetDir{}; + + readContent(p); + + pt::ptree tree; + std::istringstream ss{m_content}; + pt::read_xml(ss, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); + + try { + auto elements {tree.get_child("request")}; + for (const auto& element: elements) { + if (element.first == "target") { + targetDir = p.m_path / element.second.data(); + } else if (element.first == "file") { + std::string filename{element.second.data()}; + fs::path old_path{p.m_path / filename}; + fs::path new_path{targetDir / filename}; + try { + fs::copy(old_path, new_path, fs::copy_options::overwrite_existing | fs::copy_options::recursive ); + } catch (const std::exception& ex) { + result += "Error copying "s + filename + ": "s + ex.what() + "<br>"s; + } + } else { + result += "Unknown element: "s + element.first + "<br>"s; + } + } + } catch (const std::exception& ex) { + return HttpStatus("500", "Reading file list: "s + ex.what(), p); + } + + if (result.empty()) { + result = "OK"; + } + + p.m_SetResponseHeader("content_type", "text/plain"); + return result; + } +}; + class MoveCommand: public PostCommand { public: @@ -829,6 +881,7 @@ webbox_plugin::webbox_plugin() registerCommand(std::make_shared<InfoCommand>()); registerCommand(std::make_shared<DownloadZipCommand>()); registerCommand(std::make_shared<DeleteCommand>()); + registerCommand(std::make_shared<CopyCommand>()); registerCommand(std::make_shared<MoveCommand>()); registerCommand(std::make_shared<RenameCommand>()); registerCommand(std::make_shared<UploadCommand>()); |