mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:10:04 +00:00 
			
		
		
		
	Don't use a hard-coded user-agent for placefiles, add DPI parameter
This commit is contained in:
		
							parent
							
								
									751cafbfe7
								
							
						
					
					
						commit
						e3449e382d
					
				
					 5 changed files with 58 additions and 6 deletions
				
			
		|  | @ -1,8 +1,10 @@ | ||||||
| #include <scwx/qt/config/radar_site.hpp> | #include <scwx/qt/config/radar_site.hpp> | ||||||
| #include <scwx/qt/main/main_window.hpp> | #include <scwx/qt/main/main_window.hpp> | ||||||
|  | #include <scwx/qt/main/versions.hpp> | ||||||
| #include <scwx/qt/manager/radar_product_manager.hpp> | #include <scwx/qt/manager/radar_product_manager.hpp> | ||||||
| #include <scwx/qt/manager/resource_manager.hpp> | #include <scwx/qt/manager/resource_manager.hpp> | ||||||
| #include <scwx/qt/manager/settings_manager.hpp> | #include <scwx/qt/manager/settings_manager.hpp> | ||||||
|  | #include <scwx/network/cpr.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| #include <scwx/util/threads.hpp> | #include <scwx/util/threads.hpp> | ||||||
| 
 | 
 | ||||||
|  | @ -26,6 +28,8 @@ int main(int argc, char* argv[]) | ||||||
|    QApplication a(argc, argv); |    QApplication a(argc, argv); | ||||||
| 
 | 
 | ||||||
|    QCoreApplication::setApplicationName("Supercell Wx"); |    QCoreApplication::setApplicationName("Supercell Wx"); | ||||||
|  |    scwx::network::cpr::SetUserAgent( | ||||||
|  |       fmt::format("SupercellWx/{}", scwx::qt::main::kVersionString_)); | ||||||
| 
 | 
 | ||||||
|    // Enable internationalization support
 |    // Enable internationalization support
 | ||||||
|    QTranslator translator; |    QTranslator translator; | ||||||
|  |  | ||||||
|  | @ -1,11 +1,14 @@ | ||||||
| #include <scwx/qt/manager/placefile_manager.hpp> | #include <scwx/qt/manager/placefile_manager.hpp> | ||||||
| #include <scwx/gr/placefile.hpp> | #include <scwx/gr/placefile.hpp> | ||||||
|  | #include <scwx/network/cpr.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| 
 | 
 | ||||||
| #include <shared_mutex> | #include <shared_mutex> | ||||||
| #include <vector> | #include <vector> | ||||||
| 
 | 
 | ||||||
| #include <QDir> | #include <QDir> | ||||||
|  | #include <QGuiApplication> | ||||||
|  | #include <QScreen> | ||||||
| #include <QUrl> | #include <QUrl> | ||||||
| #include <boost/algorithm/string.hpp> | #include <boost/algorithm/string.hpp> | ||||||
| #include <boost/asio/post.hpp> | #include <boost/asio/post.hpp> | ||||||
|  | @ -340,9 +343,12 @@ void PlacefileManager::Impl::PlacefileRecord::Update() | ||||||
|          return; |          return; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|  |       auto dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch(); | ||||||
|  | 
 | ||||||
|       // Specify parameters
 |       // Specify parameters
 | ||||||
|       auto parameters = cpr::Parameters { |       auto parameters = cpr::Parameters { | ||||||
|          {"version", "1.2"}, // Placefile Version Supported
 |          {"version", "1.2"}, // Placefile Version Supported
 | ||||||
|  |          {"dpi", fmt::format("{:0.0f}", dpi)}, | ||||||
|          {"lat", fmt::format("{:0.3f}", p->radarSite_->latitude())}, |          {"lat", fmt::format("{:0.3f}", p->radarSite_->latitude())}, | ||||||
|          {"lon", fmt::format("{:0.3f}", p->radarSite_->longitude())}}; |          {"lon", fmt::format("{:0.3f}", p->radarSite_->longitude())}}; | ||||||
| 
 | 
 | ||||||
|  | @ -373,11 +379,8 @@ void PlacefileManager::Impl::PlacefileRecord::Update() | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       // Send HTTP GET request
 |       // Send HTTP GET request
 | ||||||
|       // TODO: Update hard coded User-Agent
 |  | ||||||
|       auto response = |       auto response = | ||||||
|          cpr::Get(cpr::Url {decodedUrl}, |          cpr::Get(cpr::Url {decodedUrl}, network::cpr::GetHeader(), parameters); | ||||||
|                   cpr::Header {{"User-Agent", "SupercellWx/0.2.2"}}, |  | ||||||
|                   parameters); |  | ||||||
| 
 | 
 | ||||||
|       if (cpr::status::is_success(response.status_code)) |       if (cpr::status::is_success(response.status_code)) | ||||||
|       { |       { | ||||||
|  |  | ||||||
							
								
								
									
										17
									
								
								wxdata/include/scwx/network/cpr.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								wxdata/include/scwx/network/cpr.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,17 @@ | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <cpr/cprtypes.h> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace network | ||||||
|  | { | ||||||
|  | namespace cpr | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | ::cpr::Header GetHeader(); | ||||||
|  | void          SetUserAgent(const std::string& userAgent); | ||||||
|  | 
 | ||||||
|  | } // namespace cpr
 | ||||||
|  | } // namespace network
 | ||||||
|  | } // namespace scwx
 | ||||||
							
								
								
									
										26
									
								
								wxdata/source/scwx/network/cpr.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								wxdata/source/scwx/network/cpr.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | ||||||
|  | #include <scwx/network/cpr.hpp> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace network | ||||||
|  | { | ||||||
|  | namespace cpr | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | static const std::string logPrefix_ = "scwx::network::cpr"; | ||||||
|  | 
 | ||||||
|  | static ::cpr::Header header_ {}; | ||||||
|  | 
 | ||||||
|  | ::cpr::Header GetHeader() | ||||||
|  | { | ||||||
|  |    return header_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void SetUserAgent(const std::string& userAgent) | ||||||
|  | { | ||||||
|  |    header_.insert_or_assign("User-Agent", userAgent); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | } // namespace cpr
 | ||||||
|  | } // namespace network
 | ||||||
|  | } // namespace scwx
 | ||||||
|  | @ -50,8 +50,10 @@ set(HDR_GR include/scwx/gr/color.hpp | ||||||
|            include/scwx/gr/placefile.hpp) |            include/scwx/gr/placefile.hpp) | ||||||
| set(SRC_GR source/scwx/gr/color.cpp | set(SRC_GR source/scwx/gr/color.cpp | ||||||
|            source/scwx/gr/placefile.cpp) |            source/scwx/gr/placefile.cpp) | ||||||
| set(HDR_NETWORK include/scwx/network/dir_list.hpp) | set(HDR_NETWORK include/scwx/network/cpr.hpp | ||||||
| set(SRC_NETWORK source/scwx/network/dir_list.cpp) |                 include/scwx/network/dir_list.hpp) | ||||||
|  | set(SRC_NETWORK source/scwx/network/cpr.cpp | ||||||
|  |                 source/scwx/network/dir_list.cpp) | ||||||
| set(HDR_PROVIDER include/scwx/provider/aws_level2_data_provider.hpp | set(HDR_PROVIDER include/scwx/provider/aws_level2_data_provider.hpp | ||||||
|                  include/scwx/provider/aws_level3_data_provider.hpp |                  include/scwx/provider/aws_level3_data_provider.hpp | ||||||
|                  include/scwx/provider/aws_nexrad_data_provider.hpp |                  include/scwx/provider/aws_nexrad_data_provider.hpp | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat