From 25107a04813b122a86041056baee4a679d528d6d Mon Sep 17 00:00:00 2001 From: Ivan K Date: Sat, 22 Feb 2025 09:52:04 +0300 Subject: [PATCH] refactor: simplify label fetching and decoding in podkop.js --- .../resources/view/podkop/podkop.js | 41 +++++-------------- podkop/files/etc/init.d/podkop | 10 +---- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js index 0952646..3a71052 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js @@ -53,36 +53,17 @@ function createConfigSection(section, map, network) { o.rows = 5; o.ucisection = s.section; o.load = function (section_id) { - return new Promise((resolve, reject) => { - const timeout = setTimeout(() => { - console.error('Label fetch timeout'); - resolve(this.super('load', section_id)); - }, 5000); // 5 second timeout - - fs.exec('/etc/init.d/podkop', ['get_proxy_label', section_id]) - .then(res => { - clearTimeout(timeout); - if (res.stdout) { - try { - 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)); - }); + return fs.exec('/etc/init.d/podkop', ['get_proxy_label', section_id]).then(res => { + if (res.stdout) { + try { + const decodedLabel = decodeURIComponent(res.stdout.trim()); + this.description = _('Current config: ') + decodedLabel; + } catch (e) { + console.error('Error decoding label:', e); + this.description = _('Current config: ') + res.stdout.trim(); + } + } + return this.super('load', section_id); }); }; o.validate = function (section_id, value) { diff --git a/podkop/files/etc/init.d/podkop b/podkop/files/etc/init.d/podkop index f2edc9b..37e87ed 100755 --- a/podkop/files/etc/init.d/podkop +++ b/podkop/files/etc/init.d/podkop @@ -1840,19 +1840,11 @@ get_proxy_label() { local section="$1" local proxy_string local label="" - local chunk_size=50 - local start=0 config_get proxy_string "$section" "proxy_string" if [ -n "$proxy_string" ]; then label=$(echo "$proxy_string" | sed -n 's/.*#\(.*\)$/\1/p') - if [ -n "$label" ]; then - # 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 + echo "$label" fi }