From 3a69062a82a4b9cc30d3408cbf03f9fb19f60033 Mon Sep 17 00:00:00 2001 From: Carson Coder Date: Mon, 13 Oct 2025 20:52:31 -0400 Subject: [PATCH] Add the ability for on message hooks to see selected files --- copyparty/httpcli.py | 17 ++++++++++++++--- copyparty/util.py | 5 ++++- copyparty/web/browser.js | 6 +++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 9020db3a..dfa8b69b 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -2146,8 +2146,18 @@ class HttpCli(object): try: zb = unquote(buf.replace(b"+", b" ")) plain = zb.decode("utf-8", "replace") - if buf.startswith(b"msg="): - plain = plain[4:] + _msg_data = plain.split("&") + msg_data = {} + for i in _msg_data: + d = i.split("=") + if d[0] in msg_data.keys(): + if type(msg_data[d[0]]) is list: + msg_data[d[0]].append("=".join(d[1:])) + else: + msg_data[d[0]] = [msg_data[d[0]], "=".join(d[1:])] + else: + msg_data[d[0]] = "=".join(d[1:]) + if "msg" in msg_data.keys(): xm = self.vn.flags.get("xm") if xm: xm_rsp = runhook( @@ -2165,7 +2175,8 @@ class HttpCli(object): len(buf), self.ip, time.time(), - plain, + msg_data["msg"], + {"sel": [self.vn.canonical(i) for i in msg_data.get("sel", [])]} ) t = "urlform_dec %d @ %r\n %r\n" diff --git a/copyparty/util.py b/copyparty/util.py index 4f026a56..5cbf9f71 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -3886,6 +3886,7 @@ def _runhook( ip: str, at: float, txt: str, + other: dict ) -> dict[str, Any]: ret = {"rc": 0} areq, chk, imp, fork, sin, jtxt, wait, sp_ka, acmd = _parsehook(log, cmd) @@ -3910,6 +3911,7 @@ def _runhook( "src": src, "txt": txt, } + ja.update(other) if imp: ja["log"] = log mod = loadpy(acmd[0], False) @@ -3980,6 +3982,7 @@ def runhook( ip: str, at: float, txt: str, + other: dict, ) -> dict[str, Any]: assert broker or up2k # !rm args = (broker or up2k).args # type: ignore @@ -3989,7 +3992,7 @@ def runhook( for cmd in cmds: try: hr = _runhook( - log, verbose, src, cmd, ap, vp, host, uname, perms, mt, sz, ip, at, txt + log, verbose, src, cmd, ap, vp, host, uname, perms, mt, sz, ip, at, txt, other ) if verbose and log: log("hook(%s) %r => \033[32m%s" % (src, cmd, hr), 6) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 74fcdac5..0961c96f 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -8622,8 +8622,12 @@ var msel = (function () { xhr.setRequestHeader('Content-Type', ct); if (xhr.overrideMimeType) xhr.overrideMimeType('Content-Type', ct); + let selected = msel.getsel() + for (let i=0;i