fix: Support UNIX paths

This commit is contained in:
blessedcoolant 2023-09-04 10:16:57 +12:00
parent c91ba2dbe7
commit f9c3c07d98
2 changed files with 19 additions and 13 deletions

View File

@ -28,7 +28,7 @@ export default function AdvancedAddCheckpoint(
const advancedAddCheckpointForm = useForm<CheckpointModelConfig>({
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
);
}
}
}}
/>

View File

@ -25,7 +25,7 @@ export default function AdvancedAddDiffusers(props: AdvancedAddDiffusersProps) {
const advancedAddDiffusersForm = useForm<DiffusersModelConfig>({
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
);
}
}
}}
/>