From 40084f07626c0c513c4653bbe9ec9bb8b00f866c Mon Sep 17 00:00:00 2001 From: remittor Date: Thu, 18 Dec 2025 11:30:16 +0300 Subject: [PATCH] luci: Show package version with release number (exclude r1) --- .../resources/view/zapret/service.js | 2 +- .../resources/view/zapret/tools.js | 41 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/service.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/service.js index 6b2d627..07aa45a 100644 --- a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/service.js +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/service.js @@ -400,7 +400,7 @@ return view.extend({ poll.add(L.bind(this.statusPoll, this)); let page_title = _('Zapret'); - let pkgdict = tools.decode_pkg_list(pkg_list.stdout); + let pkgdict = tools.decode_pkg_list(pkg_list.stdout, false); page_title += '   '; if (pkgdict['zapret'] === undefined || pkgdict['zapret'] == '') { page_title += 'unknown version'; diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js index 4c57d0c..1cc5e7e 100644 --- a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js @@ -181,40 +181,49 @@ return baseclass.extend({ return m ? m[2] : defval; }, - decode_pkg_list: function(pkg_list) { + decode_pkg_list: function(pkg_list, with_suffix_r1 = true) { let pkg_dict = { }; + if (!pkg_list) { + return pkg_dict; + } let lines = pkg_list.trim().split('\n'); for (let i = 0; i < lines.length; i++) { let line = lines[i].trim(); let name; let ver; + let rev = -1; if (this.packager.name == 'apk') { let fullname = line.split(' ')[0]; - let mpos = fullname.lastIndexOf("-"); - if (mpos <= 0) - continue; - if (fullname.substring(mpos+1, mpos+2) == 'r') { - // release number - fullname = fullname.substring(0, mpos); + let match = fullname.match(/^(.*)-r(\d+)$/); + if (match) { + fullname = match[1]; + rev = parseInt(match[2], 10); } - mpos = fullname.lastIndexOf("-"); + let mpos = fullname.lastIndexOf('-'); if (mpos <= 0) - continue; - name = fullname.substring(0, mpos).trim(); - ver = fullname.substring(mpos+1).trim(); + continue; // incorrect format + name = fullname.slice(0, mpos).trim(); + ver = fullname.slice(mpos + 1).trim(); } else { if (!line.includes(' - ')) - continue; + continue; // incorrect format name = line.split(' - ')[0].trim(); ver = line.split(' - ')[1].trim(); let spos = ver.indexOf(" "); if (spos > 0) { ver = ver.substring(0, spos); } - let mpos = ver.lastIndexOf("-"); - if (mpos > 0 && ver.substring(mpos+1, mpos+2) == 'r') { - // release number - ver = ver.substring(0, mpos); + let match = ver.match(/^(.*)-r(\d+)$/); + if (match) { + ver = match[1]; + rev = parseInt(match[2], 10); + } + } + if (rev >= 0) { + if (rev == 1 && !with_suffix_r1) { + // nothing + } else { + ver += '-r' + rev; } } pkg_dict[name] = ver;