2026-01-07 03:58:37 -05:00
|
|
|
#pragma once
|
2026-02-08 21:29:14 +01:00
|
|
|
#include <HalStorage.h>
|
2026-01-07 03:58:37 -05:00
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* HTTP client utility for fetching content and downloading files.
|
2026-02-22 11:31:33 +02:00
|
|
|
* Wraps NetworkClientSecure and HTTPClient for HTTPS requests.
|
2026-01-07 03:58:37 -05:00
|
|
|
*/
|
|
|
|
|
class HttpDownloader {
|
|
|
|
|
public:
|
|
|
|
|
using ProgressCallback = std::function<void(size_t downloaded, size_t total)>;
|
|
|
|
|
|
|
|
|
|
enum DownloadError {
|
|
|
|
|
OK = 0,
|
|
|
|
|
HTTP_ERROR,
|
|
|
|
|
FILE_ERROR,
|
|
|
|
|
ABORTED,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch text content from a URL.
|
|
|
|
|
* @param url The URL to fetch
|
|
|
|
|
* @param outContent The fetched content (output)
|
|
|
|
|
* @return true if fetch succeeded, false on error
|
|
|
|
|
*/
|
|
|
|
|
static bool fetchUrl(const std::string& url, std::string& outContent);
|
|
|
|
|
|
2026-01-21 17:43:51 +03:00
|
|
|
static bool fetchUrl(const std::string& url, Stream& stream);
|
|
|
|
|
|
2026-01-07 03:58:37 -05:00
|
|
|
/**
|
|
|
|
|
* Download a file to the SD card.
|
|
|
|
|
* @param url The URL to download
|
|
|
|
|
* @param destPath The destination path on SD card
|
|
|
|
|
* @param progress Optional progress callback
|
|
|
|
|
* @return DownloadError indicating success or failure type
|
|
|
|
|
*/
|
|
|
|
|
static DownloadError downloadToFile(const std::string& url, const std::string& destPath,
|
|
|
|
|
ProgressCallback progress = nullptr);
|
|
|
|
|
};
|