mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
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:
parent
acf69139b9
commit
8ba8bbeef6
|
@ -55,6 +55,7 @@ SOURCES += \
|
|||
src/common/Channel.cpp \
|
||||
src/common/CompletionModel.cpp \
|
||||
src/common/DownloadManager.cpp \
|
||||
src/common/Env.cpp \
|
||||
src/common/LinkParser.cpp \
|
||||
src/common/NetworkData.cpp \
|
||||
src/common/NetworkManager.cpp \
|
||||
|
|
18
docs/ENV.md
18
docs/ENV.md
|
@ -1,8 +1,20 @@
|
|||
# Environment variables
|
||||
Below I have tried to list all environment variables that can be used to modify the behaviour of Chatterino. Used for things that I don't feel like fit in the settings system.
|
||||
|
||||
## CHATTERINO2_RECENT_MESSAGES_URL
|
||||
### CHATTERINO2_RECENT_MESSAGES_URL
|
||||
Used to change the URL that Chatterino2 uses when trying to load historic Twitch chat messages (if the setting is enabled).
|
||||
Default value: `"https://recent-messages.robotty.de/api/v2/recent-messages/%1?clearchatToNotice=true"`
|
||||
Default value: `https://recent-messages.robotty.de/api/v2/recent-messages/%1?clearchatToNotice=true`
|
||||
Arguments:
|
||||
1) `%1` = Name of the Twitch channel
|
||||
- `%1` = Name of the Twitch channel
|
||||
|
||||
### CHATTERINO2_LINK_RESOLVER_URL
|
||||
Used to change the URL that Chatterino2 uses when trying to get link information to display in the tooltip on hover.
|
||||
Default value: `https://braize.pajlada.com/chatterino/link_resolver/%1`
|
||||
Arguments:
|
||||
- `%1` = Escaped URL the link resolver should resolve
|
||||
|
||||
### CHATTERINO2_TWITCH_EMOTE_SET_RESOLVER_URL
|
||||
Used to change the URL that Chatterino2 uses when trying to get emote set information
|
||||
Default value: `https://braize.pajlada.com/chatterino/twitchemotes/set/%1/`
|
||||
Arguments:
|
||||
- `%1` = Emote set ID
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue