fix(ignore): Improvements for #25299 (#25364)

This commit is contained in:
Koen Kanters
2024-12-30 14:30:54 +01:00
committed by GitHub
parent 02666e9139
commit 1e7e00e8dd
2 changed files with 16 additions and 10 deletions
+9 -5
View File
@@ -459,15 +459,19 @@ function migrateToFour(
const saveBase64DeviceIconsAsImage = (currentSettings: Partial<Settings>): ReturnType<SettingsCustomHandler['execute']> => {
const [validPath, previousValue] = getValue(currentSettings, ['devices']);
let changed = false;
for (const deviceKey in currentSettings.devices) {
const base64Match = utils.matchBase64File(currentSettings.devices[deviceKey].icon ?? '');
if (base64Match) {
currentSettings.devices[deviceKey].icon = utils.saveBase64DeviceIcon(base64Match);
if (validPath) {
for (const deviceKey in currentSettings.devices) {
const base64Match = utils.matchBase64File(currentSettings.devices[deviceKey].icon);
if (base64Match) {
changed = true;
currentSettings.devices[deviceKey].icon = utils.saveBase64DeviceIcon(base64Match);
}
}
}
return [validPath, previousValue, validPath];
return [validPath, previousValue, changed];
};
customHandlers.push({
+7 -5
View File
@@ -375,11 +375,13 @@ function deviceNotCoordinator(device: zh.Device): boolean {
return device.type !== 'Coordinator';
}
function matchBase64File(value: string): {extension: string; data: string} | false {
const match = value.match(BASE64_IMAGE_REGEX);
if (match) {
assert(match.groups?.extension && match.groups?.data);
return {extension: match.groups.extension, data: match.groups.data};
function matchBase64File(value: string | undefined): {extension: string; data: string} | false {
if (value !== undefined) {
const match = value.match(BASE64_IMAGE_REGEX);
if (match) {
assert(match.groups?.extension && match.groups?.data);
return {extension: match.groups.extension, data: match.groups.data};
}
}
return false;
}