fix(dashboard): pasting secrets into create secret modal

This commit is contained in:
Daniel Hougaard
2024-12-10 04:01:17 +04:00
parent 68988a3e78
commit d2b909b72b
3 changed files with 47 additions and 10 deletions
+19 -4
View File
@@ -1,14 +1,29 @@
/** Extracts the key and value from a passed in env string based on the provided delimiters. */
export const getKeyValue = (pastedContent: string, delimiters: string[]) => {
const foundDelimiter = delimiters.find((delimiter) => pastedContent.includes(delimiter));
if (!pastedContent) {
return { key: "", value: "" };
}
if (!foundDelimiter) {
let firstDelimiterIndex = -1;
let foundDelimiter = "";
delimiters.forEach((delimiter) => {
const index = pastedContent.indexOf(delimiter);
if (index !== -1 && (firstDelimiterIndex === -1 || index < firstDelimiterIndex)) {
firstDelimiterIndex = index;
foundDelimiter = delimiter;
}
});
if (firstDelimiterIndex === -1) {
return { key: pastedContent.trim(), value: "" };
}
const [key, value] = pastedContent.split(foundDelimiter);
const key = pastedContent.substring(0, firstDelimiterIndex);
const value = pastedContent.substring(firstDelimiterIndex + foundDelimiter.length);
return {
key: key.trim(),
value: (value ?? "").trim()
value: value.trim()
};
};