1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-05-03 21:12:43 +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
delegate: UserGridDelegate {
name: model.name
image: model.primaryImageTag ? "%1/Users/%2/Images/Primary?tag=%3".arg(ApiClient.baseUrl).arg(model.id).arg(model.primaryImageTag) : null
highlighted: model.name == username.text
image: model.primaryImageTag ? "%1/Users/%2/Images/Primary?tag=%3".arg(ApiClient.baseUrl).arg(model.id).arg(model.primaryImageTag) : ""
highlighted: model.name === username.text
onClicked: {
username.text = model.name
password.focus = true

View file

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