mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
return file URL in PUT response
This commit is contained in:
parent
0214793740
commit
e87ea19ff1
|
@ -524,7 +524,7 @@ class HttpCli(object):
|
||||||
return self.handle_stash()
|
return self.handle_stash()
|
||||||
|
|
||||||
if "save" in opt:
|
if "save" in opt:
|
||||||
post_sz, _, _, _, path = self.dump_to_file()
|
post_sz, _, _, _, path, _ = self.dump_to_file()
|
||||||
self.log("urlform: {} bytes, {}".format(post_sz, path))
|
self.log("urlform: {} bytes, {}".format(post_sz, path))
|
||||||
elif "print" in opt:
|
elif "print" in opt:
|
||||||
reader, _ = self.get_body_reader()
|
reader, _ = self.get_body_reader()
|
||||||
|
@ -651,26 +651,45 @@ class HttpCli(object):
|
||||||
bos.unlink(path)
|
bos.unlink(path)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if not self.args.nw:
|
if self.args.nw:
|
||||||
vfs, vrem = vfs.get_dbv(rem)
|
return post_sz, sha_hex, sha_b64, remains, path, ""
|
||||||
self.conn.hsrv.broker.put(
|
|
||||||
False,
|
|
||||||
"up2k.hash_file",
|
|
||||||
vfs.realpath,
|
|
||||||
vfs.flags,
|
|
||||||
vrem,
|
|
||||||
fn,
|
|
||||||
self.ip,
|
|
||||||
time.time(),
|
|
||||||
)
|
|
||||||
|
|
||||||
return post_sz, sha_hex, sha_b64, remains, path
|
vfs, rem = vfs.get_dbv(rem)
|
||||||
|
self.conn.hsrv.broker.put(
|
||||||
|
False,
|
||||||
|
"up2k.hash_file",
|
||||||
|
vfs.realpath,
|
||||||
|
vfs.flags,
|
||||||
|
rem,
|
||||||
|
fn,
|
||||||
|
self.ip,
|
||||||
|
time.time(),
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.can_read and "fk" in vfs.flags:
|
||||||
|
vsuf = "?k=" + gen_filekey(
|
||||||
|
self.args.fk_salt,
|
||||||
|
path,
|
||||||
|
post_sz,
|
||||||
|
0 if ANYWIN else bos.stat(path).st_ino,
|
||||||
|
)[: vfs.flags["fk"]]
|
||||||
|
|
||||||
|
vpath = "/".join([x for x in [vfs.vpath, rem, fn] if x])
|
||||||
|
vpath = quotep(vpath)
|
||||||
|
|
||||||
|
url = "{}://{}/{}".format(
|
||||||
|
"https" if self.is_https else "http",
|
||||||
|
self.headers.get("host") or "{}:{}".format(*list(self.s.getsockname())),
|
||||||
|
vpath + vsuf,
|
||||||
|
)
|
||||||
|
|
||||||
|
return post_sz, sha_hex, sha_b64, remains, path, url
|
||||||
|
|
||||||
def handle_stash(self):
|
def handle_stash(self):
|
||||||
post_sz, sha_hex, sha_b64, remains, path = self.dump_to_file()
|
post_sz, sha_hex, sha_b64, remains, path, url = self.dump_to_file()
|
||||||
spd = self._spd(post_sz)
|
spd = self._spd(post_sz)
|
||||||
self.log("{} wrote {}/{} bytes to {}".format(spd, post_sz, remains, path))
|
self.log("{} wrote {}/{} bytes to {}".format(spd, post_sz, remains, path))
|
||||||
m = "{}\n{}\n{}\n".format(post_sz, sha_b64, sha_hex[:56])
|
m = "{}\n{}\n{}\n{}\n".format(post_sz, sha_b64, sha_hex[:56], url)
|
||||||
self.reply(m.encode("utf-8"))
|
self.reply(m.encode("utf-8"))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -1170,11 +1189,12 @@ class HttpCli(object):
|
||||||
)[: vfs.flags["fk"]]
|
)[: vfs.flags["fk"]]
|
||||||
|
|
||||||
vpath = "{}/{}".format(upload_vpath, lfn).strip("/")
|
vpath = "{}/{}".format(upload_vpath, lfn).strip("/")
|
||||||
|
rel_url = quotep(vpath) + vsuf
|
||||||
msg += 'sha512: {} // {} // {} bytes // <a href="/{}">{}</a> {}\n'.format(
|
msg += 'sha512: {} // {} // {} bytes // <a href="/{}">{}</a> {}\n'.format(
|
||||||
sha_hex[:56],
|
sha_hex[:56],
|
||||||
sha_b64,
|
sha_b64,
|
||||||
sz,
|
sz,
|
||||||
quotep(vpath) + vsuf,
|
rel_url,
|
||||||
html_escape(ofn, crlf=True),
|
html_escape(ofn, crlf=True),
|
||||||
vsuf,
|
vsuf,
|
||||||
)
|
)
|
||||||
|
@ -1183,15 +1203,16 @@ class HttpCli(object):
|
||||||
jpart = {
|
jpart = {
|
||||||
"url": "{}://{}/{}".format(
|
"url": "{}://{}/{}".format(
|
||||||
"https" if self.is_https else "http",
|
"https" if self.is_https else "http",
|
||||||
self.headers.get("host", "copyparty"),
|
self.headers.get("host")
|
||||||
vpath + vsuf,
|
or "{}:{}".format(*list(self.s.getsockname())),
|
||||||
|
rel_url,
|
||||||
),
|
),
|
||||||
"sha512": sha_hex[:56],
|
"sha512": sha_hex[:56],
|
||||||
"sha_b64": sha_b64,
|
"sha_b64": sha_b64,
|
||||||
"sz": sz,
|
"sz": sz,
|
||||||
"fn": lfn,
|
"fn": lfn,
|
||||||
"fn_orig": ofn,
|
"fn_orig": ofn,
|
||||||
"path": vpath + vsuf,
|
"path": rel_url,
|
||||||
}
|
}
|
||||||
jmsg["files"].append(jpart)
|
jmsg["files"].append(jpart)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue