Use verification job within edit locally job

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-05-24 00:17:09 +08:00
parent 1422df733a
commit a5713fc233
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 4 additions and 41 deletions

View file

@ -18,7 +18,7 @@
#include <QDesktopServices>
#include <QtConcurrent>
#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()

View file

@ -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);