[Libreoffice-commits] online.git: 2 commits - loolwsd/LOOLWSD.cpp
Miklos Vajna
vmiklos at collabora.co.uk
Tue Oct 20 06:42:04 PDT 2015
loolwsd/LOOLWSD.cpp | 39 +++++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 8 deletions(-)
New commits:
commit 8f90c38844ba6840acd97c6a72eb104d1171dc8d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Oct 20 15:41:42 2015 +0200
loolwsd convert-to: implement actual conversion
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index c945251..c241e08 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -252,7 +252,27 @@ public:
if (!fromPath.empty() && !format.empty())
{
- // TODO implement actual conversion
+ // Load the document.
+ std::shared_ptr<WebSocket> ws;
+ LOOLSession::Kind kind = LOOLSession::Kind::ToClient;
+ std::shared_ptr<MasterProcessSession> session(new MasterProcessSession(ws, kind));
+ const std::string filePrefix("file://");
+ std::string load = "load url=" + filePrefix + fromPath;
+ session->handleInput(load.data(), load.size());
+
+ // Convert it to the requested format.
+ Path toPath(fromPath);
+ toPath.setExtension(format);
+ std::string toJailURL = filePrefix + LOOLSession::jailDocumentURL + Path::separator() + toPath.getFileName();
+ std::string saveas = "saveas url=" + toJailURL + " format=" + format + " options=";
+ session->handleInput(saveas.data(), saveas.size());
+ std::string toURL = session->getSaveAs();
+
+ // Send it back to the client.
+ std::string mimeType = "application/octet-stream";
+ if (toURL.find(filePrefix) == 0)
+ toURL = toURL.substr(filePrefix.length());
+ response.sendFile(toURL, mimeType);
}
else
{
commit 355362f5198da3b51539b77d5d9a03fd451f3cbe
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Oct 20 15:35:43 2015 +0200
loolwsd convert-to: clean up temp directory in case format would be empty
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 21256be..c945251 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -253,15 +253,18 @@ public:
if (!fromPath.empty() && !format.empty())
{
// TODO implement actual conversion
-
- Path tempDirectory(fromPath);
- tempDirectory.setFileName("");
- File(tempDirectory).remove(/*recursive=*/true);
+ }
+ else
+ {
+ response.setStatus(HTTPResponse::HTTP_BAD_REQUEST);
+ response.setContentLength(0);
+ response.send();
}
- response.setStatus(HTTPResponse::HTTP_OK);
- response.setContentLength(0);
- response.send();
+ // Clean up the temporary directory the HTMLForm ctor created.
+ Path tempDirectory(fromPath);
+ tempDirectory.setFileName("");
+ File(tempDirectory).remove(/*recursive=*/true);
}
else if (tokens.count() >= 4)
{
More information about the Libreoffice-commits
mailing list