From 077cd4e40a116e31c8529e109afd9b20c92d0e87 Mon Sep 17 00:00:00 2001 From: Til Schmitter Date: Fri, 1 May 2026 20:22:27 +0200 Subject: [PATCH] less cursed method for checking for dirs --- copyparty/httpcli.py | 4 +++- copyparty/web/browser.css | 2 +- copyparty/web/browser.js | 24 ++++++++++-------------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 0e6a95ea..37f99834 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -7208,7 +7208,7 @@ class HttpCli(object): and vpath ) for fn in ls_names: - base = "" + cls = base = "" href = fn if use_abs_url: base = "/" + vpath + "/" @@ -7228,6 +7228,7 @@ class HttpCli(object): is_dir = stat.S_ISDIR(inf.st_mode) if is_dir: + cls = "dir" href += "/" if no_zip: margin = "DIR" @@ -7297,6 +7298,7 @@ class HttpCli(object): "ext": ext, "dt": dt, "ts": int(linf.st_mtime), + "cls": cls, } if is_dir: dirs.append(item) diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index fa0036d3..44290e85 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -636,7 +636,7 @@ a:hover { a.dir { color: var(--a); } -tr:has(a.dir) td:nth-child(2) a::before { +tr.dir td:nth-child(2) a::before { content: "📁"; margin: 0 .1em 0 -.2em; } diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index bbdcb83a..cbe7229e 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -6232,10 +6232,6 @@ var thegrid = (function () { if (!ref) continue; var cl = ebi(ref).closest('tr').className || ''; - - if (noq_href(ths[a]).endsWith('/')) - cl += ' dir'; - ths[a].className = cl; var chk = ths[a].getElementsByTagName('input')[0]; @@ -6315,8 +6311,8 @@ var thegrid = (function () { ext0 = '', name = uricom_dec(vsplit(href)[1]), ref = ao.getAttribute('id'), - isdir = href.endsWith('/'), - ac = isdir ? ' class="dir"' : '', + isdir = clgot(ao.parentElement.parentElement, 'dir'), + ac = ao.parentElement.parentElement.classList, ihref = ohref; if (need_ext && href != "#") { @@ -6369,12 +6365,12 @@ var thegrid = (function () { ihref += "&raster"; html.push('' + + '" class="' + ac + '" ttt="' + esc(name) + '">' + '
' + '' + '
' + ao.innerHTML + '
'); + ihref + '" />' + ao.innerHTML + ''); } ggrid.innerHTML = html.join('\n'); clmod(ggrid, 'crop', r.crop); @@ -8306,8 +8302,8 @@ var treectl = (function () { '" rel="nofollow" class="doc' + (lang ? ' bri' : '') + '" hl="' + id + '" name="' + hname + '">-txt-'; - var cl = /\.PARTIAL$/.exec(fname) ? ' class="fade"' : '', - ln = ['' + tn.lead + '' + tn.lead + '' + hname + '' + filesizefun(tn.sz)]; @@ -8808,7 +8804,7 @@ function find_file_col(txt) { function mk_files_header(taglist) { var html = [ '', - 'c', + '!', 'File Name', 'Size' ]; @@ -9999,7 +9995,7 @@ if (sb_lg && logues.length) { var td = tr[a].cells[1], ao = td.firstChild, href = noq_href(ao), - isdir = href.endsWith('/'), + isdir = clgot(tr[a], 'dir'), txt = ao.textContent; td.setAttribute('sortv', (isdir ? '\t' : '') + txt); @@ -10607,7 +10603,7 @@ var drag = (function() { for (var j = 0; j < links.length; j++) links[j].draggable = false; - if (/(zip|DIR)/.test(f.firstChild.innerHTML)) // very cursed but it works + if (clgot(f, 'dir')) r.mktarget(f); } }; @@ -10635,7 +10631,7 @@ var drag = (function() { r.no_warn = false; }; - if (clgot(f, "dir")) + if (clgot(f, 'dir')) r.mktarget(f); } };