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:
		
					parent
					
						
							
								316c1fb1ae
							
						
					
				
			
			
				commit
				
					
						7ec33e8e57
					
				
			
		
					 2 changed files with 27 additions and 0 deletions
				
			
		| 
						 | 
					@ -31,6 +31,16 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "libdanbooru_debug.h"
 | 
					#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
 | 
					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
 | 
					} // namespace Danbooru
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -119,5 +119,9 @@ QVariant parseDanbooruResult(QByteArray data, bool *result);
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating);
 | 
					bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void fixPostUrl(DanbooruPost *post, QUrl boardUrl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // UTILS_H
 | 
					#endif // UTILS_H
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue