1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-05-18 03:52:42 +00:00

(Hopefully) fixed #1

[Setup] Fixed: Sailfin would get into an infinite loop while trying to resolve certain urls.
This commit is contained in:
Chris Josten 2020-09-28 14:23:10 +02:00
parent d6f0881e5e
commit 7bb1fdddba
2 changed files with 14 additions and 20 deletions

View file

@ -97,8 +97,8 @@ Dialog {
model: userModel model: userModel
delegate: UserGridDelegate { delegate: UserGridDelegate {
name: model.name name: model.name
image: model.primaryImageTag ? "%1/Users/%2/Images/Primary?tag=%3".arg(ApiClient.baseUrl).arg(model.id).arg(model.primaryImageTag) : null image: model.primaryImageTag ? "%1/Users/%2/Images/Primary?tag=%3".arg(ApiClient.baseUrl).arg(model.id).arg(model.primaryImageTag) : ""
highlighted: model.name == username.text highlighted: model.name === username.text
onClicked: { onClicked: {
username.text = model.name username.text = model.name
password.focus = true password.focus = true

View file

@ -126,31 +126,25 @@ void ApiClient::setupConnection() {
// First detect redirects: // First detect redirects:
// Note that this is done without calling JellyfinApiClient::get since that automatically includes the base_url, // Note that this is done without calling JellyfinApiClient::get since that automatically includes the base_url,
// which is something we want to avoid here. // which is something we want to avoid here.
QNetworkReply *rep = m_naManager.get(QNetworkRequest(m_baseUrl)); QNetworkRequest req = QNetworkRequest(m_baseUrl);
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *rep = m_naManager.get(req);
connect(rep, &QNetworkReply::finished, this, [rep, this](){ connect(rep, &QNetworkReply::finished, this, [rep, this](){
int status = statusCode(rep); int status = statusCode(rep);
qDebug() << status; qDebug() << status;
// Check if redirect QString newUrl = rep->url().toString();
if (status >= 300 && status < 400) { // If the server wants to redirect us to their web interface, we have to chop the last part of the url off.
QString location = QString::fromUtf8(rep->rawHeader("location")); if (newUrl.endsWith("/web/index.html")) {
qInfo() << "Redirect from " << this->m_baseUrl << " to " << location; newUrl.chop(QString("/web/index.html").size());
QUrl base = QUrl(m_baseUrl); this->setBaseUrl(newUrl);
QString newUrl = base.resolved(QUrl(location)).toString();
// If the url wants to redirect us to their web interface, we have to chop the last part of.
if (newUrl.endsWith("/web/index.html")) {
newUrl.chop(QString("/web/index.html").size());
this->setBaseUrl(newUrl);
getBrandingConfiguration();
} else {
this->setBaseUrl(newUrl);
setupConnection();
}
} else {
getBrandingConfiguration();
} }
this->getBrandingConfiguration();
rep->deleteLater(); rep->deleteLater();
}); });
connect(rep, &QNetworkReply::redirected, this, [req] (const QUrl &url) {
qDebug() << "Redirect from " << req.url() << " to " << url;
});
setDefaultErrorHandler(rep); setDefaultErrorHandler(rep);
} }