From 6d6d79fcbc92f9f07690939d8b8b745694f880c4 Mon Sep 17 00:00:00 2001
From: ed
Date: Fri, 1 Aug 2025 15:08:55 +0000
Subject: [PATCH] fix upload-abort in shares; closes #347
---
copyparty/httpcli.py | 29 ++++++++++++++++++++++-------
copyparty/up2k.py | 12 ++++++++----
copyparty/web/browser.js | 22 ++++++----------------
3 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py
index f698255a..16f94a11 100644
--- a/copyparty/httpcli.py
+++ b/copyparty/httpcli.py
@@ -5363,6 +5363,7 @@ class HttpCli(object):
else:
shr_dbv = None
+ wret: dict[str, Any] = {}
ret: list[dict[str, Any]] = []
t0 = time.time()
lim = time.time() - self.args.unpost
@@ -5384,7 +5385,13 @@ class HttpCli(object):
x = self.conn.hsrv.broker.ask(
"up2k.get_unfinished_by_user", self.uname, "" if bad_xff else self.ip
)
- uret = x.get()
+ zdsa: dict[str, Any] = x.get()
+ uret: list[dict[str, Any]] = []
+ if "timeout" in zdsa:
+ wret["nou"] = 1
+ else:
+ uret = zdsa["f"]
+ nu = len(uret)
if not self.args.unpost:
allvols = []
@@ -5430,6 +5437,8 @@ class HttpCli(object):
if len(ret) > 2000:
ret = ret[:2000]
+ if len(ret) >= 2000:
+ wret["oc"] = 1
for rv in ret:
rv["vp"] = quotep(rv["vp"])
@@ -5449,6 +5458,13 @@ class HttpCli(object):
)
rv["vp"] += "?k=" + fk[:nfk]
+ if not allvols:
+ wret["noc"] = 1
+ ret = []
+
+ nc = len(ret)
+ ret = uret + ret
+
if shr_dbv:
# translate vpaths from share-target to share-url
# to satisfy access checks
@@ -5463,12 +5479,11 @@ class HttpCli(object):
for v in ret:
v["vp"] = self.args.SR + v["vp"]
- if not allvols:
- ret = [{"kinshi": 1}]
-
- jtxt = '{"u":%s,"c":%s}' % (uret, json.dumps(ret, separators=(",\n", ": ")))
- zi = len(uret.split('\n"pd":')) - 1
- self.log("%s #%d+%d %.2fsec" % (lm, zi, len(ret), time.time() - t0))
+ wret["f"] = ret
+ wret["nu"] = nu
+ wret["nc"] = nc
+ jtxt = json.dumps(wret, separators=(",\n", ": "))
+ self.log("%s #%d+%d %.2fsec" % (lm, nu, nc, time.time() - t0))
self.reply(jtxt.encode("utf-8", "replace"), mime="application/json")
return True
diff --git a/copyparty/up2k.py b/copyparty/up2k.py
index f544d0e3..ea2bbb57 100644
--- a/copyparty/up2k.py
+++ b/copyparty/up2k.py
@@ -399,12 +399,14 @@ class Up2k(object):
return "{}"
- def get_unfinished_by_user(self, uname, ip) -> str:
+ def get_unfinished_by_user(self, uname, ip) -> dict[str, Any]:
+ # returns dict due to ExceptionalQueue
if PY2 or not self.reg_mutex.acquire(timeout=2):
- return '[{"timeout":1}]'
+ return {"timeout":1}
ret: list[tuple[int, str, int, int, int]] = []
userset = set([(uname or "\n"), "*"])
+ n = 1000
try:
for ptop, tab2 in self.registry.items():
cfg = self.flags.get(ptop, {}).get("u2abort", 1)
@@ -419,7 +421,6 @@ class Up2k(object):
or (addr and addr != job["addr"])
):
continue
-
zt5 = (
int(job["t0"]),
djoin(job["vtop"], job["prel"], job["name"]),
@@ -428,6 +429,9 @@ class Up2k(object):
len(job["hash"]),
)
ret.append(zt5)
+ n -= 1
+ if not n:
+ break
finally:
self.reg_mutex.release()
@@ -444,7 +448,7 @@ class Up2k(object):
}
for (at, vp, sz, nn, nh) in ret
]
- return json.dumps(ret2, separators=(",\n", ": "))
+ return {"f": ret2}
def get_unfinished(self) -> str:
if PY2 or not self.reg_mutex.acquire(timeout=0.5):
diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js
index affcbaa7..239800db 100644
--- a/copyparty/web/browser.js
+++ b/copyparty/web/browser.js
@@ -12526,29 +12526,19 @@ var unpost = (function () {
return ebi('op_unpost').innerHTML = '
' + L.badreply + ':
' + unpre(this.responseText); } - if (ores.u.length == 1 && ores.u[0].timeout) { + if (ores.nou) html.push('' + L.un_nou + '
'); - ores.u = []; - } - if (ores.c.length == 1 && ores.c[0].kinshi) { + if (ores.noc) html.push('' + L.un_noc + '
'); - ores.c = []; - } - for (var a = 0; a < ores.u.length; a++) - ores.u[a].k = 'u'; - - for (var a = 0; a < ores.c.length; a++) - ores.c[a].k = 'c'; - - var res = ores.u.concat(ores.c); + var res = ores.f; if (res.length) { - if (res.length == 2000) + if (ores.of) html.push("" + L.un_max); else - html.push("
" + L.un_avail.format(ores.c.length, ores.u.length)); + html.push("
" + L.un_avail.format(ores.nc, ores.nu));
html.push("
" + L.un_m2 + "
time | size | done | file | |
' + (done ? L.un_del : L.un_abrt) + ' | ' + '' + unix2iso(res[a].at) + ' | ' +