Revise utilities (#28)
* Overhaul of config-editor * Update default card header * Update config-editor.tsx * Update config-editor.tsx * Update config-editor.tsx * Revert "Merge branch 'patch5-temp' into patch-5" This reverts commit538eab6ac6, reversing changes made tob0538f6e3c. * Update config-editor.tsx * Revert "Update config-editor.tsx" This reverts commit68dc70f216. * Update utilities.module.scss * Revert "Update utilities.module.scss" This reverts commitd9d14756d6. * Update dump-viewer.tsx
This commit is contained in:
1 parent
64f38f1b69
commit
b582b92414
2 files changed
+46
-50
No files matched your search
@@ -8,7 +8,8 @@ import { useRef, useState } from 'react';
|
|||||||
const ConfigEditorPage: React.FC = () => {
|
const ConfigEditorPage: React.FC = () => {
|
||||||
const [config, setConfig] = useState('');
|
const [config, setConfig] = useState('');
|
||||||
const [parsedConfig, setParsedConfig] = useState<any>({});
|
const [parsedConfig, setParsedConfig] = useState<any>({});
|
||||||
|
// match optional key
|
||||||
|
const keyReg = /^#? ?[^:\sA-Z]+:(?!\S)/
|
||||||
const editedConfig = useRef<any>({});
|
const editedConfig = useRef<any>({});
|
||||||
const uploadRef = useRef<any>(null);
|
const uploadRef = useRef<any>(null);
|
||||||
|
|
||||||
@@ -55,7 +56,8 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
const newConfig = {};
|
const newConfig = {};
|
||||||
|
|
||||||
// Parse each line of the config
|
// Parse each line of the config
|
||||||
lines.forEach(line => {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
let line = lines[i];
|
||||||
// Reset the section if we are no indented
|
// Reset the section if we are no indented
|
||||||
if (!line.startsWith(' ')) {
|
if (!line.startsWith(' ')) {
|
||||||
currentSection = '';
|
currentSection = '';
|
||||||
@@ -65,80 +67,73 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
line = line.trim()
|
line = line.trim()
|
||||||
if (line === '') {
|
if (line === '') {
|
||||||
currentComment = '';
|
currentComment = '';
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we are in a comment
|
const commented = line.startsWith('#');
|
||||||
if (line.startsWith('#')) {
|
|
||||||
if (!line.includes('# ') && line.includes(': ')) {
|
|
||||||
const splitLine = line.split(':');
|
|
||||||
splitLine[0] = splitLine[0].trim();
|
|
||||||
splitLine[1] = splitLine[1].trim();
|
|
||||||
if (splitLine[0] === '#proxy-protocol-whitelisted-ips') {
|
|
||||||
currentComment = '';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
currentComment += '<strong>Note: This option is commented on, and if you change it, it will be automatically uncommented.</strong>' + '<br>';
|
|
||||||
// Add the config option to the config object
|
|
||||||
newConfig[currentSection] = newConfig[currentSection] || {};
|
|
||||||
newConfig[currentSection][splitLine[0]] = {
|
|
||||||
desc: currentComment,
|
|
||||||
value: splitLine[1]
|
|
||||||
};
|
|
||||||
|
|
||||||
// Reset the comment
|
const match = line.match(keyReg)
|
||||||
currentComment = '';
|
if (match === null) {
|
||||||
return;
|
// Check if we are in a comment
|
||||||
|
if (commented) {
|
||||||
|
currentComment += line.replace(/^# ?/i, '') + '<br>';
|
||||||
}
|
}
|
||||||
currentComment += line.replace(/^# ?/i, '') + '<br>';
|
continue;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore these lines since they will fail to parse
|
// Check if we are in a new section
|
||||||
if (!line.includes(':')) {
|
if (line.endsWith(':')) {
|
||||||
return;
|
currentSection = line.replace(':', '');
|
||||||
|
currentComment = '';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore user auths section
|
||||||
|
if (currentSection === 'saved-user-logins') {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the key and value
|
// Get the key and value
|
||||||
const splitLine = line.split(':');
|
const splitLine = line.split(':');
|
||||||
splitLine[0] = splitLine[0].trim();
|
splitLine[0] = splitLine[0].trim();
|
||||||
splitLine[1] = splitLine[1].trim();
|
let val = '';
|
||||||
|
for (let j = 1;j<splitLine.length;j++) {
|
||||||
|
val += splitLine[j];
|
||||||
|
}
|
||||||
|
val = val.trim();
|
||||||
|
|
||||||
// Check if we are in a new section
|
if (splitLine[0].includes('proxy-protocol-whitelisted-ips')) {
|
||||||
if (line.endsWith(':')) {
|
|
||||||
currentSection = splitLine[0];
|
|
||||||
currentComment = '';
|
currentComment = '';
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore user auths section
|
if (commented) {
|
||||||
if (currentSection === 'saved-user-logins') {
|
currentComment += '<strong>Note: This option is commented on, and if you change it, it will be automatically uncommented.</strong>' + '<br>';
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the config option to the config object
|
// Add the config option to the config object
|
||||||
newConfig[currentSection] = newConfig[currentSection] || {};
|
newConfig[currentSection] = newConfig[currentSection] || {};
|
||||||
newConfig[currentSection][splitLine[0]] = {
|
newConfig[currentSection][splitLine[0]] = {
|
||||||
desc: currentComment,
|
desc: currentComment,
|
||||||
value: splitLine[1]
|
value: val,
|
||||||
|
line: i
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reset the comment
|
// Reset the comment
|
||||||
currentComment = '';
|
currentComment = '';
|
||||||
})
|
}
|
||||||
|
|
||||||
return newConfig;
|
return newConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
const generateHTML = (config: any) => {
|
const generateHTML = (config: any) => {
|
||||||
return Object.keys(config).map(configKey => (
|
return Object.keys(config).map(configKey => (
|
||||||
<div key={configKey} className={styles.card}>
|
<div key={configKey} className={styles.card}>
|
||||||
<div className={styles.cardHeader}>{configKey === '' ? '.' : configKey}</div>
|
<div className={styles.cardHeader}>{configKey === '' ? 'Root' : configKey}</div>
|
||||||
<div className={styles.cardBody}>
|
<div className={styles.cardBody}>
|
||||||
{Object.keys(config[configKey]).map(configOption => {
|
{Object.keys(config[configKey]).map(configOption => {
|
||||||
const configOptionInfo = config[configKey][configOption];
|
const configOptionInfo = config[configKey][configOption];
|
||||||
const configOptionKey = configKey === '' ? configOption : `${configKey}.${configOption}`;
|
const configOptionKey = configKey === '' ? configOption : `${configKey}.${configOption}`;
|
||||||
const showOptionName = configOption.replace('#','')
|
const showOptionName = configOption.replace('#','').trim()
|
||||||
return (
|
return (
|
||||||
<div key={configOptionKey} className={styles.configOption}>
|
<div key={configOptionKey} className={styles.configOption}>
|
||||||
<h3>{showOptionName}</h3>
|
<h3>{showOptionName}</h3>
|
||||||
@@ -154,7 +149,7 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
|
|
||||||
const handleExport = () => {
|
const handleExport = () => {
|
||||||
let newConfig = config;
|
let newConfig = config;
|
||||||
|
const lines = newConfig.split('\n');
|
||||||
Object.entries(editedConfig.current).forEach(([key, value]) => {
|
Object.entries(editedConfig.current).forEach(([key, value]) => {
|
||||||
const keys = key.split('.');
|
const keys = key.split('.');
|
||||||
let currentObj = parsedConfig;
|
let currentObj = parsedConfig;
|
||||||
@@ -162,19 +157,18 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
keys.forEach((nestedKey, index) => {
|
keys.forEach((nestedKey, index) => {
|
||||||
if (currentObj.hasOwnProperty(nestedKey)) {
|
if (currentObj.hasOwnProperty(nestedKey)) {
|
||||||
if (index === keys.length - 1) {
|
if (index === keys.length - 1) {
|
||||||
const oldValue = currentObj[nestedKey].value;
|
const option = currentObj[nestedKey];
|
||||||
if (nestedKey.startsWith('#')) {
|
const oldValue = option.value;
|
||||||
const newKey = nestedKey.replace('#','');
|
const index = option.line;
|
||||||
newConfig = newConfig.replace(` ${nestedKey}: ${oldValue}`, ` ${newKey}: ${value}`);
|
const newKey = nestedKey.replace('#','').trim();
|
||||||
} else {
|
lines[index] = lines[index].replace(` ${nestedKey}: ${oldValue}`,` ${newKey}: ${value}`);
|
||||||
newConfig = newConfig.replace(` ${nestedKey}: ${oldValue}`, ` ${nestedKey}: ${value}`);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
currentObj = currentObj[nestedKey];
|
currentObj = currentObj[nestedKey];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
newConfig = lines.join('\n');
|
||||||
|
|
||||||
// Trigger a download of the final config
|
// Trigger a download of the final config
|
||||||
downloadString(newConfig, 'text/plain', 'config.yml');
|
downloadString(newConfig, 'text/plain', 'config.yml');
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ const DumpViewerPage: React.FC = () => {
|
|||||||
|
|
||||||
const pluginPopoverRef = useRef<any>(null);
|
const pluginPopoverRef = useRef<any>(null);
|
||||||
|
|
||||||
|
const urlReg = /^(https?:\/\/)?dump\.geysermc\.org/;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleClickOutside = (event) => setActivePlugin({});
|
const handleClickOutside = (event) => setActivePlugin({});
|
||||||
document.addEventListener("mousedown", handleClickOutside);
|
document.addEventListener("mousedown", handleClickOutside);
|
||||||
@@ -44,7 +46,7 @@ const DumpViewerPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
let id = dumpId;
|
let id = dumpId;
|
||||||
|
|
||||||
if (dumpId.startsWith('https://dump.geysermc.org/')) {
|
if (dumpId.match(urlReg)) {
|
||||||
id = dumpId.split('/').pop();
|
id = dumpId.split('/').pop();
|
||||||
}
|
}
|
||||||
setDumpId(id);
|
setDumpId(id);
|
||||||
|
|||||||
Reference in new issue
Block a user