Refactor logo path handling in update-data.js

- Updated logic to create a Set of logo filenames instead of paths.
- Stripped directory path from logo.path to ensure only filenames are compared.
- Adjusted filtering for new logos to check against filenames directly.
- Ensured consistency in handling logo paths across the scanLogos and main functions.
- Minor formatting adjustments in logos.json to ensure proper file structure.
This commit is contained in:
sHa
2025-06-18 12:36:55 +03:00
parent 6e8168daac
commit d7feb6db19
4 changed files with 5103 additions and 5098 deletions

View File

@@ -5,4 +5,4 @@
"format": "SVG", "format": "SVG",
"disable": false "disable": false
} }
] ]

File diff suppressed because it is too large Load Diff

View File

@@ -3589,4 +3589,4 @@
], ],
"brand": "Bvr" "brand": "Bvr"
} }
] ]

View File

@@ -126,32 +126,34 @@ function scanLogos() {
/\.(svg|png|jpg|jpeg)$/i.test(file) /\.(svg|png|jpg|jpeg)$/i.test(file)
); );
// Create a Set of all logo paths in the directory // Create a Set of all logo filenames in the directory
const logoPathsSet = new Set(logoFiles.map(file => `${collection.baseDir}/${file}`)); const logoFilesSet = new Set(logoFiles);
// Mark existing records as disabled if they are not found in the directory // Mark existing records as disabled if they are not found in the directory
for (const logo of existing) { for (const logo of existing) {
if (!logoPathsSet.has(logo.path)) { // Fix: If logo.path contains a slash, strip to filename only
if (logo.path.includes('/')) {
logo.path = logo.path.split('/').pop();
}
if (!logoFilesSet.has(logo.path)) {
logo.disable = true; logo.disable = true;
} else if (logo.disable) { } else if (logo.disable) {
// If file exists, re-enable if previously disabled
logo.disable = false; logo.disable = false;
} }
} }
// Create a Set of existing paths to avoid duplication // Create a Set of existing filenames to avoid duplication
const existingPathsSet = new Set(existing.map(logo => logo.path)); const existingPathsSet = new Set(existing.map(logo => logo.path));
// Create new minimal logo objects for files that don't have records yet // Create new minimal logo objects for files that don't have records yet
const newLogos = logoFiles const newLogos = logoFiles
.filter(file => !existingPathsSet.has(`${collection.baseDir}/${file}`)) .filter(file => !existingPathsSet.has(file))
.map(file => { .map(file => {
const format = getFileExtension(file); const format = getFileExtension(file);
const logoPath = `${collection.baseDir}/${file}`;
// Only add minimal fields for new files // Only add minimal fields for new files
return { return {
name: formatName(file), name: formatName(file),
path: logoPath, path: file,
format: format, format: format,
disable: false disable: false
}; };
@@ -203,9 +205,13 @@ function main() {
const logoFiles = files.filter(file => const logoFiles = files.filter(file =>
/\.(svg|png|jpg|jpeg)$/i.test(file) /\.(svg|png|jpg|jpeg)$/i.test(file)
); );
const logoPathsSet = new Set(logoFiles.map(file => `${col.baseDir}/${file}`)); const logoFilesSet = new Set(logoFiles);
for (const logo of existing) { for (const logo of existing) {
if (!logoPathsSet.has(logo.path)) { // Fix: If logo.path contains a slash, strip to filename only
if (logo.path.includes('/')) {
logo.path = logo.path.split('/').pop();
}
if (!logoFilesSet.has(logo.path)) {
logo.disable = true; logo.disable = true;
} else if (logo.disable) { } else if (logo.disable) {
logo.disable = false; logo.disable = false;
@@ -213,13 +219,12 @@ function main() {
} }
const existingPathsSet = new Set(existing.map(logo => logo.path)); const existingPathsSet = new Set(existing.map(logo => logo.path));
const newLogos = logoFiles const newLogos = logoFiles
.filter(file => !existingPathsSet.has(`${col.baseDir}/${file}`)) .filter(file => !existingPathsSet.has(file))
.map(file => { .map(file => {
const format = getFileExtension(file); const format = getFileExtension(file);
const logoPath = `${col.baseDir}/${file}`;
return { return {
name: formatName(file), name: formatName(file),
path: logoPath, path: file,
format: format, format: format,
disable: false disable: false
}; };