up2k-ui: button to randomize upload filenames

This commit is contained in:
ed 2023-02-01 22:26:18 +00:00
parent 1e20eafbe0
commit a918c285bf
3 changed files with 28 additions and 4 deletions

View file

@ -2092,7 +2092,16 @@ class Up2k(object):
)
alts.append((score, -len(alts), j))
job = sorted(alts, reverse=True)[0][2] if alts else None
if alts:
best = sorted(alts, reverse=True)[0]
job = best[2]
if best[0] == 5 and vfs.flags.get("rand") or cj.get("rand"):
# filenames are randomized; found dupe in same folder;
# perfect! return the original file
cj["name"] = job["name"]
else:
job = None
if job and wark in reg:
# self.log("pop " + wark + " " + job["name"] + " handle_json db", 4)
del reg[wark]
@ -2167,7 +2176,13 @@ class Up2k(object):
job[k] = cj[k]
pdir = djoin(cj["ptop"], cj["prel"])
if vfs.flags.get("rand") or cj.get("rand"):
job["name"] = rand_name(
pdir, cj["name"], vfs.flags["nrand"]
)
else:
job["name"] = self._untaken(pdir, cj, now)
dst = os.path.join(job["ptop"], job["prel"], job["name"])
if not self.args.nw:
bos.unlink(dst) # TODO ed pls

View file

@ -134,6 +134,7 @@ var Ls = {
"wt_next": "next track$NHotkey: L",
"ul_par": "parallel uploads:",
"ut_rand": "randomize filenames",
"ut_mt": "continue hashing other files while uploading$N$Nmaybe disable if your CPU or HDD is a bottleneck",
"ut_ask": "ask for confirmation before upload starts",
"ut_pot": "improve upload speed on slow devices$Nby making the UI less complex",
@ -580,6 +581,7 @@ var Ls = {
"wt_next": "neste sang$NSnarvei: L",
"ul_par": "samtidige handl.:",
"ut_rand": "finn opp nye tilfeldige filnavn",
"ut_mt": "fortsett å befare køen mens opplastning foregår$N$Nskru denne av dersom du har en$Ntreg prosessor eller harddisk",
"ut_ask": "bekreft filutvalg før opplastning starter",
"ut_pot": "forbedre ytelsen på trege enheter ved å$Nforenkle brukergrensesnittet",
@ -957,8 +959,8 @@ ebi('op_up2k').innerHTML = (
' <tr>\n' +
' <td class="c" data-perm="read"><br />' + L.ul_par + '</td>\n' +
' <td class="c" rowspan="2">\n' +
' <input type="checkbox" id="multitask" />\n' +
' <label for="multitask" tt="' + L.ut_mt + '">🏃</label>\n' +
' <input type="checkbox" id="u2rand" />\n' +
' <label for="u2rand" tt="' + L.ut_rand + '">🎲</label>\n' +
' </td>\n' +
' <td class="c" rowspan="2">\n' +
' <input type="checkbox" id="potato" />\n' +
@ -1075,6 +1077,7 @@ ebi('op_cfg').innerHTML = (
'<div>\n' +
' <h3>' + L.cl_uopts + '</h3>\n' +
' <div>\n' +
' <a id="multitask" class="tgl btn" href="#" tt="' + L.ut_mt + '">🏃</a>\n' +
' <a id="hashw" class="tgl btn" href="#" tt="' + L.cut_mt + '">mt</a>\n' +
' <a id="u2turbo" class="tgl btn ttb" href="#" tt="' + L.cut_turbo + '">turbo</a>\n' +
' <a id="u2tdate" class="tgl btn ttb" href="#" tt="' + L.cut_datechk + '">date-chk</a>\n' +

View file

@ -856,6 +856,7 @@ function up2k_init(subtle) {
fdom_ctr = 0,
biggest_file = 0;
bcfg_bind(uc, 'rand', 'u2rand', false, null, false);
bcfg_bind(uc, 'multitask', 'multitask', true, null, false);
bcfg_bind(uc, 'potato', 'potato', false, set_potato, false);
bcfg_bind(uc, 'ask_up', 'ask_up', true, null, false);
@ -1364,6 +1365,9 @@ function up2k_init(subtle) {
if (uc.fsearch)
entry.srch = 1;
if (uc.fsearch && uc.rand)
entry.rand = true;
if (biggest_file < entry.size)
biggest_file = entry.size;
@ -2368,6 +2372,8 @@ function up2k_init(subtle) {
};
if (t.srch)
req.srch = 1;
if (t.rand)
req.rand = true;
xhr.open('POST', t.purl, true);
xhr.responseType = 'text';