Move environment variable parsing and storage to its own class

Make the Link resolver and Twitch emotes set resolver urls modifiable with
environment variables
This commit is contained in:
Rasmus Karlsson
2019-05-26 21:44:13 +02:00
parent acf69139b9
commit 8ba8bbeef6
5 changed files with 24 additions and 22 deletions
+3 -3
View File
@@ -1,6 +1,7 @@
#include "providers/LinkResolver.hpp"
#include "common/Common.hpp"
#include "common/Env.hpp"
#include "common/NetworkRequest.hpp"
#include "messages/Link.hpp"
#include "singletons/Settings.hpp"
@@ -17,11 +18,10 @@ void LinkResolver::getLinkInfo(
successCallback("No link info loaded", Link(Link::Url, url));
return;
}
QString requestUrl("https://braize.pajlada.com/chatterino/link_resolver/" +
QUrl::toPercentEncoding(url, "", "/:"));
// Uncomment to test crashes
// QTimer::singleShot(3000, [=]() {
NetworkRequest request(requestUrl);
NetworkRequest request(Env::get().linkResolverUrl.arg(
QString::fromUtf8(QUrl::toPercentEncoding(url, "", "/:"))));
request.setCaller(QThread::currentThread());
request.setTimeout(30000);
request.onSuccess([successCallback, url](auto result) mutable -> Outcome {
+2 -3
View File
@@ -3,6 +3,7 @@
#include <QThread>
#include "Application.hpp"
#include "common/Env.hpp"
#include "common/NetworkRequest.hpp"
#include "common/Outcome.hpp"
#include "debug/Log.hpp"
@@ -534,9 +535,7 @@ void TwitchAccount::loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet)
return;
}
NetworkRequest req(
"https://braize.pajlada.com/chatterino/twitchemotes/set/" +
emoteSet->key + "/");
NetworkRequest req(Env::get().twitchEmoteSetResolverUrl.arg(emoteSet->key));
req.setUseQuickLoadCache(true);
req.onError([](int errorCode) -> bool {
+3 -13
View File
@@ -2,6 +2,7 @@
#include "Application.hpp"
#include "common/Common.hpp"
#include "common/Env.hpp"
#include "common/NetworkRequest.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/notifications/NotificationController.hpp"
@@ -607,19 +608,8 @@ void TwitchChannel::loadRecentMessages()
return;
}
static QString genericURL = [] {
QString url("https://recent-messages.robotty.de/api/v2/recent-messages/"
"%1?clearchatToNotice=true");
auto envString = std::getenv("CHATTERINO2_RECENT_MESSAGES_URL");
if (envString != nullptr)
{
url = envString;
}
return url;
}();
NetworkRequest request(genericURL.arg(this->getName()));
NetworkRequest request(
Env::get().recentMessagesApiUrl.arg(this->getName()));
request.setCaller(QThread::currentThread());
// can't be concurrent right now due to SignalVector
// request.setExecuteConcurrently(true);