From f9c3c07d9819d9ec1f259b8576b5c9bd6961e309 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Mon, 4 Sep 2023 10:16:57 +1200 Subject: [PATCH] fix: Support UNIX paths --- .../AddModelsPanel/AdvancedAddCheckpoint.tsx | 19 +++++++++++-------- .../AddModelsPanel/AdvancedAddDiffusers.tsx | 13 ++++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddCheckpoint.tsx b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddCheckpoint.tsx index 4f452b0727..8a525c543b 100644 --- a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddCheckpoint.tsx +++ b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddCheckpoint.tsx @@ -28,7 +28,7 @@ export default function AdvancedAddCheckpoint( const advancedAddCheckpointForm = useForm({ initialValues: { - model_name: model_path?.split('\\').splice(-1)[0]?.split('.')[0] ?? '', + model_name: model_path?.match(/[^\\/]+$/)?.[0]?.split('.')[0] ?? '', base_model: 'sd-1', model_type: 'main', path: model_path ? model_path : '', @@ -102,13 +102,16 @@ export default function AdvancedAddCheckpoint( {...advancedAddCheckpointForm.getInputProps('path')} onBlur={(e) => { if (advancedAddCheckpointForm.values['model_name'] === '') { - advancedAddCheckpointForm.setFieldValue( - 'model_name', - e.currentTarget.value - .split('\\') - .splice(-1)[0] - ?.split('.')[0] as string - ); + const modelName = e.currentTarget.value + .match(/[^\\/]+$/)?.[0] + ?.split('.')[0]; + + if (modelName) { + advancedAddCheckpointForm.setFieldValue( + 'model_name', + modelName as string + ); + } } }} /> diff --git a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddDiffusers.tsx b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddDiffusers.tsx index f576f5a61f..469c0c7061 100644 --- a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddDiffusers.tsx +++ b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddDiffusers.tsx @@ -25,7 +25,7 @@ export default function AdvancedAddDiffusers(props: AdvancedAddDiffusersProps) { const advancedAddDiffusersForm = useForm({ initialValues: { - model_name: model_path?.split('\\').splice(-1)[0] ?? '', + model_name: model_path?.match(/[^\\/]+$/)?.[0] ?? '', base_model: 'sd-1', model_type: 'main', path: model_path ? model_path : '', @@ -94,10 +94,13 @@ export default function AdvancedAddDiffusers(props: AdvancedAddDiffusersProps) { {...advancedAddDiffusersForm.getInputProps('path')} onBlur={(e) => { if (advancedAddDiffusersForm.values['model_name'] === '') { - advancedAddDiffusersForm.setFieldValue( - 'model_name', - e.currentTarget.value.split('\\').splice(-1)[0] as string - ); + const modelName = e.currentTarget.value.match(/[^\\/]+$/)?.[0]; + if (modelName) { + advancedAddDiffusersForm.setFieldValue( + 'model_name', + modelName as string + ); + } } }} />