Skip to content

Commit a291117

Browse files
committed
Add socket api call for hydration
1 parent 8629f48 commit a291117

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

src/gui/socketapi/socketapi.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,33 @@ void SocketApi::command_V2_LIST_ACCOUNTS(const QSharedPointer<SocketApiJobV2> &j
662662
out << QJsonObject(
663663
{{QStringLiteral("name"), acc->account()->displayNameWithHost()}, {QStringLiteral("uuid"), acc->account()->uuid().toString(QUuid::WithoutBraces)}});
664664
}
665-
job->success({ { QStringLiteral("accounts"), out } });
665+
job->success({{QStringLiteral("accounts"), out}});
666+
}
667+
668+
void SocketApi::command_V2_HYDRATE_FILE(const QSharedPointer<SocketApiJobV2> &job) const
669+
{
670+
const auto &arguments = job->arguments();
671+
672+
const QString file = arguments[QStringLiteral("file")].toString();
673+
const QByteArray fileId = arguments[QStringLiteral("fileId")].toString().toUtf8();
674+
675+
auto fileData = FileData::get(file);
676+
677+
if (fileData.folder) {
678+
auto watcher = new QFutureWatcher<Result<void, QString>>();
679+
connect(watcher, &QFutureWatcher<Result<void, QString>>::finished, this, [job, watcher] {
680+
const auto resut = watcher->result<Result<void, QString>>();
681+
watcher->deleteLater();
682+
if (!resut) {
683+
job->success({{QStringLiteral("status"), QStringLiteral("ERROR")}, {QStringLiteral("error"), resut.error()}});
684+
} else {
685+
job->success({{QStringLiteral("status"), QStringLiteral("OK")}});
686+
}
687+
});
688+
watcher->setFuture(fileData.folder->vfs().hydrateFile(fileId));
689+
} else {
690+
job->failure(QStringLiteral("cannot hydrate unknown file"));
691+
}
666692
}
667693

668694
void SocketApi::command_V2_GET_CLIENT_ICON(const QSharedPointer<SocketApiJobV2> &job) const

src/gui/socketapi/socketapi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ private Q_SLOTS:
118118
// External sync
119119
Q_INVOKABLE void command_V2_LIST_ACCOUNTS(const QSharedPointer<SocketApiJobV2> &job) const;
120120

121+
Q_INVOKABLE void command_V2_HYDRATE_FILE(const QSharedPointer<SocketApiJobV2> &job) const;
122+
121123
// Sends the id and the client icon as PNG image (base64 encoded) in Json key "png"
122124
// e.g. { "id" : "1", "arguments" : { "png" : "hswehs343dj8..." } } or an error message in key "error"
123125
//

src/libsync/vfs/vfs.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ void Vfs::wipeDehydratedVirtualFiles()
144144
// But hydrated placeholders may still be around.
145145
}
146146

147+
QFuture<Result<void, QString>> Vfs::hydrateFile(const QByteArray &fileId)
148+
{
149+
// nothing to do
150+
return QtFuture::makeReadyValueFuture(Result<void, QString>{});
151+
}
152+
147153
Q_LOGGING_CATEGORY(lcPlugin, "sync.plugins", QtInfoMsg)
148154

149155
OCC::VfsPluginManager *OCC::VfsPluginManager::_instance = nullptr;

src/libsync/vfs/vfs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <QUrl>
2828
#include <QVersionNumber>
2929

30+
#include <QFuture>
3031
#include <filesystem>
3132
#include <memory>
3233

@@ -202,6 +203,15 @@ class OPENCLOUD_SYNC_EXPORT Vfs : public QObject
202203
*/
203204
void wipeDehydratedVirtualFiles();
204205

206+
207+
/** Start a hydration (download of remote contents) of a file.
208+
*
209+
* The fileId is the SyncFileItem::id() value of the file to hydrate.
210+
*
211+
* Returns a QFuture<Result> void if successful and QFuture<Result> QString if an error occurs.
212+
*/
213+
[[nodiscard]] virtual QFuture<Result<void, QString>> hydrateFile(const QByteArray &fileId);
214+
205215
public Q_SLOTS:
206216
/** Update in-sync state based on SyncFileStatusTracker signal.
207217
*

0 commit comments

Comments
 (0)