fix recall all when loras, controls, or hrf arent present

This commit is contained in:
Jennifer Player 2024-04-12 14:34:30 -04:00 committed by psychedelicious
parent fbfa29c2ef
commit c2e3c61f28
2 changed files with 55 additions and 34 deletions

View File

@ -156,8 +156,13 @@ const parseSteps: MetadataParseFunc<ParameterSteps> = (metadata) => getProperty(
const parseStrength: MetadataParseFunc<ParameterStrength> = (metadata) =>
getProperty(metadata, 'strength', isParameterStrength);
const parseHRFEnabled: MetadataParseFunc<ParameterHRFEnabled> = (metadata) =>
getProperty(metadata, 'hrf_enabled', isParameterHRFEnabled);
const parseHRFEnabled: MetadataParseFunc<ParameterHRFEnabled> = async (metadata) => {
try {
return await getProperty(metadata, 'hrf_enabled', isParameterHRFEnabled);
} catch {
return false;
}
};
const parseHRFStrength: MetadataParseFunc<ParameterStrength> = (metadata) =>
getProperty(metadata, 'hrf_strength', isParameterStrength);
@ -224,12 +229,16 @@ const parseLoRA: MetadataParseFunc<LoRA> = async (metadataItem) => {
};
const parseAllLoRAs: MetadataParseFunc<LoRA[]> = async (metadata) => {
const lorasRaw = await getProperty(metadata, 'loras', isArray);
const parseResults = await Promise.allSettled(lorasRaw.map((lora) => parseLoRA(lora)));
const loras = parseResults
.filter((result): result is PromiseFulfilledResult<LoRA> => result.status === 'fulfilled')
.map((result) => result.value);
return loras;
try {
const lorasRaw = await getProperty(metadata, 'loras', isArray);
const parseResults = await Promise.allSettled(lorasRaw.map((lora) => parseLoRA(lora)));
const loras = parseResults
.filter((result): result is PromiseFulfilledResult<LoRA> => result.status === 'fulfilled')
.map((result) => result.value);
return loras;
} catch {
return [];
}
};
const parseControlNet: MetadataParseFunc<ControlNetConfigMetadata> = async (metadataItem) => {
@ -288,12 +297,16 @@ const parseControlNet: MetadataParseFunc<ControlNetConfigMetadata> = async (meta
};
const parseAllControlNets: MetadataParseFunc<ControlNetConfigMetadata[]> = async (metadata) => {
const controlNetsRaw = await getProperty(metadata, 'controlnets', isArray);
const parseResults = await Promise.allSettled(controlNetsRaw.map((cn) => parseControlNet(cn)));
const controlNets = parseResults
.filter((result): result is PromiseFulfilledResult<ControlNetConfigMetadata> => result.status === 'fulfilled')
.map((result) => result.value);
return controlNets;
try {
const controlNetsRaw = await getProperty(metadata, 'controlnets', isArray || undefined);
const parseResults = await Promise.allSettled(controlNetsRaw.map((cn) => parseControlNet(cn)));
const controlNets = parseResults
.filter((result): result is PromiseFulfilledResult<ControlNetConfigMetadata> => result.status === 'fulfilled')
.map((result) => result.value);
return controlNets;
} catch {
return [];
}
};
const parseT2IAdapter: MetadataParseFunc<T2IAdapterConfigMetadata> = async (metadataItem) => {
@ -348,12 +361,16 @@ const parseT2IAdapter: MetadataParseFunc<T2IAdapterConfigMetadata> = async (meta
};
const parseAllT2IAdapters: MetadataParseFunc<T2IAdapterConfigMetadata[]> = async (metadata) => {
const t2iAdaptersRaw = await getProperty(metadata, 't2iAdapters', isArray);
const parseResults = await Promise.allSettled(t2iAdaptersRaw.map((t2iAdapter) => parseT2IAdapter(t2iAdapter)));
const t2iAdapters = parseResults
.filter((result): result is PromiseFulfilledResult<T2IAdapterConfigMetadata> => result.status === 'fulfilled')
.map((result) => result.value);
return t2iAdapters;
try {
const t2iAdaptersRaw = await getProperty(metadata, 't2iAdapters', isArray);
const parseResults = await Promise.allSettled(t2iAdaptersRaw.map((t2iAdapter) => parseT2IAdapter(t2iAdapter)));
const t2iAdapters = parseResults
.filter((result): result is PromiseFulfilledResult<T2IAdapterConfigMetadata> => result.status === 'fulfilled')
.map((result) => result.value);
return t2iAdapters;
} catch {
return [];
}
};
const parseIPAdapter: MetadataParseFunc<IPAdapterConfigMetadata> = async (metadataItem) => {
@ -394,12 +411,16 @@ const parseIPAdapter: MetadataParseFunc<IPAdapterConfigMetadata> = async (metada
};
const parseAllIPAdapters: MetadataParseFunc<IPAdapterConfigMetadata[]> = async (metadata) => {
const ipAdaptersRaw = await getProperty(metadata, 'ipAdapters', isArray);
const parseResults = await Promise.allSettled(ipAdaptersRaw.map((ipAdapter) => parseIPAdapter(ipAdapter)));
const ipAdapters = parseResults
.filter((result): result is PromiseFulfilledResult<IPAdapterConfigMetadata> => result.status === 'fulfilled')
.map((result) => result.value);
return ipAdapters;
try {
const ipAdaptersRaw = await getProperty(metadata, 'ipAdapters', isArray);
const parseResults = await Promise.allSettled(ipAdaptersRaw.map((ipAdapter) => parseIPAdapter(ipAdapter)));
const ipAdapters = parseResults
.filter((result): result is PromiseFulfilledResult<IPAdapterConfigMetadata> => result.status === 'fulfilled')
.map((result) => result.value);
return ipAdapters;
} catch {
return [];
}
};
export const parsers = {

View File

@ -177,11 +177,11 @@ const recallLoRA: MetadataRecallFunc<LoRA> = (lora) => {
};
const recallAllLoRAs: MetadataRecallFunc<LoRA[]> = (loras) => {
const { dispatch } = getStore();
dispatch(lorasReset());
if (!loras.length) {
return;
}
const { dispatch } = getStore();
dispatch(lorasReset());
loras.forEach((lora) => {
dispatch(loraRecalled(lora));
});
@ -192,11 +192,11 @@ const recallControlNet: MetadataRecallFunc<ControlNetConfigMetadata> = (controlN
};
const recallControlNets: MetadataRecallFunc<ControlNetConfigMetadata[]> = (controlNets) => {
const { dispatch } = getStore();
dispatch(controlNetsReset());
if (!controlNets.length) {
return;
}
const { dispatch } = getStore();
dispatch(controlNetsReset());
controlNets.forEach((controlNet) => {
dispatch(controlAdapterRecalled(controlNet));
});
@ -207,11 +207,11 @@ const recallT2IAdapter: MetadataRecallFunc<T2IAdapterConfigMetadata> = (t2iAdapt
};
const recallT2IAdapters: MetadataRecallFunc<T2IAdapterConfigMetadata[]> = (t2iAdapters) => {
const { dispatch } = getStore();
dispatch(t2iAdaptersReset());
if (!t2iAdapters.length) {
return;
}
const { dispatch } = getStore();
dispatch(t2iAdaptersReset());
t2iAdapters.forEach((t2iAdapter) => {
dispatch(controlAdapterRecalled(t2iAdapter));
});
@ -222,11 +222,11 @@ const recallIPAdapter: MetadataRecallFunc<IPAdapterConfigMetadata> = (ipAdapter)
};
const recallIPAdapters: MetadataRecallFunc<IPAdapterConfigMetadata[]> = (ipAdapters) => {
const { dispatch } = getStore();
dispatch(ipAdaptersReset());
if (!ipAdapters.length) {
return;
}
const { dispatch } = getStore();
dispatch(ipAdaptersReset());
ipAdapters.forEach((ipAdapter) => {
dispatch(controlAdapterRecalled(ipAdapter));
});