[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/LOOLWSD.cpp
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Aug 15 12:16:36 UTC 2018
wsd/ClientSession.cpp | 43 --------------------------------
wsd/ClientSession.hpp | 12 --------
wsd/LOOLWSD.cpp | 67 +++++---------------------------------------------
3 files changed, 9 insertions(+), 113 deletions(-)
New commits:
commit 4dd62d4dd2d2b467a70c5735b91d691522769834
Author: Tor Lillqvist <tml at collabora.com>
AuthorDate: Thu Jul 12 15:50:04 2018 +0300
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Aug 15 15:01:03 2018 +0300
Revert "Add a cache of "thumbnails" (PNG images) generated using the convert-to API"
No need to keep such a cache here. The consumer of previews
(thumbnails) in question does it itself (Nextcloud).
This reverts commit 405b66c8db71c314c2d26c4b18e9d74806c76bf1
Change-Id: Iad16212ccbc875fe4f6d041e2fceef7eaea1d1bb
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index b11331dc8..90e099d38 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -14,7 +14,6 @@
#include <fstream>
#include <sstream>
-#include <Poco/File.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/StreamCopier.h>
#include <Poco/StringTokenizer.h>
@@ -38,14 +37,10 @@ using Poco::StringTokenizer;
ClientSession::ClientSession(const std::string& id,
const std::shared_ptr<DocumentBroker>& docBroker,
const Poco::URI& uriPublic,
- const bool readOnly,
- const bool creatingPngThumbnail,
- const std::string& thumbnailFile) :
+ const bool readOnly) :
Session("ToClient-" + id, id, readOnly),
_docBroker(docBroker),
_uriPublic(uriPublic),
- _creatingPngThumbnail(creatingPngThumbnail),
- _thumbnailFile(thumbnailFile),
_isDocumentOwner(false),
_isAttached(false),
_isViewLoaded(false),
@@ -60,7 +55,6 @@ ClientSession::ClientSession(const std::string& id,
_tilesOnFly(0),
_tilesBeingRendered(0)
{
- assert(!creatingPngThumbnail || thumbnailFile != "");
const size_t curConnections = ++LOOLWSD::NumConnections;
LOG_INF("ClientSession ctor [" << getName() << "], current number of connections: " << curConnections);
}
@@ -840,41 +834,6 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
response.set("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
HttpHelper::sendFile(_saveAsSocket, encodedFilePath, mimeType, response);
-
- if (_creatingPngThumbnail)
- {
- // Save the created PNG "thumbnail" under a name constructed from the SHA1 of
- // the document contents.
-
- // FIXME: We could first try to simply hardlink the result as the thumbnail.
-
- Poco::File(Poco::Path(_thumbnailFile).parent()).createDirectories();
- std::ofstream thumbnail(_thumbnailFile, std::ios::binary);
-
- if (thumbnail.is_open() && thumbnail.good())
- {
- std::ifstream result(resultURL.getPath(), std::ios::binary);
- if (result.is_open() && result.good())
- {
- Poco::StreamCopier::copyStream(result, thumbnail);
- if (!result.bad() && thumbnail.good())
- {
- LOG_TRC("Created cached thumbnail " << _thumbnailFile);
- }
- else
- {
- thumbnail.close();
- unlink(_thumbnailFile.c_str());
- }
- }
- }
- else
- {
- if (thumbnail.is_open())
- thumbnail.close();
- unlink(_thumbnailFile.c_str());
- }
- }
}
// Conversion is done, cleanup this fake session.
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index ae8a6937d..997058f68 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -32,9 +32,7 @@ public:
ClientSession(const std::string& id,
const std::shared_ptr<DocumentBroker>& docBroker,
const Poco::URI& uriPublic,
- const bool isReadOnly = false,
- const bool creatingPngThumbnail = false,
- const std::string& thumbnailFile = "");
+ const bool isReadOnly = false);
virtual ~ClientSession();
@@ -199,14 +197,6 @@ private:
/// URI with which client made request to us
const Poco::URI _uriPublic;
- /// True iff this is a convert-to operation creating a PNG. We assume all such PNGs will be
- /// usable as "thumbnails" for the document.
- const bool _creatingPngThumbnail;
-
- /// The pathname of the thumbnail file being created. Valid only if _creatingPngThumbnail is
- /// true.
- const std::string _thumbnailFile;
-
/// Whether this session is the owner of currently opened document
bool _isDocumentOwner;
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index ae32cfb18..502f6d7c3 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -49,15 +49,14 @@
#include <sstream>
#include <thread>
-#include <Poco/DateTimeFormatter.h>
-#include <Poco/DigestStream.h>
-#include <Poco/DirectoryIterator.h>
#include <Poco/DOM/AutoPtr.h>
#include <Poco/DOM/DOMParser.h>
#include <Poco/DOM/DOMWriter.h>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/Element.h>
#include <Poco/DOM/NodeList.h>
+#include <Poco/DateTimeFormatter.h>
+#include <Poco/DirectoryIterator.h>
#include <Poco/Environment.h>
#include <Poco/Exception.h>
#include <Poco/File.h>
@@ -77,7 +76,6 @@
#include <Poco/Pipe.h>
#include <Poco/Process.h>
#include <Poco/SAX/InputSource.h>
-#include <Poco/SHA1Engine.h>
#include <Poco/StreamCopier.h>
#include <Poco/StringTokenizer.h>
#include <Poco/TemporaryFile.h>
@@ -1524,9 +1522,7 @@ static std::shared_ptr<ClientSession> createNewClientSession(const WebSocketHand
const std::string& id,
const Poco::URI& uriPublic,
const std::shared_ptr<DocumentBroker>& docBroker,
- const bool isReadOnly,
- const bool creatingPngThumbnail,
- const std::string& thumbnailFile)
+ const bool isReadOnly)
{
LOG_CHECK_RET(docBroker && "Null docBroker instance", nullptr);
try
@@ -1542,7 +1538,7 @@ static std::shared_ptr<ClientSession> createNewClientSession(const WebSocketHand
// In case of WOPI, if this session is not set as readonly, it might be set so
// later after making a call to WOPI host which tells us the permission on files
// (UserCanWrite param).
- return std::make_shared<ClientSession>(id, docBroker, uriPublic, isReadOnly, creatingPngThumbnail, thumbnailFile);
+ return std::make_shared<ClientSession>(id, docBroker, uriPublic, isReadOnly);
}
catch (const std::exception& exc)
{
@@ -2058,55 +2054,7 @@ private:
bool sent = false;
if (!fromPath.empty() && !format.empty())
{
- LOG_INF("Conversion request for file [" << fromPath << "].");
-
- std::string thumbnailFile;
- if (format == "png")
- {
- // Check whether we already have a cached "thumbnail" for this document.
-
- // NOTE: We do *not* want to simply extract the embedded
- // Thumbnails/thumbnail.png from an ODF document, as that is typically too small
- // for many purposes (side is max 256 pixels in documents generated by
- // LibreOffice or its predecessor), and there is no way to pass in a requested
- // minimum pixel size of the result so we can't know whether the actual size of
- // the embedded thumbail is big enough.
-
- std::ifstream istr(fromPath, std::ios::binary);
- if (istr.is_open() && istr.good())
- {
- Poco::SHA1Engine sha1;
- Poco::DigestOutputStream dos(sha1);
- Poco::StreamCopier::copyStream(istr, dos);
- if (!istr.bad())
- {
- istr.close();
- dos.close();
- std::string digest = Poco::DigestEngine::digestToHex(sha1.digest());
- thumbnailFile = LOOLWSD::Cache + "/thumbnails/" + digest.substr(0, 2) + "/"
- + digest.substr(2, 2) + "/" + digest.substr(4) + ".png";
-
- istr.open(thumbnailFile, std::ios::binary);
- if (istr.is_open() && istr.good())
- {
- std::string png;
- Poco::StreamCopier::copyToString(istr, png);
- if (!istr.bad())
- {
- LOG_TRC("Found cached thumbnail " << thumbnailFile);
-
- response.set("Content-Disposition", "attachment; filename=\"" + digest + ".png\"");
- response.setContentType("image/png");
- response.setContentLength(png.size());
- socket->send(response);
- socket->send(png.data(), png.size(), true);
-
- return;
- }
- }
- }
- }
- }
+ LOG_INF("Conversion request for URI [" << fromPath << "].");
Poco::URI uriPublic = DocumentBroker::sanitizeURI(fromPath);
const std::string docKey = DocumentBroker::getDocKey(uriPublic);
@@ -2127,8 +2075,7 @@ private:
// Load the document.
// TODO: Move to DocumentBroker.
const bool isReadOnly = true;
- std::shared_ptr<ClientSession> clientSession = createNewClientSession(nullptr, _id, uriPublic, docBroker,
- isReadOnly, format == "png", thumbnailFile);
+ std::shared_ptr<ClientSession> clientSession = createNewClientSession(nullptr, _id, uriPublic, docBroker, isReadOnly);
if (clientSession)
{
disposition.setMove([docBroker, clientSession, format]
@@ -2367,7 +2314,7 @@ private:
std::shared_ptr<DocumentBroker> docBroker = findOrCreateDocBroker(ws, url, docKey, _id, uriPublic);
if (docBroker)
{
- std::shared_ptr<ClientSession> clientSession = createNewClientSession(&ws, _id, uriPublic, docBroker, isReadOnly, false, "");
+ std::shared_ptr<ClientSession> clientSession = createNewClientSession(&ws, _id, uriPublic, docBroker, isReadOnly);
if (clientSession)
{
// Transfer the client socket to the DocumentBroker when we get back to the poll:
More information about the Libreoffice-commits
mailing list