From 9b7f933b785d55c0b76f44e627681cac4aa5ee25 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 4 Oct 2025 10:45:17 +0000 Subject: [PATCH] optimize --name-url (#884) --- copyparty/__main__.py | 1 + copyparty/httpcli.py | 6 +----- copyparty/svchub.py | 8 ++++++++ copyparty/web/browser.html | 1 - copyparty/web/browser.js | 2 ++ 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 07fd937d..68ae5c0d 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1156,6 +1156,7 @@ def add_general(ap, nc, srvname): ap2.add_argument("--wintitle", metavar="TXT", type=u, default="cpp @ $pub", help="server terminal title, for example [\033[32m$ip-10.1.2.\033[0m] or [\033[32m$ip-]") ap2.add_argument("--name", metavar="TXT", type=u, default=srvname, help="server name (displayed topleft in browser and in mDNS)") ap2.add_argument("--name-url", metavar="TXT", type=u, help="URL for server name hyperlink (displayed topleft in browser)") + ap2.add_argument("--name-html", type=u, help=argparse.SUPPRESS) ap2.add_argument("--mime", metavar="EXT=MIME", type=u, action="append", help="\033[34mREPEATABLE:\033[0m map file \033[33mEXT\033[0mension to \033[33mMIME\033[0mtype, for example [\033[32mjpg=image/jpeg\033[0m]") ap2.add_argument("--mimes", action="store_true", help="list default mimetype mapping and exit") ap2.add_argument("--rmagic", action="store_true", help="do expensive analysis to improve accuracy of returned mimetypes; will make file-downloads, rss, and webdav slower (volflag=rmagic)") diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index d48ab77a..77778547 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -6493,11 +6493,7 @@ class HttpCli(object): try: if not self.args.nih: - if self.args.name_url: - url = html_escape(self.args.name_url, True, True) - srv_info.append(f"{self.args.name}") - else: - srv_info.append(self.args.name) + srv_info.append(self.args.name_html) except: self.log("#wow #whoa") diff --git a/copyparty/svchub.py b/copyparty/svchub.py index 46261e22..3efe5d24 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -67,6 +67,7 @@ from .util import ( build_netmap, expat_ver, gzip, + html_escape, load_ipr, load_ipu, lock_file, @@ -1171,6 +1172,13 @@ class SvcHub(object): if len(al.tcolor) == 3: # fc5 => ffcc55 al.tcolor = "".join([x * 2 for x in al.tcolor]) + if self.args.name_url: + zs = html_escape(self.args.name_url, True, True) + zs = '%s' % (zs, self.args.name) + else: + zs = self.args.name + self.args.name_html = zs + zs = al.u2sz zsl = [x.strip() for x in zs.split(",")] if len(zsl) not in (1, 3): diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index ebf41f8e..2201ab58 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -134,7 +134,6 @@ CGV = {{ cgv|tojson }}, TS = "{{ ts }}", dtheme = "{{ dtheme }}", - srvinf = "{{ srv_info }}", lang = "{{ lang }}", dfavico = "{{ favico }}", have_tags_idx = {{ have_tags_idx }}, diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 82daa1ea..1f584e98 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -13093,6 +13093,7 @@ var ACtx = !IPHONE && (window.AudioContext || window.webkitAudioContext), abrt_key = "", can_shr = false, rtt = null, + srvinf = "", ldks = [], dks = {}, dk, mp; @@ -19336,6 +19337,7 @@ var treectl = (function () { r.hydrate = function () { qsr('#bbsw'); + srvinf = ebi('srv_info').innerHTML.slice(6, -7); if (ls0 === null) { var xhr = new XHR(); xhr.open('GET', SR + '/?setck=js=y', true);