diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 8f034c99..f59b390f 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1144,6 +1144,7 @@ def add_ui(ap, retry): ap2.add_argument("--lang", metavar="LANG", type=u, default="eng", help="language; one of the following: eng nor") ap2.add_argument("--theme", metavar="NUM", type=int, default=0, help="default theme to use") ap2.add_argument("--themes", metavar="NUM", type=int, default=8, help="number of themes installed") + ap2.add_argument("--sort", metavar="C,C,C", type=u, default="href", help="default sort order, comma-separated column IDs (see header tooltips), prefix with '-' for descending. Examples: \033[32mhref -href ext sz ts tags/Album tags/.tn\033[0m (volflag=sort)") ap2.add_argument("--unlist", metavar="REGEX", type=u, default="", help="don't show files matching REGEX in file list. Purely cosmetic! Does not affect API calls, just the browser. Example: [\033[32m\\.(js|css)$\033[0m] (volflag=unlist)") ap2.add_argument("--favico", metavar="TXT", type=u, default="c 000 none" if retry else "🎉 000 none", help="\033[33mfavicon-text\033[0m [ \033[33mforeground\033[0m [ \033[33mbackground\033[0m ] ], set blank to disable") ap2.add_argument("--mpmc", metavar="URL", type=u, default="", help="change the mediaplayer-toggle mouse cursor; URL to a folder with {2..5}.png inside (or disable with [\033[32m.\033[0m])") diff --git a/copyparty/cfg.py b/copyparty/cfg.py index 7fde3c6c..53b3c318 100644 --- a/copyparty/cfg.py +++ b/copyparty/cfg.py @@ -42,7 +42,7 @@ def vf_bmap() -> dict[str, str]: def vf_vmap() -> dict[str, str]: """argv-to-volflag: simple values""" ret = {"th_convt": "convt", "th_size": "thsize"} - for k in ("dbd", "lg_sbf", "md_sbf", "nrand", "unlist"): + for k in ("dbd", "lg_sbf", "md_sbf", "nrand", "sort", "unlist"): ret[k] = k return ret @@ -149,6 +149,7 @@ flagcats = { }, "client and ux": { "grid": "show grid/thumbnails by default", + "sort": "default sort order", "unlist": "dont list files matching REGEX", "html_head=TXT": "includes TXT in the ", "robots": "allows indexing by search engines (default)", diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 2c438168..22ed8d97 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -3833,6 +3833,7 @@ class HttpCli(object): "acct": self.uname, "idx": e2d, "itag": e2t, + "dsort": vf["sort"], "lifetime": vn.flags.get("lifetime") or 0, "frand": bool(vn.flags.get("rand")), "unlist": unlist, @@ -3857,6 +3858,7 @@ class HttpCli(object): "sb_md": "" if "no_sb_md" in vf else (vf.get("md_sbf") or "y"), "readme": readme, "dgrid": "grid" in vf, + "dsort": vf["sort"], "themes": self.args.themes, "turbolvl": self.args.turbo, "idxh": int(self.args.ih), diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index cc6e786e..46683cf6 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -3133,11 +3133,34 @@ function eval_hash() { })(); +function read_dsort(txt) { + try { + var zt = txt.trim().split(/,+/g); + dsort = []; + for (var a = 0; a < zt.length; a++) { + var z = zt[a].trim(), n = 1, t = ""; + if (z.startsWith("-")) { + z = z.slice(1); + n = -1; + } + if (z == "sz" || z.indexOf('/.') + 1) + t = "int"; + + dsort.push([z, n, t]); + } + } + catch (ex) { + toast.warn(10, 'failed to apply default sort order [' + txt + ']:\n' + ex); + } +} +read_dsort(dsort); + + function sortfiles(nodes) { if (!nodes.length) return nodes; - var sopts = jread('fsort', [["href", 1, ""]]), + var sopts = jread('fsort', jcp(dsort)), dir1st = sread('dir1st') !== '0'; try { @@ -5791,6 +5814,8 @@ var treectl = (function () { if (res.files[a].tags === undefined) res.files[a].tags = {}; + read_dsort(res.dsort); + srvinf = res.srvinf; try { ebi('srv_info').innerHTML = ebi('srv_info2').innerHTML = '' + res.srvinf + ''; @@ -6354,6 +6379,7 @@ var filecols = (function () { toh = ths[a].outerHTML, // !ff10 ttv = L.cols[ths[a].textContent]; + ttv = (ttv ? ttv + '$N' : '') + 'ID: ' + th.getAttribute('name') + ''; if (!MOBILE && toh) { th.innerHTML = '
-
' + toh; th.getElementsByTagName('a')[0].onclick = ev_row_tgl; diff --git a/copyparty/web/ui.css b/copyparty/web/ui.css index 74f5fd52..03e0415c 100644 --- a/copyparty/web/ui.css +++ b/copyparty/web/ui.css @@ -15,6 +15,7 @@ html { max-width: min(34em, calc(100% - 7em)); color: #ddd; background: #333; + background: var(--bg-u2); border: 0 solid #777; box-shadow: 0 .2em .5em #111; border-radius: .4em; @@ -159,9 +160,10 @@ html { #modalc code, #tt code { color: #eee; + color: var(--fg-max); background: #444; + background: var(--bg-u5); padding: .1em .3em; - border-top: 1px solid #777; border-radius: .3em; line-height: 1.7em; } @@ -182,8 +184,10 @@ html.y #toast { box-shadow: 0 .3em 1em rgba(0,0,0,0.4); } html.y #tt code { - background: #060; color: #fff; + color: var(--fg-max); + background: #060; + background: var(--bg-u5); } #modalc code { color: #060; diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 51a93828..7d1f2fdb 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -483,7 +483,7 @@ function yscroll() { function showsort(tab) { var v, vn, v1, v2, th = tab.tHead, - sopts = jread('fsort', [["href", 1, ""]]); + sopts = jread('fsort', jcp(dsort)); th && (th = th.rows[0]) && (th = th.cells);