mirror of
https://github.com/9001/copyparty.git
synced 2026-06-21 13:42:29 -06:00
re-enable custom thumbnails for special folders
This commit is contained in:
parent
5b96ecaecc
commit
a479d0ec0e
|
|
@ -5282,11 +5282,10 @@ class HttpCli(object):
|
||||||
# chrome cannot handle more than ~2000 unique SVGs
|
# chrome cannot handle more than ~2000 unique SVGs
|
||||||
# so url-param "raster" returns a png/webp instead
|
# so url-param "raster" returns a png/webp instead
|
||||||
# (useragent-sniffing kinshi due to caching proxies)
|
# (useragent-sniffing kinshi due to caching proxies)
|
||||||
# mime, ico = self.conn.hsrv.ico.get(txt, not small, "raster" in self.uparam, self.uparam.get('a'))
|
mime, ico = self.conn.hsrv.ico.get(txt, not small, "raster" in self.uparam, self.uparam.get('a'))
|
||||||
|
|
||||||
lm = formatdate(self.E.t0)
|
lm = formatdate(self.E.t0)
|
||||||
# self.reply(ico, mime=mime, headers={"Last-Modified": lm})
|
self.reply(ico, mime=mime, headers={"Last-Modified": lm})
|
||||||
self.reply('', headers={"Last-Modified": lm})
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def tx_qr(self):
|
def tx_qr(self):
|
||||||
|
|
@ -6852,7 +6851,7 @@ class HttpCli(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if is_dir:
|
if is_dir:
|
||||||
return self.tx_svg("folder")
|
return '' # self.tx_svg("folder")
|
||||||
|
|
||||||
thp = None
|
thp = None
|
||||||
if self.thumbcli and not nothumb:
|
if self.thumbcli and not nothumb:
|
||||||
|
|
@ -6872,7 +6871,7 @@ class HttpCli(object):
|
||||||
elif th_fmt in ACODE2_FMT:
|
elif th_fmt in ACODE2_FMT:
|
||||||
raise Pebkac(415)
|
raise Pebkac(415)
|
||||||
|
|
||||||
return self.tx_ico(rem)
|
return '' # self.tx_ico(rem)
|
||||||
|
|
||||||
elif self.can_write and th_fmt is not None:
|
elif self.can_write and th_fmt is not None:
|
||||||
return self.tx_svg("upload\nonly")
|
return self.tx_svg("upload\nonly")
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,7 @@ class Ico(object):
|
||||||
|
|
||||||
bext = ext.encode("ascii", "replace")
|
bext = ext.encode("ascii", "replace")
|
||||||
ext = bext.decode("utf-8")
|
ext = bext.decode("utf-8")
|
||||||
zb = hashlib.sha1(bext).digest()[2:4]
|
|
||||||
if PY2:
|
|
||||||
zb = [ord(x) for x in zb] # type: ignore
|
|
||||||
|
|
||||||
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])
|
|
||||||
|
|
||||||
w = 100
|
w = 100
|
||||||
h = 30
|
h = 30
|
||||||
if as_thumb:
|
if as_thumb:
|
||||||
|
|
@ -48,11 +40,11 @@ class Ico(object):
|
||||||
|
|
||||||
h = int(128.0 * h / w)
|
h = int(128.0 * h / w)
|
||||||
w = 128
|
w = 128
|
||||||
img = Image.new("RGBA", (w, h), "#" + c[:6] + 'aa')
|
img = Image.new("RGBA", (w, h), "#00000000")
|
||||||
pb = ImageDraw.Draw(img)
|
pb = ImageDraw.Draw(img)
|
||||||
_, _, tw, th = pb.textbbox((0, 0), ext2, font_size=16)
|
_, _, tw, th = pb.textbbox((0, 0), ext2, font_size=16)
|
||||||
xy = (int((w - tw) / 2), int((h - th) / 2))
|
xy = (int((w - tw) / 2), int((h - th) / 2))
|
||||||
pb.text(xy, ext2, fill="#" + c[6:], font_size=16)
|
pb.text(xy, ext2, fill=accent, font_size=16)
|
||||||
|
|
||||||
img = img.resize((w * 2, h * 2), Image.NEAREST)
|
img = img.resize((w * 2, h * 2), Image.NEAREST)
|
||||||
|
|
||||||
|
|
@ -69,7 +61,7 @@ class Ico(object):
|
||||||
|
|
||||||
h = int(64.0 * h / w)
|
h = int(64.0 * h / w)
|
||||||
w = 64
|
w = 64
|
||||||
img = Image.new("RGBA", (w, h), "#" + c[:6] + 'aa')
|
img = Image.new("RGBA", (w, h), "#00000000")
|
||||||
pb = ImageDraw.Draw(img)
|
pb = ImageDraw.Draw(img)
|
||||||
try:
|
try:
|
||||||
_, _, tw, th = pb.textbbox((0, 0), ext)
|
_, _, tw, th = pb.textbbox((0, 0), ext)
|
||||||
|
|
@ -79,7 +71,7 @@ class Ico(object):
|
||||||
tw += len(ext)
|
tw += len(ext)
|
||||||
cw = tw // len(ext)
|
cw = tw // len(ext)
|
||||||
x = ((w - tw) // 2) - (cw * 2) // 3
|
x = ((w - tw) // 2) - (cw * 2) // 3
|
||||||
fill = "#" + c[6:]
|
fill = accent
|
||||||
for ch in ext:
|
for ch in ext:
|
||||||
pb.text((x, (h - th) // 2), " %s " % (ch,), fill=fill)
|
pb.text((x, (h - th) // 2), " %s " % (ch,), fill=fill)
|
||||||
x += cw
|
x += cw
|
||||||
|
|
@ -90,14 +82,14 @@ class Ico(object):
|
||||||
img.save(buf, format="PNG", compress_level=1)
|
img.save(buf, format="PNG", compress_level=1)
|
||||||
return "image/png", buf.getvalue()
|
return "image/png", buf.getvalue()
|
||||||
|
|
||||||
# svg = """\
|
svg = """\
|
||||||
# <?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
# <svg version="1.1" viewBox="0 0 100 {}" xmlns="http://www.w3.org/2000/svg"><g>
|
<svg version="1.1" viewBox="0 0 100 {}" xmlns="http://www.w3.org/2000/svg"><g>
|
||||||
# <rect width="100%" height="100%" fill="#{}" />
|
<rect width="100%" height="100%" fill="#0000" />
|
||||||
# <text x="50%" y="{}" dominant-baseline="middle" text-anchor="middle" xml:space="preserve"
|
<text x="50%" y="{}" dominant-baseline="middle" text-anchor="middle" xml:space="preserve"
|
||||||
# fill="#{}" font-family="monospace" font-size="14px" style="letter-spacing:.5px">{}</text>
|
fill="{}" font-family="monospace" font-size="14px" style="letter-spacing:.5px">{}</text>
|
||||||
# </g></svg>
|
</g></svg>
|
||||||
# """
|
"""
|
||||||
|
|
||||||
txt = html_escape(ext, True)
|
txt = html_escape(ext, True)
|
||||||
if "\n" in txt:
|
if "\n" in txt:
|
||||||
|
|
@ -107,52 +99,8 @@ class Ico(object):
|
||||||
zs = '<tspan x="50%%" dy="1.2em">%s</tspan>'
|
zs = '<tspan x="50%%" dy="1.2em">%s</tspan>'
|
||||||
txt = "".join([zs % (x,) for x in lines])
|
txt = "".join([zs % (x,) for x in lines])
|
||||||
else:
|
else:
|
||||||
y = "55%"
|
y = "50%"
|
||||||
|
|
||||||
#svg = svg.format(h, c[:6], y, c[6:], txt)
|
svg = svg.format(h, y, accent, txt)
|
||||||
|
|
||||||
if(len(ext) > 3):
|
|
||||||
fontsz = 12 / len(ext) * 3
|
|
||||||
else:
|
|
||||||
fontsz = 12
|
|
||||||
|
|
||||||
svg = """\
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg
|
|
||||||
viewBox="0 0 48 48"
|
|
||||||
version="1.1"
|
|
||||||
xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path
|
|
||||||
fill="#{}aa"
|
|
||||||
d="m 28.22643,3.6905246 0.0063,10.1096644 a 1.6331061,1.6331061 44.698111 0 0 1.649296,1.632007 l 9.339558,-0.09259 z"/>
|
|
||||||
<path
|
|
||||||
class="a"
|
|
||||||
d="M39.5,15.5h-9a2,2,0,0,1-2-2v-9h-18a2,2,0,0,0-2,2v35a2,2,0,0,0,2,2h27a2,2,0,0,0,2-2Z"
|
|
||||||
id="path1"
|
|
||||||
stroke-width="1" fill="none" stroke="{}" stroke-linecap="round" stroke-linejoin="round" />
|
|
||||||
<line
|
|
||||||
class="a"
|
|
||||||
x1="28.5"
|
|
||||||
y1="4.5"
|
|
||||||
x2="39.5"
|
|
||||||
y2="15.5"
|
|
||||||
stroke-width="1" fill="none" stroke="{}" stroke-linecap="round" stroke-linejoin="round" />
|
|
||||||
<text
|
|
||||||
font-size="{}px" dominant-baseline="middle" text-anchor="middle" xml:space="preserve"
|
|
||||||
fill="{}" font-family="monospace" style="letter-spacing:.5px"
|
|
||||||
x="50%" y="{}">{}</text>
|
|
||||||
</svg>
|
|
||||||
"""
|
|
||||||
svg = svg.format(c[:6], accent, accent, fontsz, accent, y, txt)
|
|
||||||
|
|
||||||
if(txt == 'folder'):
|
|
||||||
svg = """\
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg version="1.1" width="100%" height="100%" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M3 7C3 5.89543 3.89543 5 5 5L8.67157 5C9.20201 5 9.71071 5.21071 10.0858 5.58579L10.9142 6.41421C11.2893 6.78929 11.798 7 12.3284 7H19C20.1046 7 21 7.89543 21 9V17C21 18.1046 20.1046 19 19 19H5C3.89543 19 3 18.1046 3 17V7Z"
|
|
||||||
fill="{}"/>
|
|
||||||
</svg>
|
|
||||||
"""
|
|
||||||
svg = svg.format(accent)
|
|
||||||
|
|
||||||
return "image/svg+xml", svg.encode("utf-8")
|
return "image/svg+xml", svg.encode("utf-8")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue