refactor: simplify label fetching and decoding in podkop.js
This commit is contained in:
@@ -53,36 +53,17 @@ function createConfigSection(section, map, network) {
|
|||||||
o.rows = 5;
|
o.rows = 5;
|
||||||
o.ucisection = s.section;
|
o.ucisection = s.section;
|
||||||
o.load = function (section_id) {
|
o.load = function (section_id) {
|
||||||
return new Promise((resolve, reject) => {
|
return fs.exec('/etc/init.d/podkop', ['get_proxy_label', section_id]).then(res => {
|
||||||
const timeout = setTimeout(() => {
|
if (res.stdout) {
|
||||||
console.error('Label fetch timeout');
|
try {
|
||||||
resolve(this.super('load', section_id));
|
const decodedLabel = decodeURIComponent(res.stdout.trim());
|
||||||
}, 5000); // 5 second timeout
|
this.description = _('Current config: ') + decodedLabel;
|
||||||
|
} catch (e) {
|
||||||
fs.exec('/etc/init.d/podkop', ['get_proxy_label', section_id])
|
console.error('Error decoding label:', e);
|
||||||
.then(res => {
|
this.description = _('Current config: ') + res.stdout.trim();
|
||||||
clearTimeout(timeout);
|
}
|
||||||
if (res.stdout) {
|
}
|
||||||
try {
|
return this.super('load', section_id);
|
||||||
const chunks = res.stdout.trim().split('\n');
|
|
||||||
const fullLabel = chunks.join('');
|
|
||||||
const decodedLabel = decodeURIComponent(fullLabel);
|
|
||||||
this.description = _('Current config: ') + decodedLabel;
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error processing label:', e);
|
|
||||||
// If decoding fails, try to display the raw chunks
|
|
||||||
const chunks = res.stdout.trim().split('\n');
|
|
||||||
const fullLabel = chunks.join('');
|
|
||||||
this.description = _('Current config: ') + fullLabel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resolve(this.super('load', section_id));
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
console.error('Error fetching label:', error);
|
|
||||||
resolve(this.super('load', section_id));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
o.validate = function (section_id, value) {
|
o.validate = function (section_id, value) {
|
||||||
|
|||||||
@@ -1840,19 +1840,11 @@ get_proxy_label() {
|
|||||||
local section="$1"
|
local section="$1"
|
||||||
local proxy_string
|
local proxy_string
|
||||||
local label=""
|
local label=""
|
||||||
local chunk_size=50
|
|
||||||
local start=0
|
|
||||||
|
|
||||||
config_get proxy_string "$section" "proxy_string"
|
config_get proxy_string "$section" "proxy_string"
|
||||||
if [ -n "$proxy_string" ]; then
|
if [ -n "$proxy_string" ]; then
|
||||||
label=$(echo "$proxy_string" | sed -n 's/.*#\(.*\)$/\1/p')
|
label=$(echo "$proxy_string" | sed -n 's/.*#\(.*\)$/\1/p')
|
||||||
if [ -n "$label" ]; then
|
echo "$label"
|
||||||
# Split label into chunks and output one at a time
|
|
||||||
while [ $start -lt ${#label} ]; do
|
|
||||||
echo "${label:$start:$chunk_size}"
|
|
||||||
start=$((start + chunk_size))
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user