mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
Text fix
This commit is contained in:
parent
b483b46b40
commit
07ccf3acc0
@ -38,7 +38,7 @@ class RecentBooksStore {
|
|||||||
* Update the path of a book in the recent list.
|
* Update the path of a book in the recent list.
|
||||||
* Useful when moving/renaming files or entire directories.
|
* Useful when moving/renaming files or entire directories.
|
||||||
* If oldPath is a directory, all books within will have their paths updated.
|
* If oldPath is a directory, all books within will have their paths updated.
|
||||||
*
|
*
|
||||||
* @param oldPath Original absolute path
|
* @param oldPath Original absolute path
|
||||||
* @param newPath New absolute path
|
* @param newPath New absolute path
|
||||||
*/
|
*/
|
||||||
@ -46,4 +46,4 @@ class RecentBooksStore {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Helper macro to access recent books store
|
// Helper macro to access recent books store
|
||||||
#define RECENT_BOOKS RecentBooksStore::getInstance()
|
#define RECENT_BOOKS RecentBooksStore::getInstance()
|
||||||
@ -1,7 +1,6 @@
|
|||||||
#include "CrossPointWebServer.h"
|
#include "CrossPointWebServer.h"
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include "util/BookCacheManager.h"
|
|
||||||
#include <Epub.h>
|
#include <Epub.h>
|
||||||
#include <FsHelpers.h>
|
#include <FsHelpers.h>
|
||||||
#include <SDCardManager.h>
|
#include <SDCardManager.h>
|
||||||
@ -12,6 +11,7 @@
|
|||||||
|
|
||||||
#include "html/FilesPageHtml.generated.h"
|
#include "html/FilesPageHtml.generated.h"
|
||||||
#include "html/HomePageHtml.generated.h"
|
#include "html/HomePageHtml.generated.h"
|
||||||
|
#include "util/BookCacheManager.h"
|
||||||
#include "util/StringUtils.h"
|
#include "util/StringUtils.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -848,7 +848,7 @@ void CrossPointWebServer::handleRename() const {
|
|||||||
if (!newPath.startsWith("/")) newPath = "/" + newPath;
|
if (!newPath.startsWith("/")) newPath = "/" + newPath;
|
||||||
|
|
||||||
// Security check: prevent renaming system files
|
// Security check: prevent renaming system files
|
||||||
if (oldPath.substring(oldPath.lastIndexOf('/') + 1).startsWith(".") ||
|
if (oldPath.substring(oldPath.lastIndexOf('/') + 1).startsWith(".") ||
|
||||||
newPath.substring(newPath.lastIndexOf('/') + 1).startsWith(".")) {
|
newPath.substring(newPath.lastIndexOf('/') + 1).startsWith(".")) {
|
||||||
server->send(403, "text/plain", "Cannot rename system files");
|
server->send(403, "text/plain", "Cannot rename system files");
|
||||||
return;
|
return;
|
||||||
@ -875,8 +875,6 @@ void CrossPointWebServer::handleRename() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// WebSocket callback trampoline
|
// WebSocket callback trampoline
|
||||||
void CrossPointWebServer::wsEventCallback(uint8_t num, WStype_t type, uint8_t* payload, size_t length) {
|
void CrossPointWebServer::wsEventCallback(uint8_t num, WStype_t type, uint8_t* payload, size_t length) {
|
||||||
if (wsInstance) {
|
if (wsInstance) {
|
||||||
|
|||||||
@ -80,5 +80,4 @@ class CrossPointWebServer {
|
|||||||
void handleDelete() const;
|
void handleDelete() const;
|
||||||
void handleMove() const;
|
void handleMove() const;
|
||||||
void handleRename() const;
|
void handleRename() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
#include "BookCacheManager.h"
|
#include "BookCacheManager.h"
|
||||||
#include "StringUtils.h"
|
|
||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
#include "../RecentBooksStore.h"
|
|
||||||
#include "../CrossPointState.h"
|
#include "../CrossPointState.h"
|
||||||
|
#include "../RecentBooksStore.h"
|
||||||
|
#include "StringUtils.h"
|
||||||
|
|
||||||
bool BookCacheManager::migrateCache(const String& oldPath, const String& newPath) {
|
bool BookCacheManager::migrateCache(const String& oldPath, const String& newPath) {
|
||||||
if (oldPath == newPath) return true;
|
if (oldPath == newPath) return true;
|
||||||
@ -40,7 +42,7 @@ bool BookCacheManager::migrateCache(const String& oldPath, const String& newPath
|
|||||||
|
|
||||||
String subOldPath = oldPath + "/" + fileName;
|
String subOldPath = oldPath + "/" + fileName;
|
||||||
String subNewPath = newPath + "/" + fileName;
|
String subNewPath = newPath + "/" + fileName;
|
||||||
|
|
||||||
if (!migrateCache(subOldPath, subNewPath)) {
|
if (!migrateCache(subOldPath, subNewPath)) {
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
@ -52,7 +54,7 @@ bool BookCacheManager::migrateCache(const String& oldPath, const String& newPath
|
|||||||
|
|
||||||
// It's a file. check if it's a supported book type
|
// It's a file. check if it's a supported book type
|
||||||
if (!isSupportedFile(oldPath)) {
|
if (!isSupportedFile(oldPath)) {
|
||||||
return true; // Not a book, nothing to migrate
|
return true; // Not a book, nothing to migrate
|
||||||
}
|
}
|
||||||
|
|
||||||
String oldCache = getCachePath(oldPath);
|
String oldCache = getCachePath(oldPath);
|
||||||
@ -78,7 +80,7 @@ bool BookCacheManager::migrateCache(const String& oldPath, const String& newPath
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true; // No old cache to migrate
|
return true; // No old cache to migrate
|
||||||
}
|
}
|
||||||
|
|
||||||
String BookCacheManager::getCachePath(const String& path) {
|
String BookCacheManager::getCachePath(const String& path) {
|
||||||
@ -89,15 +91,13 @@ String BookCacheManager::getCachePath(const String& path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool BookCacheManager::isSupportedFile(const String& path) {
|
bool BookCacheManager::isSupportedFile(const String& path) {
|
||||||
return StringUtils::checkFileExtension(path, ".epub") ||
|
return StringUtils::checkFileExtension(path, ".epub") || StringUtils::checkFileExtension(path, ".txt") ||
|
||||||
StringUtils::checkFileExtension(path, ".txt") ||
|
StringUtils::checkFileExtension(path, ".xtc") || StringUtils::checkFileExtension(path, ".xtg") ||
|
||||||
StringUtils::checkFileExtension(path, ".xtc") ||
|
|
||||||
StringUtils::checkFileExtension(path, ".xtg") ||
|
|
||||||
StringUtils::checkFileExtension(path, ".xth");
|
StringUtils::checkFileExtension(path, ".xth");
|
||||||
}
|
}
|
||||||
|
|
||||||
String BookCacheManager::getCachePrefix(const String& path) {
|
String BookCacheManager::getCachePrefix(const String& path) {
|
||||||
if (StringUtils::checkFileExtension(path, ".epub")) return "epub";
|
if (StringUtils::checkFileExtension(path, ".epub")) return "epub";
|
||||||
if (StringUtils::checkFileExtension(path, ".txt")) return "txt";
|
if (StringUtils::checkFileExtension(path, ".txt")) return "txt";
|
||||||
return "xtc"; // .xtc, .xtg, .xth
|
return "xtc"; // .xtc, .xtg, .xth
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <SDCardManager.h>
|
#include <SDCardManager.h>
|
||||||
#include <WString.h>
|
#include <WString.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class BookCacheManager {
|
class BookCacheManager {
|
||||||
@ -9,7 +10,7 @@ class BookCacheManager {
|
|||||||
/**
|
/**
|
||||||
* Migrate cache data for a file or directory.
|
* Migrate cache data for a file or directory.
|
||||||
* If path is a directory, it recursively migrates all files within.
|
* If path is a directory, it recursively migrates all files within.
|
||||||
*
|
*
|
||||||
* @param oldPath Original absolute path
|
* @param oldPath Original absolute path
|
||||||
* @param newPath New absolute path
|
* @param newPath New absolute path
|
||||||
* @return true if migration was successful or no cache existed
|
* @return true if migration was successful or no cache existed
|
||||||
@ -18,7 +19,7 @@ class BookCacheManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cache directory path for a given book file.
|
* Get the cache directory path for a given book file.
|
||||||
*
|
*
|
||||||
* @param path Absolute path to the book file
|
* @param path Absolute path to the book file
|
||||||
* @return Full path to the cache directory, or empty string if not a supported book type
|
* @return Full path to the cache directory, or empty string if not a supported book type
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user