mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-17 23:05:20 +00:00
refac/fix: valves array type handling
Co-Authored-By: Jacob Leksan <63938553+jmleksan@users.noreply.github.com>
This commit is contained in:
parent
a7061383e8
commit
53cd660de7
2 changed files with 28 additions and 7 deletions
|
|
@ -27,10 +27,19 @@
|
||||||
class="p-1 px-3 text-xs flex rounded-sm transition"
|
class="p-1 px-3 text-xs flex rounded-sm transition"
|
||||||
type="button"
|
type="button"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
valves[property] =
|
const propertySpec = valvesSpec.properties[property] ?? {};
|
||||||
(valves[property] ?? null) === null
|
|
||||||
? (valvesSpec.properties[property]?.default ?? '')
|
if ((valves[property] ?? null) === null) {
|
||||||
: null;
|
// Initialize to custom value
|
||||||
|
if ((propertySpec?.type ?? null) === 'array') {
|
||||||
|
const defaultArray = propertySpec?.default ?? [];
|
||||||
|
valves[property] = Array.isArray(defaultArray) ? defaultArray.join(', ') : '';
|
||||||
|
} else {
|
||||||
|
valves[property] = propertySpec?.default ?? '';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
valves[property] = null;
|
||||||
|
}
|
||||||
|
|
||||||
dispatch('change');
|
dispatch('change');
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,14 @@
|
||||||
// Convert string to array
|
// Convert string to array
|
||||||
for (const property in valvesSpec.properties) {
|
for (const property in valvesSpec.properties) {
|
||||||
if (valvesSpec.properties[property]?.type === 'array') {
|
if (valvesSpec.properties[property]?.type === 'array') {
|
||||||
valves[property] = (valves[property] ?? '').split(',').map((v) => v.trim());
|
if (typeof valves[property] === 'string') {
|
||||||
|
valves[property] = (valves[property] ?? '')
|
||||||
|
.split(',')
|
||||||
|
.map((v) => v.trim())
|
||||||
|
.filter((v) => v.length > 0);
|
||||||
|
} else if (valves[property] == null) {
|
||||||
|
valves[property] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,10 +127,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valvesSpec) {
|
if (valvesSpec) {
|
||||||
// Convert array to string
|
|
||||||
for (const property in valvesSpec.properties) {
|
for (const property in valvesSpec.properties) {
|
||||||
if (valvesSpec.properties[property]?.type === 'array') {
|
if (valvesSpec.properties[property]?.type === 'array') {
|
||||||
valves[property] = (valves[property] ?? []).join(',');
|
if (valves[property] != null) {
|
||||||
|
valves[property] = (Array.isArray(valves[property]) ? valves[property] : []).join(
|
||||||
|
','
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
valves[property] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue