2018-08-25 20:38:14 +02:00
|
|
|
#include "providers/LinkResolver.hpp"
|
2018-08-24 11:56:42 +02:00
|
|
|
|
|
|
|
#include "common/Common.hpp"
|
|
|
|
#include "common/NetworkRequest.hpp"
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2018-08-25 20:38:14 +02:00
|
|
|
void LinkResolver::getLinkInfo(const QString url,
|
2018-08-24 11:56:42 +02:00
|
|
|
std::function<void(QString)> successCallback)
|
|
|
|
{
|
2018-08-26 14:41:46 +02:00
|
|
|
QString requestUrl("https://braize.pajlada.com/chatterino/link_resolver/" +
|
2018-08-24 11:56:42 +02:00
|
|
|
QUrl::toPercentEncoding(url, "", "/:"));
|
|
|
|
|
|
|
|
NetworkRequest request(requestUrl);
|
|
|
|
request.setCaller(QThread::currentThread());
|
|
|
|
request.setTimeout(30000);
|
|
|
|
request.onSuccess([successCallback](auto result) mutable -> Outcome {
|
|
|
|
auto root = result.parseJson();
|
|
|
|
/* When tooltip is not a string, in this case,
|
|
|
|
onError runs before onSuccess,
|
|
|
|
so there is no point in doing "if" condition. */
|
|
|
|
auto tooltip = root.value("tooltip").toString();
|
|
|
|
successCallback(QUrl::fromPercentEncoding(tooltip.toUtf8()));
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
});
|
|
|
|
|
|
|
|
request.onError([successCallback](auto result) {
|
|
|
|
successCallback("No link info found");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
request.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|