lets try this again (Config fix) (#1159)
* Introducing a custom settings file * formats * chnages * Update README.md * fixes --------- Co-authored-by: a <a>
This commit is contained in:
parent
890163053b
commit
38979dd362
2 changed files with 61 additions and 41 deletions
|
@ -76,53 +76,76 @@ public class ConfigInitializer
|
||||||
Files.createFile(customSettingsPath);
|
Files.createFile(customSettingsPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, String> extractEntries(List<String> lines) {
|
private static Map<String, String> extractEntries(List<String> lines) {
|
||||||
Map<String, String> entries = new HashMap<>();
|
Map<String, String> entries = new HashMap<>();
|
||||||
String keyRegex = "^\\s*(\\w+)\\s*:\\s*(.*)"; // Capture key and value
|
StringBuilder currentEntry = new StringBuilder();
|
||||||
Pattern pattern = Pattern.compile(keyRegex);
|
String currentKey = null;
|
||||||
|
int blockIndent = -1;
|
||||||
|
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
Matcher matcher = pattern.matcher(line);
|
if (line.trim().isEmpty()) {
|
||||||
if (matcher.find() && !line.trim().startsWith("#")) {
|
if (currentKey != null) {
|
||||||
String key = matcher.group(1).trim();
|
currentEntry.append(line).append("\n");
|
||||||
String value = matcher.group(2).trim(); // Capture the value directly
|
}
|
||||||
entries.put(key, line);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int indentLevel = getIndentationLevel(line);
|
||||||
|
if (line.trim().startsWith("#")) {
|
||||||
|
if (indentLevel <= blockIndent || blockIndent == -1) {
|
||||||
|
if (currentKey != null) {
|
||||||
|
entries.put(currentKey, currentEntry.toString().trim());
|
||||||
|
currentEntry = new StringBuilder();
|
||||||
|
}
|
||||||
|
currentKey = line.trim().replaceAll("#", "").split(":")[0].trim();
|
||||||
|
blockIndent = indentLevel;
|
||||||
|
}
|
||||||
|
currentEntry.append(line).append("\n");
|
||||||
|
} else if (indentLevel == 0 || indentLevel <= blockIndent) {
|
||||||
|
if (currentKey != null) {
|
||||||
|
entries.put(currentKey, currentEntry.toString().trim());
|
||||||
|
currentEntry = new StringBuilder();
|
||||||
|
}
|
||||||
|
currentKey = line.split(":")[0].trim();
|
||||||
|
blockIndent = indentLevel;
|
||||||
|
currentEntry.append(line).append("\n");
|
||||||
|
} else {
|
||||||
|
currentEntry.append(line).append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentKey != null) {
|
||||||
|
entries.put(currentKey, currentEntry.toString().trim());
|
||||||
|
}
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static List<String> mergeConfigs(
|
private static List<String> mergeConfigs(List<String> templateLines, Map<String, String> templateEntries, Map<String, String> userEntries) {
|
||||||
List<String> templateLines,
|
|
||||||
Map<String, String> templateEntries,
|
|
||||||
Map<String, String> userEntries) {
|
|
||||||
List<String> mergedLines = new ArrayList<>();
|
List<String> mergedLines = new ArrayList<>();
|
||||||
Set<String> handledKeys = new HashSet<>();
|
Set<String> handledKeys = new HashSet<>();
|
||||||
|
|
||||||
|
String currentBlockKey = null;
|
||||||
|
int blockIndent = -1;
|
||||||
|
|
||||||
for (String line : templateLines) {
|
for (String line : templateLines) {
|
||||||
String cleanLine = line.split("#")[0].trim();
|
if (line.trim().isEmpty()) {
|
||||||
if (!cleanLine.isEmpty() && cleanLine.contains(":")) {
|
|
||||||
String key = cleanLine.split(":")[0].trim();
|
|
||||||
if (userEntries.containsKey(key)) {
|
|
||||||
// Always use user's entry if exists
|
|
||||||
mergedLines.add(userEntries.get(key));
|
|
||||||
handledKeys.add(key);
|
|
||||||
} else {
|
|
||||||
// Use template's entry if no user entry
|
|
||||||
mergedLines.add(line);
|
mergedLines.add(line);
|
||||||
}
|
continue;
|
||||||
} else {
|
|
||||||
// Add comments and other lines directly
|
|
||||||
mergedLines.add(line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add user entries not present in the template at the end
|
int indentLevel = getIndentationLevel(line);
|
||||||
for (String key : userEntries.keySet()) {
|
if (indentLevel == 0 || (indentLevel <= blockIndent && !line.trim().startsWith("#"))) {
|
||||||
if (!handledKeys.contains(key)) {
|
currentBlockKey = line.split(":")[0].trim();
|
||||||
mergedLines.add(userEntries.get(key));
|
blockIndent = indentLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userEntries.containsKey(currentBlockKey) && !handledKeys.contains(currentBlockKey)) {
|
||||||
|
mergedLines.add(userEntries.get(currentBlockKey));
|
||||||
|
handledKeys.add(currentBlockKey);
|
||||||
|
} else if (!handledKeys.contains(currentBlockKey)) {
|
||||||
|
mergedLines.add(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,13 +153,13 @@ public class ConfigInitializer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static List<String> cleanInvalidYamlEntries(List<String> lines) {
|
private static List<String> cleanInvalidYamlEntries(List<String> lines) {
|
||||||
List<String> cleanedLines = new ArrayList<>();
|
List<String> cleanedLines = new ArrayList<>();
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
String line = lines.get(i);
|
String line = lines.get(i);
|
||||||
String trimmedLine = line.trim();
|
String trimmedLine = line.trim();
|
||||||
|
|
||||||
// Ignore commented lines and lines that don't look like key-only entries
|
|
||||||
if (trimmedLine.startsWith("#")
|
if (trimmedLine.startsWith("#")
|
||||||
|| !trimmedLine.endsWith(":")
|
|| !trimmedLine.endsWith(":")
|
||||||
|| trimmedLine.contains(" ")) {
|
|| trimmedLine.contains(" ")) {
|
||||||
|
@ -144,10 +167,7 @@ public class ConfigInitializer
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For potential key-only lines, check the next line to determine context
|
|
||||||
if (isKeyWithoutChildrenOrValue(i, lines)) {
|
if (isKeyWithoutChildrenOrValue(i, lines)) {
|
||||||
// Skip adding the current line since it's a key without any following value or
|
|
||||||
// children
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@ system:
|
||||||
showUpdate: true # see when a new update is available
|
showUpdate: true # see when a new update is available
|
||||||
showUpdateOnlyAdmin: false # Only admins can see when a new update is available, depending on showUpdate it must be set to 'true'
|
showUpdateOnlyAdmin: false # Only admins can see when a new update is available, depending on showUpdate it must be set to 'true'
|
||||||
|
|
||||||
#ui:
|
ui:
|
||||||
# appName: exampleAppName # Application's visible name
|
appName: null # Application's visible name
|
||||||
# homeDescription: I am a description # Short description or tagline shown on homepage.
|
homeDescription: null # Short description or tagline shown on homepage.
|
||||||
# appNameNavbar: navbarName # Name displayed on the navigation bar
|
appNameNavbar: null # Name displayed on the navigation bar
|
||||||
|
|
||||||
endpoints:
|
endpoints:
|
||||||
toRemove: [] # List endpoints to disable (e.g. ['img-to-pdf', 'remove-pages'])
|
toRemove: [] # List endpoints to disable (e.g. ['img-to-pdf', 'remove-pages'])
|
||||||
|
|
Loading…
Reference in a new issue