lobehub/src/app/api/plugin/gateway/settings.ts
Arvin Xu efd9dc9df2
feat: support plugin settings env (#821)
*  feat: support plugin settings env

* 📝 docs: add plugin settings document
2023-12-27 20:43:03 +08:00

29 lines
781 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const parserPluginSettings = (
settingsStr?: string,
): Record<string, Record<string, string>> => {
if (!settingsStr) return {};
const settings = new Map();
const array = settingsStr.split(/[,]/).filter(Boolean);
for (const item of array) {
const [id, pluginSettingsStr] = item.split(':');
if (!id) continue;
const pluginSettingItems = pluginSettingsStr.split(';');
const cleanId = id.trim();
for (const item of pluginSettingItems) {
const [key, value] = item.split('=');
if (!key || !value) continue;
const cleanKey = key.trim();
const cleanValue = value.trim();
settings.set(cleanId, { ...settings.get(cleanId), [cleanKey]: cleanValue });
}
}
return Object.fromEntries(settings.entries());
};