From 081d2cc5d766437eb80313fe9af45838f42508bc Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 11 Jun 2021 23:54:54 +0200 Subject: [PATCH] add folder thumbnails (cover.jpg or png) --- copyparty/httpcli.py | 21 +++++++++++++++++---- copyparty/web/browser.css | 7 +++++++ copyparty/web/browser.js | 11 ++++++----- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index f50b7e5b..b02ab2e8 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1525,12 +1525,24 @@ class HttpCli(object): except: raise Pebkac(404) - if self.readable and not stat.S_ISDIR(st.st_mode): + if self.readable: if rem.startswith(".hist/up2k."): raise Pebkac(403) + is_dir = stat.S_ISDIR(st.st_mode) th_fmt = self.uparam.get("th") if th_fmt is not None: + if is_dir: + for fn in ["cover.png", "cover.jpg"]: + fp = os.path.join(abspath, fn) + if os.path.exists(fp): + vrem = "{}/{}".format(vrem.rstrip("/"), fn) + is_dir = False + break + + if is_dir: + return self.tx_ico("/") + thp = None if self.thumbcli: thp = self.thumbcli.get( @@ -1542,10 +1554,11 @@ class HttpCli(object): return self.tx_ico(rem) - if abspath.endswith(".md") and "raw" not in self.uparam: - return self.tx_md(abspath) + if not is_dir: + 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 = [] diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index d8e22fa2..6334692e 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -798,6 +798,13 @@ html.light #ghead { padding: .2em .3em; display: block; } +#ggrid span.dir:before { + content: '📂'; + line-height: 0; + font-size: 2em; + display: inline-block; + margin: -.7em 0 -.5em -.3em; +} #ggrid a:hover { background: #444; border-color: #555; diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 80188f6b..c96b5b94 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -858,14 +858,15 @@ var thegrid = (function () { href = esc(ao.getAttribute('href')), ref = ao.getAttribute('id'), isdir = href.split('?')[0].slice(-1)[0] == '/', + ac = isdir ? ' class="dir"' : '', ihref = href; - if (isdir) { - ihref = '/.cpr/ico/folder' - } - else if (r.thumbs) { + if (r.thumbs) { ihref += (ihref.indexOf('?') === -1 ? '?' : '&') + 'th=' + (have_webp ? 'w' : 'j'); } + else if (isdir) { + ihref = '/.cpr/ico/folder'; + } else { var ar = href.split('?')[0].split('.'); if (ar.length > 1) @@ -886,7 +887,7 @@ var thegrid = (function () { } html.push('' + ao.innerHTML + ''); + ihref + '" />' + ao.innerHTML + ''); } lfiles.style.display = 'none'; gfiles.style.display = 'block';