1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-21 20:27:45 +00:00

Meh, throw out XIVAPI and fetch avatars from the Lodestone directly

XIVAPI was kind of unnecessary here, and on top of that it's barely
working nowadays. We can grab the image URL directly from the Lodestone,
cutting out the middleman.
This commit is contained in:
Joshua Goins 2024-06-29 20:46:08 -04:00
parent b04a4af954
commit a30b26fa3a
6 changed files with 47 additions and 44 deletions

View file

@ -40,8 +40,8 @@ SPDX-License-Identifier: CC0-1.0
<entry name="SquareEnixLoginServer" type="String">
<default>square-enix.com</default>
</entry>
<entry name="XivApiServer" type="String">
<default>xivapi.com</default>
<entry name="MainServer" type="String">
<default>finalfantasyxiv.com</default>
</entry>
<entry name="PreferredProtocol" type="String">
<default>https</default>

View file

@ -22,7 +22,7 @@ class LauncherSettings : public QObject
Q_PROPERTY(QString dalamudDistribServer READ dalamudDistribServer WRITE setDalamudDistribServer NOTIFY dalamudDistribServerChanged)
Q_PROPERTY(QString squareEnixServer READ squareEnixServer WRITE setSquareEnixServer NOTIFY squareEnixServerChanged)
Q_PROPERTY(QString squareEnixLoginServer READ squareEnixLoginServer WRITE setSquareEnixLoginServer NOTIFY squareEnixLoginServerChanged)
Q_PROPERTY(QString xivApiServer READ xivApiServer WRITE setXivApiServer NOTIFY xivApiServerChanged)
Q_PROPERTY(QString mainServer READ mainServer WRITE setMainServer NOTIFY mainServerChanged)
Q_PROPERTY(QString preferredProtocol READ preferredProtocol WRITE setPreferredProtocol NOTIFY preferredProtocolChanged)
Q_PROPERTY(QString screenshotDir READ screenshotDir WRITE setScreenshotDir NOTIFY screenshotDirChanged)
Q_PROPERTY(bool argumentsEncrypted READ argumentsEncrypted WRITE setArgumentsEncrypted NOTIFY encryptedArgumentsChanged)
@ -52,8 +52,8 @@ public:
[[nodiscard]] QString squareEnixLoginServer() const;
void setSquareEnixLoginServer(const QString &value);
[[nodiscard]] QString xivApiServer() const;
void setXivApiServer(const QString &value);
[[nodiscard]] QString mainServer() const;
void setMainServer(const QString &value);
[[nodiscard]] QString preferredProtocol() const;
void setPreferredProtocol(const QString &value);
@ -80,7 +80,7 @@ Q_SIGNALS:
void dalamudDistribServerChanged();
void squareEnixServerChanged();
void squareEnixLoginServerChanged();
void xivApiServerChanged();
void mainServerChanged();
void preferredProtocolChanged();
void screenshotDirChanged();
void encryptedArgumentsChanged();

View file

@ -239,27 +239,29 @@ void Account::fetchAvatar()
const QString filename = QStringLiteral("%1/%2.jpg").arg(cacheLocation, lodestoneId());
if (!QFile(filename).exists()) {
qDebug(ASTRA_LOG) << "Did not find lodestone character " << lodestoneId() << " in cache, fetching from xivapi.";
qDebug(ASTRA_LOG) << "Did not find lodestone character " << lodestoneId() << " in cache, fetching from Lodestone.";
QUrl url;
url.setScheme(m_launcher.settings()->preferredProtocol());
url.setHost(m_launcher.settings()->xivApiServer());
url.setPath(QStringLiteral("/character/%1").arg(lodestoneId()));
url.setHost(QStringLiteral("na.%1").arg(m_launcher.settings()->mainServer())); // TODO: NA isnt the only thing in the world...
url.setPath(QStringLiteral("/lodestone/character/%1").arg(lodestoneId()));
QNetworkRequest request(url);
Utility::printRequest(QStringLiteral("GET"), request);
const auto reply = m_launcher.mgr()->get(request);
connect(reply, &QNetworkReply::finished, [this, filename, reply] {
auto document = QJsonDocument::fromJson(reply->readAll());
if (document.isObject()) {
const QNetworkRequest avatarRequest(QUrl(document.object()["Character"_L1].toObject()["Avatar"_L1].toString()));
Utility::printRequest(QStringLiteral("GET"), avatarRequest);
QString document = QString::fromUtf8(reply->readAll());
if (!document.isEmpty()) {
const static QRegularExpression re(
QStringLiteral(R"lit(<div\s[^>]*class=["|']frame__chara__face["|'][^>]*>\s*<img\s[&>]*src=["|']([^"']*))lit"));
const QRegularExpressionMatch match = re.match(document);
if (avatarRequest.url().isEmpty()) {
return;
}
if (match.hasCaptured(1)) {
const QString newAvatarUrl = match.captured(1);
const QNetworkRequest avatarRequest = QNetworkRequest(QUrl(newAvatarUrl));
Utility::printRequest(QStringLiteral("GET"), avatarRequest);
auto avatarReply = m_launcher.mgr()->get(avatarRequest);
connect(avatarReply, &QNetworkReply::finished, [this, filename, avatarReply] {
@ -272,6 +274,7 @@ void Account::fetchAvatar()
Q_EMIT avatarUrlChanged();
});
}
}
});
} else {
m_avatarUrl = QStringLiteral("file:///%1").arg(filename);

View file

@ -107,17 +107,17 @@ void LauncherSettings::setSquareEnixLoginServer(const QString &value)
}
}
QString LauncherSettings::xivApiServer() const
QString LauncherSettings::mainServer() const
{
return m_config->xivApiServer();
return m_config->mainServer();
}
void LauncherSettings::setXivApiServer(const QString &value)
void LauncherSettings::setMainServer(const QString &value)
{
if (value != m_config->xivApiServer()) {
m_config->setXivApiServer(value);
if (value != m_config->mainServer()) {
m_config->setMainServer(value);
m_config->save();
Q_EMIT xivApiServerChanged();
Q_EMIT mainServerChanged();
}
}

View file

@ -237,7 +237,7 @@ QCoro::Task<std::optional<SquareEnixLogin::StoredInfo>> SquareEnixLogin::getStor
// fetches Steam username
if (m_info->profile->account()->license() == Account::GameLicense::WindowsSteam) {
const QRegularExpression re(QStringLiteral(R"lit(<input name=""sqexid"" type=""hidden"" value=""(?<sqexid>.*)""\/>)lit"));
const static QRegularExpression re(QStringLiteral(R"lit(<input name=""sqexid"" type=""hidden"" value=""(?<sqexid>.*)""\/>)lit"));
const QRegularExpressionMatch match = re.match(str);
if (match.hasMatch()) {
@ -249,7 +249,7 @@ QCoro::Task<std::optional<SquareEnixLogin::StoredInfo>> SquareEnixLogin::getStor
m_username = m_info->username;
}
const QRegularExpression re(QStringLiteral(R"lit(\t<\s*input .* name="_STORED_" value="(?<stored>.*)">)lit"));
const static QRegularExpression re(QStringLiteral(R"lit(\t<\s*input .* name="_STORED_" value="(?<stored>.*)">)lit"));
const QRegularExpressionMatch match = re.match(str);
if (match.hasMatch()) {
co_return StoredInfo{match.captured(1), url};
@ -296,7 +296,7 @@ QCoro::Task<bool> SquareEnixLogin::loginOAuth()
const QString str = QString::fromUtf8(reply->readAll());
const QRegularExpression re(QStringLiteral(R"lit(window.external.user\("login=auth,ok,(?<launchParams>.*)\);)lit"));
const static QRegularExpression re(QStringLiteral(R"lit(window.external.user\("login=auth,ok,(?<launchParams>.*)\);)lit"));
const QRegularExpressionMatch match = re.match(str);
if (match.hasMatch()) {
const auto parts = match.captured(1).split(','_L1);
@ -320,7 +320,7 @@ QCoro::Task<bool> SquareEnixLogin::loginOAuth()
co_return true;
} else {
const QRegularExpression errorRe(QStringLiteral(R"lit(window.external.user\("login=auth,ng,err,(?<launchParams>.*)\);)lit"));
const static QRegularExpression errorRe(QStringLiteral(R"lit(window.external.user\("login=auth,ng,err,(?<launchParams>.*)\);)lit"));
const QRegularExpressionMatch errorMatch = errorRe.match(str);
if (errorMatch.hasCaptured(1)) {

View file

@ -114,7 +114,7 @@ FormCard.FormCardPage {
FormCard.FormTextFieldDelegate {
id: mainServerDelegate
label: i18n("SE Main Server")
label: i18n("SE Main Server (ffxiv.com)")
text: LauncherCore.settings.squareEnixServer
onTextChanged: LauncherCore.settings.squareEnixServer = text
}
@ -127,22 +127,22 @@ FormCard.FormCardPage {
FormCard.FormTextFieldDelegate {
id: loginServerDelegate
label: i18n("SE Login Server")
label: i18n("SE Login Server (square-enix.com)")
text: LauncherCore.settings.squareEnixLoginServer
onTextChanged: LauncherCore.settings.squareEnixLoginServer = text
}
FormCard.FormDelegateSeparator {
above: loginServerDelegate
below: xivApiServerDelegate
below: mainServerDelegate
}
FormCard.FormTextFieldDelegate {
id: xivApiServerDelegate
id: mainServerDelegate
label: i18n("XIV Api Server")
text: LauncherCore.settings.xivApiServer
onTextChanged: LauncherCore.settings.xivApiServer = text
label: i18n("Main Server (finalfantasyxiv.com)")
text: LauncherCore.settings.mainServer
onTextChanged: LauncherCore.settings.mainServer = text
}
}
}