Share deck analysis URL validation and drop the unused request latch

Both analysis interfaces carried a copy of normalizeAnalysisUrl; move it to one
header next to them. They are constructed per analysis and analyzeDeck is called
once, so the analysisStarted latch was unreachable; remove it from both.
This commit is contained in:
Lukas Brübach 2026-11-04 06:21:51 +01:00
parent 02de7e1c55
commit 1229a95b7f
5 changed files with 44 additions and 54 deletions

View file

@ -1,5 +1,6 @@
#include "tapped_out_interface.h"
#include "deck_analysis_url.h"
#include "libcockatrice/card/card_info.h"
#include "libcockatrice/card/database/card_database_querier.h"
#include "libcockatrice/deck_list/tree/inner_deck_list_node.h"
@ -31,28 +32,6 @@
#include <libcockatrice/network/network_manager.h>
#include <version_string.h>
namespace
{
bool normalizeAnalysisUrl(QUrl &url, const QString &serviceHost)
{
const QString host = url.host().toLower();
const bool legacyHttp = url.scheme() == QStringLiteral("http");
const int defaultPort = legacyHttp ? 80 : 443;
if (!url.isValid() || (!legacyHttp && url.scheme() != QStringLiteral("https")) || !url.userInfo().isEmpty() ||
!url.path().startsWith('/') || (url.port() != -1 && url.port() != defaultPort) ||
(host != serviceHost && host != QStringLiteral("www.") + serviceHost)) {
return false;
}
// Both services accept HTTPS. Older public metadata may still identify the
// same deck with HTTP; retain its host/path/query while using HTTPS to open it.
if (legacyHttp) {
url.setScheme(QStringLiteral("https"));
url.setPort(-1);
}
return true;
}
} // namespace
TappedOutInterface::TappedOutInterface(QObject *parent) : QObject(parent)
{
manager = NetworkManagerFactory::create(this);
@ -134,10 +113,6 @@ void TappedOutInterface::getAnalyzeRequestData(const DeckList &deck, QByteArray
void TappedOutInterface::analyzeDeck(const DeckList &deck)
{
if (analysisStarted) {
return;
}
analysisStarted = true;
QByteArray data;
getAnalyzeRequestData(deck, data);