mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add cache validation func to startup
This commit is contained in:
@ -66,6 +66,7 @@ import { init as statsInit, onExit as statsOnExit } from './src/endpoints/stats.
|
||||
import { checkForNewContent } from './src/endpoints/content-manager.js';
|
||||
import { init as settingsInit } from './src/endpoints/settings.js';
|
||||
import { redirectDeprecatedEndpoints, ServerStartup, setupPrivateEndpoints } from './src/server-startup.js';
|
||||
import { verifyCharactersDiskCache } from './src/endpoints/characters.js';
|
||||
|
||||
// Unrestrict console logs display limit
|
||||
util.inspect.defaultOptions.maxArrayLength = null;
|
||||
@ -268,6 +269,7 @@ async function preSetupTasks() {
|
||||
const directories = await getUserDirectoriesList();
|
||||
await checkForNewContent(directories);
|
||||
await ensureThumbnailCache();
|
||||
await verifyCharactersDiskCache(directories);
|
||||
cleanUploads();
|
||||
migrateAccessLog();
|
||||
|
||||
|
@ -54,6 +54,34 @@ const diskCache = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Verifies disk cache size and prunes it if necessary.
|
||||
* @param {import('../users.js').UserDirectoryList[]} directoriesList List of user directories
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function verifyCharactersDiskCache(directoriesList) {
|
||||
if (!useDiskCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cache = await diskCache.instance();
|
||||
const validKeys = [];
|
||||
for (const dir of directoriesList) {
|
||||
const files = fs.readdirSync(dir.characters);
|
||||
for (const file of files) {
|
||||
const filePath = path.join(dir.characters, file);
|
||||
const stat = fs.statSync(filePath);
|
||||
validKeys.push(`${filePath}-${stat.mtimeMs}`);
|
||||
}
|
||||
}
|
||||
const cacheKeys = await cache.keys();
|
||||
for (const key of cacheKeys) {
|
||||
if (!validKeys.includes(key)) {
|
||||
await cache.removeItem(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the character card from the specified image file.
|
||||
* @param {string} inputFile - Path to the image file
|
||||
|
Reference in New Issue
Block a user