mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add thumbnail dimensions to config (#3262)
* Add thumbnail dimensions to config * Fix default value for thumbnails.enabled * Update comment for thumbnail recreation instructions in config.yaml * Lint config values * Verify config size > 0 * More config lint
This commit is contained in:
@@ -28,6 +28,24 @@ const color = {
|
||||
white: (mess) => color.byNum(mess, 37),
|
||||
};
|
||||
|
||||
const keyMigrationMap = [
|
||||
{
|
||||
oldKey: 'disableThumbnails',
|
||||
newKey: 'thumbnails.enabled',
|
||||
migrate: (value) => !value,
|
||||
},
|
||||
{
|
||||
oldKey: 'thumbnailsQuality',
|
||||
newKey: 'thumbnails.quality',
|
||||
migrate: (value) => value,
|
||||
},
|
||||
{
|
||||
oldKey: 'avatarThumbnailsPng',
|
||||
newKey: 'thumbnails.format',
|
||||
migrate: (value) => (value ? 'png' : 'jpg'),
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets all keys from an object recursively.
|
||||
* @param {object} obj Object to get all keys from
|
||||
@@ -83,6 +101,24 @@ function addMissingConfigValues() {
|
||||
const defaultConfig = yaml.parse(fs.readFileSync(path.join(process.cwd(), './default/config.yaml'), 'utf8'));
|
||||
let config = yaml.parse(fs.readFileSync(path.join(process.cwd(), './config.yaml'), 'utf8'));
|
||||
|
||||
// Migrate old keys to new keys
|
||||
const migratedKeys = [];
|
||||
for (const { oldKey, newKey, migrate } of keyMigrationMap) {
|
||||
if (_.has(config, oldKey)) {
|
||||
const oldValue = _.get(config, oldKey);
|
||||
const newValue = migrate(oldValue);
|
||||
_.set(config, newKey, newValue);
|
||||
_.unset(config, oldKey);
|
||||
|
||||
migratedKeys.push({
|
||||
oldKey,
|
||||
newKey,
|
||||
oldValue,
|
||||
newValue,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Get all keys from the original config
|
||||
const originalKeys = getAllKeys(config);
|
||||
|
||||
@@ -95,11 +131,18 @@ function addMissingConfigValues() {
|
||||
// Find the keys that were added
|
||||
const addedKeys = _.difference(updatedKeys, originalKeys);
|
||||
|
||||
if (addedKeys.length === 0) {
|
||||
if (addedKeys.length === 0 && migratedKeys.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Adding missing config values to config.yaml:', addedKeys);
|
||||
if (addedKeys.length > 0) {
|
||||
console.log('Adding missing config values to config.yaml:', addedKeys);
|
||||
}
|
||||
|
||||
if (migratedKeys.length > 0) {
|
||||
console.log('Migrating config values in config.yaml:', migratedKeys);
|
||||
}
|
||||
|
||||
fs.writeFileSync('./config.yaml', yaml.stringify(config));
|
||||
} catch (error) {
|
||||
console.error(color.red('FATAL: Could not add missing config values to config.yaml'), error);
|
||||
|
Reference in New Issue
Block a user