mirror of
				https://github.com/9001/copyparty.git
				synced 2025-11-03 21:43:12 +00:00 
			
		
		
		
	fix thumb/ico bugs
This commit is contained in:
		@@ -250,9 +250,9 @@ def run_argparse(argv, formatter):
 | 
				
			|||||||
    ap.add_argument("--salt", type=str, default="hunter2", help="up2k file-hash salt")
 | 
					    ap.add_argument("--salt", type=str, default="hunter2", help="up2k file-hash salt")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ap2 = ap.add_argument_group('thumbnail options')
 | 
					    ap2 = ap.add_argument_group('thumbnail options')
 | 
				
			||||||
    ap.add_argument("--no-thumb", action="store_true", help="disable all thumbnails")
 | 
					    ap2.add_argument("--no-thumb", action="store_true", help="disable all thumbnails")
 | 
				
			||||||
    ap.add_argument("--no-vthumb", action="store_true", help="disable video thumbnails")
 | 
					    ap2.add_argument("--no-vthumb", action="store_true", help="disable video thumbnails")
 | 
				
			||||||
    ap.add_argument("--thumbsz", metavar="WxH", default="352x352", help="thumbnail res")
 | 
					    ap2.add_argument("--thumbsz", metavar="WxH", default="352x352", help="thumbnail res")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ap2 = ap.add_argument_group('database options')
 | 
					    ap2 = ap.add_argument_group('database options')
 | 
				
			||||||
    ap2.add_argument("-e2d", action="store_true", help="enable up2k database")
 | 
					    ap2.add_argument("-e2d", action="store_true", help="enable up2k database")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1208,10 +1208,11 @@ class HttpCli(object):
 | 
				
			|||||||
        return True
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def tx_ico(self, ext):
 | 
					    def tx_ico(self, ext):
 | 
				
			||||||
        n = ext.split(".")[::-1]
 | 
					        bad = re.compile(r"[](){}[]|^[0-9_-]*$")
 | 
				
			||||||
 | 
					        n = ext.split(".")[1:][::-1]
 | 
				
			||||||
        ext = ""
 | 
					        ext = ""
 | 
				
			||||||
        for v in n:
 | 
					        for v in n:
 | 
				
			||||||
            if len(v) > 7:
 | 
					            if len(v) > 7 or bad.match(v):
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ext = "{}.{}".format(v, ext)
 | 
					            ext = "{}.{}".format(v, ext)
 | 
				
			||||||
@@ -1374,9 +1375,6 @@ class HttpCli(object):
 | 
				
			|||||||
            raise Pebkac(404)
 | 
					            raise Pebkac(404)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if self.readable and not stat.S_ISDIR(st.st_mode):
 | 
					        if self.readable and not stat.S_ISDIR(st.st_mode):
 | 
				
			||||||
            if abspath.endswith(".md") and "raw" not in self.uparam:
 | 
					 | 
				
			||||||
                return self.tx_md(abspath)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if rem.startswith(".hist/up2k."):
 | 
					            if rem.startswith(".hist/up2k."):
 | 
				
			||||||
                raise Pebkac(403)
 | 
					                raise Pebkac(403)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1390,6 +1388,9 @@ class HttpCli(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                return self.tx_ico(rem)
 | 
					                return self.tx_ico(rem)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if abspath.endswith(".md") and "raw" not in self.uparam:
 | 
				
			||||||
 | 
					                return self.tx_md(abspath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return self.tx_file(abspath)
 | 
					            return self.tx_file(abspath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        srv_info = []
 | 
					        srv_info = []
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,8 @@
 | 
				
			|||||||
import hashlib
 | 
					import hashlib
 | 
				
			||||||
import colorsys
 | 
					import colorsys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from .__init__ import PY2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Ico(object):
 | 
					class Ico(object):
 | 
				
			||||||
    def __init__(self):
 | 
					    def __init__(self):
 | 
				
			||||||
@@ -9,18 +11,14 @@ class Ico(object):
 | 
				
			|||||||
    def get(self, ext):
 | 
					    def get(self, ext):
 | 
				
			||||||
        """placeholder to make thumbnails not break"""
 | 
					        """placeholder to make thumbnails not break"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if False:
 | 
					 | 
				
			||||||
            h = hashlib.md5(ext.encode("utf-8")).digest()[:6]
 | 
					 | 
				
			||||||
            lo = [int(x / 3) for x in h]
 | 
					 | 
				
			||||||
            hi = [int(x / 3 + 170) for x in h]
 | 
					 | 
				
			||||||
            c = lo[:3] + hi[3:6]
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
        h = hashlib.md5(ext.encode("utf-8")).digest()[:2]
 | 
					        h = hashlib.md5(ext.encode("utf-8")).digest()[:2]
 | 
				
			||||||
 | 
					        if PY2:
 | 
				
			||||||
 | 
					            h = [ord(x) for x in h]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        c1 = colorsys.hsv_to_rgb(h[0] / 256.0, 1, 0.3)
 | 
					        c1 = colorsys.hsv_to_rgb(h[0] / 256.0, 1, 0.3)
 | 
				
			||||||
        c2 = colorsys.hsv_to_rgb(h[0] / 256.0, 1, 1)
 | 
					        c2 = colorsys.hsv_to_rgb(h[0] / 256.0, 1, 1)
 | 
				
			||||||
        c = list(c1) + list(c2)
 | 
					        c = list(c1) + list(c2)
 | 
				
			||||||
        c = [int(x * 255) for x in c]
 | 
					        c = [int(x * 255) for x in c]
 | 
				
			||||||
 | 
					 | 
				
			||||||
        c = "".join(["{:02x}".format(x) for x in c])
 | 
					        c = "".join(["{:02x}".format(x) for x in c])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        svg = """\
 | 
					        svg = """\
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@
 | 
				
			|||||||
from __future__ import print_function, unicode_literals
 | 
					from __future__ import print_function, unicode_literals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
import threading
 | 
					import threading
 | 
				
			||||||
@@ -39,8 +40,13 @@ class SvcHub(object):
 | 
				
			|||||||
        self.tcpsrv = TcpSrv(self)
 | 
					        self.tcpsrv = TcpSrv(self)
 | 
				
			||||||
        self.up2k = Up2k(self)
 | 
					        self.up2k = Up2k(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        enth = HAVE_PIL and not args.no_thumb
 | 
					        self.thumbsrv = None
 | 
				
			||||||
        self.thumbsrv = ThumbSrv(self) if enth else None
 | 
					        if not args.no_thumb:
 | 
				
			||||||
 | 
					            if HAVE_PIL:
 | 
				
			||||||
 | 
					                self.thumbsrv = ThumbSrv(self)
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                msg = "need Pillow to create thumbnails; for example:\n  {} -m pip install --user Pillow"
 | 
				
			||||||
 | 
					                self.log("thumb", msg.format(os.path.basename(sys.executable)), c=3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # decide which worker impl to use
 | 
					        # decide which worker impl to use
 | 
				
			||||||
        if self.check_mp_enable():
 | 
					        if self.check_mp_enable():
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -127,7 +127,7 @@ class ThumbSrv(object):
 | 
				
			|||||||
        with self.mutex:
 | 
					        with self.mutex:
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                self.busy[tpath].append(cond)
 | 
					                self.busy[tpath].append(cond)
 | 
				
			||||||
                self.log("conv {}".format(tpath))
 | 
					                self.log("wait {}".format(tpath))
 | 
				
			||||||
            except:
 | 
					            except:
 | 
				
			||||||
                thdir = os.path.dirname(tpath)
 | 
					                thdir = os.path.dirname(tpath)
 | 
				
			||||||
                try:
 | 
					                try:
 | 
				
			||||||
@@ -142,7 +142,7 @@ class ThumbSrv(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                self.busy[tpath] = [cond]
 | 
					                self.busy[tpath] = [cond]
 | 
				
			||||||
                self.q.put([abspath, tpath])
 | 
					                self.q.put([abspath, tpath])
 | 
				
			||||||
                self.log("CONV {}".format(tpath))
 | 
					                self.log("conv {}".format(tpath))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while not self.stopping:
 | 
					        while not self.stopping:
 | 
				
			||||||
            with self.mutex:
 | 
					            with self.mutex:
 | 
				
			||||||
@@ -198,7 +198,7 @@ class ThumbSrv(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def conv_pil(self, abspath, tpath):
 | 
					    def conv_pil(self, abspath, tpath):
 | 
				
			||||||
        with Image.open(abspath) as im:
 | 
					        with Image.open(abspath) as im:
 | 
				
			||||||
            if im.mode in ("RGBA", "P"):
 | 
					            if im.mode not in ("RGB", "L"):
 | 
				
			||||||
                im = im.convert("RGB")
 | 
					                im = im.convert("RGB")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            im.thumbnail(self.res)
 | 
					            im.thumbnail(self.res)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user