diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index 9af8e83de..e2d7f5639 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -18,7 +18,7 @@ #include #include -#include "editlocallymanager.h" +#include "editlocallyverificationjob.h" #include "folder.h" #include "folderman.h" #include "syncengine.h" @@ -84,45 +84,9 @@ void EditLocallyJob::startSetup() void EditLocallyJob::startTokenRemoteCheck() { - if (!_accountState || _relPath.isEmpty() || _token.isEmpty()) { - qCWarning(lcEditLocallyJob) << "Could not start token check." - << "accountState:" << _accountState - << "relPath:" << _relPath - << "token:" << _token; - - showError(tr("Could not start editing locally."), - tr("An error occurred trying to verify the request to edit locally.")); - return; - } - - const auto encodedToken = QString::fromUtf8(QUrl::toPercentEncoding(_token)); // Sanitise the token - const auto encodedRelPath = QUrl::toPercentEncoding(_relPath); // Sanitise the relPath - - const auto checkTokenJob = new SimpleApiJob(_accountState->account(), - QStringLiteral("/ocs/v2.php/apps/files/api/v1/openlocaleditor/%1").arg(encodedToken)); - - QUrlQuery params; - params.addQueryItem(QStringLiteral("path"), prefixSlashToPath(encodedRelPath)); - checkTokenJob->addQueryParams(params); - checkTokenJob->setVerb(SimpleApiJob::Verb::Post); - connect(checkTokenJob, &SimpleApiJob::resultReceived, this, &EditLocallyJob::remoteTokenCheckResultReceived); - - checkTokenJob->start(); -} - -void EditLocallyJob::remoteTokenCheckResultReceived(const int statusCode) -{ - qCInfo(lcEditLocallyJob) << "token check result" << statusCode; - - constexpr auto HTTP_OK_CODE = 200; - _tokenVerified = statusCode == HTTP_OK_CODE; - - if (!_tokenVerified) { - showError(tr("Could not validate the request to open a file from server."), tr("Please try again.")); - return; - } - - findAfolderAndConstructPaths(); + const auto verificationJob = new EditLocallyVerificationJob(_accountState, _relPath, _token); + connect(verificationJob, &EditLocallyVerificationJob::error, this, &EditLocallyJob::showError); + connect(verificationJob, &EditLocallyVerificationJob::finished, this, &EditLocallyJob::findAfolderAndConstructPaths); } void EditLocallyJob::proceedWithSetup() diff --git a/src/gui/editlocallyjob.h b/src/gui/editlocallyjob.h index e778cf4a8..84bb11123 100644 --- a/src/gui/editlocallyjob.h +++ b/src/gui/editlocallyjob.h @@ -63,7 +63,6 @@ private slots: void showErrorNotification(const QString &message, const QString &informativeText) const; void showErrorMessageBox(const QString &message, const QString &informativeText) const; - void remoteTokenCheckResultReceived(const int statusCode); void slotItemDiscovered(const OCC::SyncFileItemPtr &item); void slotItemCompleted(const OCC::SyncFileItemPtr &item);