mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
refac
This commit is contained in:
parent
1c41e95ba6
commit
be7166d6fc
1 changed files with 53 additions and 1 deletions
|
|
@ -145,8 +145,60 @@
|
||||||
return variables;
|
return variables;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const splitProperties = (str: string, delimiter: string): string[] => {
|
||||||
|
const result: string[] = [];
|
||||||
|
let current = '';
|
||||||
|
let depth = 0;
|
||||||
|
let inString = false;
|
||||||
|
let escapeNext = false;
|
||||||
|
|
||||||
|
for (let i = 0; i < str.length; i++) {
|
||||||
|
const char = str[i];
|
||||||
|
|
||||||
|
if (escapeNext) {
|
||||||
|
current += char;
|
||||||
|
escapeNext = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (char === '\\') {
|
||||||
|
current += char;
|
||||||
|
escapeNext = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (char === '"' && !escapeNext) {
|
||||||
|
inString = !inString;
|
||||||
|
current += char;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inString) {
|
||||||
|
if (char === '{' || char === '[') {
|
||||||
|
depth++;
|
||||||
|
} else if (char === '}' || char === ']') {
|
||||||
|
depth--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (char === delimiter && depth === 0) {
|
||||||
|
result.push(current.trim());
|
||||||
|
current = '';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
current += char;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.trim()) {
|
||||||
|
result.push(current.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const parseVariableDefinition = (definition: string): Record<string, any> => {
|
const parseVariableDefinition = (definition: string): Record<string, any> => {
|
||||||
const [firstPart, ...propertyParts] = definition.split(':');
|
const [firstPart, ...propertyParts] = splitProperties(definition, ':');
|
||||||
|
|
||||||
// Parse type (explicit or implied)
|
// Parse type (explicit or implied)
|
||||||
const type = firstPart.startsWith('type=') ? firstPart.slice(5) : firstPart;
|
const type = firstPart.startsWith('type=') ? firstPart.slice(5) : firstPart;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue