Files
kidsbox/device/main/CacheManager.hpp
Claude bf9852c345 Implement full NFC-URL streaming architecture
- rc522: add NDEF URL reading via WUPA+cascade anticoll+SELECT+TLV parse
- AudioPlayer: route http:// URIs to esp_player_http_music_play()
- CacheManager: download URLs async to /sdcard/cache/{hash}.{ext}
- TagPlayerControl: NDEF URL → cache-or-stream; fallback to UID local mapping
- RFIDInterface: wire ndef_callback, expose combined uid+url callback
- WebInterface: add /api/info, /api/storage, /api/playback, /api/bluetooth
- BluetoothInterface: stub for A2DP speaker mode
- Networking: WiFi connect with 30s timeout instead of blocking forever
- main.cpp: re-enable WiFi + web server, fix init order, add CacheManager
- www/: full SPA — playback controls, device info, storage, BT pairing
- .gitmodules: switch rc522 submodule URL to HTTPS

https://claude.ai/code/session_01MhAnh68DPNnTjcKqjNYDmk
2026-06-12 19:44:54 +00:00

47 lines
1.4 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <functional>
struct CacheEntry {
std::string key; /* hex hash of the URL */
std::string url;
std::string path; /* full SD card path */
size_t size; /* file size in bytes, 0 if unknown */
};
class CacheManager {
public:
CacheManager();
/* Returns the SD-card path for url if cached, or empty string if not. */
std::string getCachedPath(const std::string& url) const;
/* Enqueue an async FreeRTOS task that downloads url and caches it.
* onComplete is called (from the download task) when done or on error. */
void downloadAsync(const std::string& url, std::function<void(bool success)> onComplete = nullptr);
/* List all cached entries. */
std::vector<CacheEntry> listEntries() const;
/* Delete a single cache entry by key (hex hash). Returns true if deleted. */
bool deleteEntry(const std::string& key);
/* Delete the entire cache directory. */
void deleteAll();
/* Total bytes used by cache. */
size_t totalBytes() const;
private:
static constexpr const char* CACHE_DIR = "/sdcard/cache";
std::string urlToKey(const std::string& url) const;
std::string urlExtension(const std::string& url) const;
std::string keyToPath(const std::string& key, const std::string& ext) const;
std::string findFileByKey(const std::string& key) const;
static void downloadTask(void* arg);
};