mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-06-01 01:54:00 +00:00
remove unused code
This commit is contained in:
@@ -105,8 +105,6 @@ set(SOURCES
|
|||||||
src/services/wikipedia/get_summary.cpp
|
src/services/wikipedia/get_summary.cpp
|
||||||
src/services/wikipedia/fetch_extract.cpp
|
src/services/wikipedia/fetch_extract.cpp
|
||||||
src/web_client/curl_global_state.cpp
|
src/web_client/curl_global_state.cpp
|
||||||
src/web_client/curl_web_client.cpp
|
|
||||||
src/web_client/curl_web_client_download_to_file.cpp
|
|
||||||
src/web_client/curl_web_client_get.cpp
|
src/web_client/curl_web_client_get.cpp
|
||||||
src/web_client/curl_web_client_utils.cpp
|
src/web_client/curl_web_client_utils.cpp
|
||||||
src/web_client/curl_web_client_url_encode.cpp
|
src/web_client/curl_web_client_url_encode.cpp
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
* @brief libcurl-based WebClient implementation.
|
* @brief libcurl-based WebClient implementation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "web_client/web_client.h"
|
#include "web_client/web_client.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,21 +34,6 @@ class CurlGlobalState {
|
|||||||
*/
|
*/
|
||||||
class CURLWebClient : public WebClient {
|
class CURLWebClient : public WebClient {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructs a CURL web client.
|
|
||||||
CURLWebClient();
|
|
||||||
|
|
||||||
/// @brief Destroys the CURL web client.
|
|
||||||
~CURLWebClient() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Downloads URL contents to a file.
|
|
||||||
*
|
|
||||||
* @param url Source URL.
|
|
||||||
* @param file_path Destination file path.
|
|
||||||
*/
|
|
||||||
void DownloadToFile(const std::string& url,
|
|
||||||
const std::string& file_path) override;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Executes an HTTP GET request.
|
* @brief Executes an HTTP GET request.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -16,15 +16,6 @@ class WebClient {
|
|||||||
/// @brief Virtual destructor for polymorphic cleanup.
|
/// @brief Virtual destructor for polymorphic cleanup.
|
||||||
virtual ~WebClient() = default;
|
virtual ~WebClient() = default;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Downloads content from a URL into a file.
|
|
||||||
*
|
|
||||||
* @param url Source URL.
|
|
||||||
* @param file_path Destination file path.
|
|
||||||
*/
|
|
||||||
virtual void DownloadToFile(const std::string& url,
|
|
||||||
const std::string& file_path) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Executes an HTTP GET request.
|
* @brief Executes an HTTP GET request.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file web_client/curl_web_client.cpp
|
|
||||||
* @brief CURLWebClient constructor and destructor implementation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "web_client/curl_web_client.h"
|
|
||||||
|
|
||||||
CURLWebClient::CURLWebClient() = default;
|
|
||||||
|
|
||||||
CURLWebClient::~CURLWebClient() = default;
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file web_client/curl_web_client_download_to_file.cpp
|
|
||||||
* @brief CURLWebClient::DownloadToFile() implementation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <curl/curl.h>
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
#include "curl_web_client_utils.h"
|
|
||||||
#include "web_client/curl_web_client.h"
|
|
||||||
|
|
||||||
// curl write callback that writes to a file stream
|
|
||||||
static size_t WriteCallbackFile(void* contents, size_t size, size_t nmemb,
|
|
||||||
void* userp) {
|
|
||||||
size_t realsize = size * nmemb;
|
|
||||||
auto* outFile = static_cast<std::ofstream*>(userp);
|
|
||||||
outFile->write(static_cast<char*>(contents), realsize);
|
|
||||||
return realsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CURLWebClient::DownloadToFile(const std::string& url,
|
|
||||||
const std::string& file_path) {
|
|
||||||
auto curl = create_handle();
|
|
||||||
|
|
||||||
std::ofstream outFile(file_path, std::ios::binary);
|
|
||||||
if (!outFile.is_open()) {
|
|
||||||
throw std::runtime_error(
|
|
||||||
"[CURLWebClient] Cannot open file for writing: " + file_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
set_common_get_options(curl.get(), url, {30L, 300L});
|
|
||||||
curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, WriteCallbackFile);
|
|
||||||
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA,
|
|
||||||
static_cast<void*>(&outFile));
|
|
||||||
|
|
||||||
CURLcode res = curl_easy_perform(curl.get());
|
|
||||||
outFile.close();
|
|
||||||
|
|
||||||
if (res != CURLE_OK) {
|
|
||||||
std::remove(file_path.c_str());
|
|
||||||
std::string error = std::string("[CURLWebClient] Download failed: ") +
|
|
||||||
curl_easy_strerror(res);
|
|
||||||
throw std::runtime_error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
long httpCode = 0;
|
|
||||||
curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE, &httpCode);
|
|
||||||
|
|
||||||
if (httpCode != 200) {
|
|
||||||
std::remove(file_path.c_str());
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "[CURLWebClient] HTTP error " << httpCode << " for URL " << url;
|
|
||||||
throw std::runtime_error(ss.str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user