mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 06:37:38 +03:00
## Summary - Rewrite OpdsParser to stream parsing instead of full content - Fix OOM due to big http xml response Closes #385 --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**NO**_
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#pragma once
|
|
#include <SDCardManager.h>
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
/**
|
|
* HTTP client utility for fetching content and downloading files.
|
|
* Wraps WiFiClientSecure and HTTPClient for HTTPS requests.
|
|
*/
|
|
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);
|
|
|
|
static bool fetchUrl(const std::string& url, Stream& stream);
|
|
|
|
/**
|
|
* 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);
|
|
|
|
private:
|
|
static constexpr size_t DOWNLOAD_CHUNK_SIZE = 1024;
|
|
};
|