Load and store redirects properly.

This commit is contained in:
Lukas Brübach 2024-11-22 18:33:15 +01:00
parent d22137bb89
commit eca74114a2
3 changed files with 12 additions and 3 deletions

View file

@ -145,10 +145,13 @@ PictureLoaderWorker::PictureLoaderWorker()
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(picDownloadFinished(QNetworkReply *)));
cacheFilePath = "redirectCache.ini";
cacheFilePath = SettingsCache::instance().getRedirectCachePath() + "cacheSettings.ini";
loadRedirectCache();
cleanStaleEntries();
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this,
&PictureLoaderWorker::saveRedirectCache);
pictureLoaderThread = new QThread;
pictureLoaderThread->start(QThread::LowPriority);
moveToThread(pictureLoaderThread);
@ -156,7 +159,6 @@ PictureLoaderWorker::PictureLoaderWorker()
PictureLoaderWorker::~PictureLoaderWorker()
{
saveRedirectCache();
pictureLoaderThread->deleteLater();
}
@ -489,6 +491,7 @@ QNetworkReply *PictureLoaderWorker::makeRequest(const QUrl &url)
void PictureLoaderWorker::cacheRedirect(const QUrl &originalUrl, const QUrl &redirectUrl)
{
redirectCache[originalUrl] = qMakePair(redirectUrl, QDateTime::currentDateTimeUtc());
saveRedirectCache();
}
QUrl PictureLoaderWorker::getCachedRedirect(const QUrl &originalUrl) const
@ -520,6 +523,7 @@ void PictureLoaderWorker::loadRedirectCache()
void PictureLoaderWorker::saveRedirectCache() const
{
qDebug() << "Saving redirect cache";
QSettings settings(cacheFilePath, QSettings::IniFormat);
settings.beginWriteArray("redirects", redirectCache.size());

View file

@ -1030,6 +1030,7 @@ void SettingsCache::loadPaths()
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
themesPath = getSafeConfigPath("paths/themes", dataPath + "/themes/");
picsPath = getSafeConfigPath("paths/pics", dataPath + "/pics/");
redirectCachePath = getSafeConfigPath("paths/redirects", dataPath + "/pics/redirects/");
// this has never been exposed as an user-configurable setting
if (picsPath.endsWith("/")) {
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "CUSTOM/");

View file

@ -73,7 +73,7 @@ private:
QByteArray tokenDialogGeometry;
QByteArray setsDialogGeometry;
QString lang;
QString deckPath, replaysPath, picsPath, customPicsPath, cardDatabasePath, customCardDatabasePath, themesPath,
QString deckPath, replaysPath, picsPath, redirectCachePath, customPicsPath, cardDatabasePath, customCardDatabasePath, themesPath,
spoilerDatabasePath, tokenDatabasePath, themeName;
bool notifyAboutUpdates;
bool notifyAboutNewVersion;
@ -183,6 +183,10 @@ public:
{
return picsPath;
}
QString getRedirectCachePath() const
{
return redirectCachePath;
}
QString getCustomPicsPath() const
{
return customPicsPath;