Add a function to include host names in URLs that don't have it

Because appparently the original Danbooru doesn't add them...
This commit is contained in:
Luca Beltrame 2015-08-26 20:28:56 +02:00
parent 316c1fb1ae
commit 7ec33e8e57
2 changed files with 27 additions and 0 deletions

View file

@ -31,6 +31,16 @@
#include "libdanbooru_debug.h"
namespace {
QUrl adjustUrl(QUrl baseUrl, QUrl boardUrl) {
if(baseUrl.host().isEmpty()) {
baseUrl.setHost(boardUrl.host());
baseUrl.setScheme(boardUrl.scheme());
}
return baseUrl;
}
}
namespace Danbooru
{
@ -195,4 +205,17 @@ bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost
}
void fixPostUrl(DanbooruPost *post, QUrl boardUrl) {
auto thumbnailUrl = post->thumbnailUrl();
auto sampleUrl = post->sampleUrl();
auto fileUrl = post->fileUrl();
post->setThumbnailUrl(adjustUrl(thumbnailUrl, boardUrl));
post->setSampleUrl(adjustUrl(sampleUrl, boardUrl));
post->setFileUrl(adjustUrl(fileUrl, boardUrl));
}
} // namespace Danbooru

View file

@ -119,5 +119,9 @@ QVariant parseDanbooruResult(QByteArray data, bool *result);
*/
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating);
void fixPostUrl(DanbooruPost *post, QUrl boardUrl);
}
#endif // UTILS_H