Skip to content

Commit

Permalink
fix authorized websockets, fix download button in manga number
Browse files Browse the repository at this point in the history
  • Loading branch information
mgn-norm committed Oct 11, 2022
1 parent 7e615c9 commit e7eb88e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/models/DownloadsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ void DownloadsModel::setupWebsocket()

connect(&_webSocket, &QWebSocket::connected, this, &DownloadsModel::onConnected);
connect(&_webSocket, &QWebSocket::disconnected, this, &DownloadsModel::closed);
connect(&_webSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error),
[=](QAbstractSocket::SocketError error){
qDebug() << "error: " << error << _webSocket.errorString();
});
auto resolved = _networkManager->resolvedPath().arg("/api/v1/downloads");
bool ssl = resolved.startsWith("https", Qt::CaseInsensitive);
resolved = resolved.mid(resolved.indexOf('/', resolved.indexOf(':'))+2);
resolved = QStringLiteral("%1://%2")
.arg(ssl ? "wss" : "ws")
.arg(resolved);

_webSocket.open(QUrl(resolved));
QNetworkRequest request;
request.setUrl(resolved);
request.setRawHeader("Authorization", QString("Basic %1").arg(QByteArray(QString("%1:%2").arg(_networkManager->username()).arg(_networkManager->password()).toUtf8()).toBase64()).toUtf8());

_webSocket.open(request);
}

/******************************************************************************
Expand Down
10 changes: 9 additions & 1 deletion src/models/UpdatesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ void UpdatesModel::componentComplete()
{
connect(&_webSocket, &QWebSocket::connected, this, &UpdatesModel::onConnected);
connect(&_webSocket, &QWebSocket::disconnected, this, &UpdatesModel::closed);
connect(&_webSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error),
[=](QAbstractSocket::SocketError error){
qDebug() << "error: " << error << _webSocket.errorString();
});
connect(
_networkManager,
&NetworkManager::receiveUpdates,
Expand All @@ -97,7 +101,11 @@ void UpdatesModel::componentComplete()
.arg(ssl ? "wss" : "ws")
.arg(resolved);

_webSocket.open(QUrl(resolved));
QNetworkRequest request;
request.setUrl(resolved);
request.setRawHeader("Authorization", QString("Basic %1").arg(QByteArray(QString("%1:%2").arg(_networkManager->username()).arg(_networkManager->password()).toUtf8()).toBase64()).toUtf8());

_webSocket.open(request);

next();
}
Expand Down
8 changes: 8 additions & 0 deletions src/networkmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ private slots:

QNetworkAccessManager *create(QObject *parent) override;

const auto& username() const {
return _username;
}

const auto& password() const {
return _password;
}

void get(const QString &endpoint);
void get(
const QString &endpoint,
Expand Down
2 changes: 1 addition & 1 deletion src/qml/MangaDetails.qml
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: {
chaptersModel.downloadChapter(ChaptersModel.DownloadCustom, chapterNumber)
chaptersModel.downloadChapter(ChaptersModel.DownloadCustom, chapterIndex)
}
}
}
Expand Down

0 comments on commit e7eb88e

Please sign in to comment.