From f0406ab472e13a1ef760fb55919f4a7aad12955f Mon Sep 17 00:00:00 2001 From: Til Schmitter Date: Fri, 8 May 2026 01:08:46 +0200 Subject: [PATCH] new placeholder thumbnail generation --- copyparty/httpcli.py | 2 +- copyparty/ico.py | 65 ++++++++++++++++++++++++++++++++------- copyparty/web/browser.css | 1 + copyparty/web/browser.js | 3 ++ 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 156c2ef6..14338280 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -5282,7 +5282,7 @@ class HttpCli(object): # chrome cannot handle more than ~2000 unique SVGs # so url-param "raster" returns a png/webp instead # (useragent-sniffing kinshi due to caching proxies) - mime, ico = self.conn.hsrv.ico.get(txt, not small, "raster" in self.uparam) + mime, ico = self.conn.hsrv.ico.get(txt, not small, "raster" in self.uparam, self.uparam.get('a')) lm = formatdate(self.E.t0) self.reply(ico, mime=mime, headers={"Last-Modified": lm}) diff --git a/copyparty/ico.py b/copyparty/ico.py index 15341134..021a2c4a 100644 --- a/copyparty/ico.py +++ b/copyparty/ico.py @@ -15,7 +15,7 @@ class Ico(object): def __init__(self, args: argparse.Namespace) -> None: self.args = args - def get(self, ext: str, as_thumb: bool, chrome: bool) -> tuple[str, bytes]: + def get(self, ext: str, as_thumb: bool, chrome: bool, accent: str) -> tuple[str, bytes]: """placeholder to make thumbnails not break""" bext = ext.encode("ascii", "replace") @@ -24,7 +24,7 @@ class Ico(object): if PY2: zb = [ord(x) for x in zb] # type: ignore - c1 = colorsys.hsv_to_rgb(zb[0] / 256.0, 1, 0.3) + c1 = colorsys.hsv_to_rgb(zb[0] / 256.0, 1, 1) c2 = colorsys.hsv_to_rgb(zb[0] / 256.0, 0.5 if HAVE_PILF else 1, 0.9) ci = [int(x * 255) for x in list(c1) + list(c2)] c = "".join(["%02x" % (x,) for x in ci]) @@ -90,14 +90,14 @@ class Ico(object): img.save(buf, format="PNG", compress_level=1) return "image/png", buf.getvalue() - svg = """\ - - - -{} - -""" +# svg = """\ +# +# +# +# {} +# +# """ txt = html_escape(ext, True) if "\n" in txt: @@ -107,8 +107,51 @@ class Ico(object): zs = '%s' txt = "".join([zs % (x,) for x in lines]) else: - y = "50%" + y = "55%" svg = svg.format(h, c[:6], y, c[6:], txt) + if(len(ext) > 3): + fontsz = 12 / len(ext) * 3 + else: + fontsz = 12 + + svg = """\ + + + + + + {} + +""" + svg = svg.format(c[:6], accent, accent, fontsz, accent, y, txt) + + if(txt == 'folder'): + svg = """\ + + + + +""" + svg = svg.format(accent) + return "image/svg+xml", svg.encode("utf-8") diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index c708bb6b..7cbdf72f 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -956,6 +956,7 @@ tr.play td:nth-child(1) a { } #ggrid>a img { z-index: 1; + background: var(--bg); border-radius: 5px; border-radius: calc(var(--radius) / 3 * 2); max-width: 10em; diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 7f2e2feb..f6004c1b 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -6447,6 +6447,9 @@ var thegrid = (function () { if (CHROME) ihref += "&raster"; + var accent = getComputedStyle(document.body).getPropertyValue('--a'); + ihref += '&a=' + accent; + html.push('' + '
' +