- Add /api/hash endpoint to compute and cache MD5 hashes on demand - Extend /api/files response with md5 field for EPUBs (null if not cached) - Compute and cache MD5 automatically after EPUB uploads - Add flush() before close() in WebSocket and HTTP upload handlers - New Md5Utils module using ESP32's mbedtls for chunked hash computation The MD5 hashes enable the companion app to detect file changes without downloading content. Hashes are cached in each book's .crosspoint cache directory and invalidated when file size changes.
45 lines
1.6 KiB
C++
45 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
|
|
namespace Md5Utils {
|
|
|
|
/**
|
|
* Compute MD5 hash of a file, reading in chunks to avoid memory issues.
|
|
* @param filePath Path to the file on SD card
|
|
* @return MD5 hash as lowercase hex string, or empty string on error
|
|
*/
|
|
std::string computeFileMd5(const std::string& filePath);
|
|
|
|
/**
|
|
* Get cached MD5 for a book file.
|
|
* Validates that the cached hash was computed for the current file size.
|
|
* @param bookPath Full path to the book file (e.g., "/Books/mybook.epub")
|
|
* @param cacheDir The .crosspoint cache directory (e.g., "/.crosspoint")
|
|
* @param currentFileSize Current size of the book file for validation
|
|
* @return Cached MD5 hash, or empty string if not cached or invalid
|
|
*/
|
|
std::string getCachedMd5(const std::string& bookPath, const std::string& cacheDir, size_t currentFileSize);
|
|
|
|
/**
|
|
* Cache MD5 hash for a book file.
|
|
* Stores the hash along with the file size for later validation.
|
|
* @param bookPath Full path to the book file
|
|
* @param cacheDir The .crosspoint cache directory
|
|
* @param md5 The MD5 hash to cache
|
|
* @param fileSize The file size when hash was computed
|
|
* @return true if successfully cached
|
|
*/
|
|
bool cacheMd5(const std::string& bookPath, const std::string& cacheDir, const std::string& md5, size_t fileSize);
|
|
|
|
/**
|
|
* Compute and cache MD5 hash for a book file.
|
|
* Combines computeFileMd5 and cacheMd5 into a single operation.
|
|
* @param bookPath Full path to the book file
|
|
* @param cacheDir The .crosspoint cache directory
|
|
* @return MD5 hash as lowercase hex string, or empty string on error
|
|
*/
|
|
std::string computeAndCacheMd5(const std::string& bookPath, const std::string& cacheDir);
|
|
|
|
} // namespace Md5Utils
|