mirror of
https://github.com/9001/copyparty.git
synced 2025-08-19 01:42:20 -06:00
explicit redirect to single non-roots
This commit is contained in:
parent
33b91a7513
commit
e7982a04fe
|
@ -235,6 +235,22 @@ class HttpCli(object):
|
||||||
r = ["{}={}".format(k, quotep(v)) if v else k for k, v in kv.items()]
|
r = ["{}={}".format(k, quotep(v)) if v else k for k, v in kv.items()]
|
||||||
return "?" + "&".join(r)
|
return "?" + "&".join(r)
|
||||||
|
|
||||||
|
def redirect(self, vpath, suf="", msg="aight", flavor="go to", use302=False):
|
||||||
|
html = self.j2(
|
||||||
|
"msg",
|
||||||
|
h2='<a href="/{}">{} /{}</a>'.format(
|
||||||
|
quotep(vpath) + suf, flavor, html_escape(vpath, crlf=True) + suf
|
||||||
|
),
|
||||||
|
pre=msg,
|
||||||
|
click=True,
|
||||||
|
).encode("utf-8", "replace")
|
||||||
|
|
||||||
|
if use302:
|
||||||
|
h = {"Location": "/" + vpath, "Cache-Control": "no-cache"}
|
||||||
|
self.reply(html, status=302, headers=h)
|
||||||
|
else:
|
||||||
|
self.reply(html)
|
||||||
|
|
||||||
def handle_get(self):
|
def handle_get(self):
|
||||||
logmsg = "{:4} {}".format(self.mode, self.req)
|
logmsg = "{:4} {}".format(self.mode, self.req)
|
||||||
|
|
||||||
|
@ -262,11 +278,12 @@ class HttpCli(object):
|
||||||
nwrite = len(self.wvol)
|
nwrite = len(self.wvol)
|
||||||
if nread + nwrite == 1 or (self.rvol == self.wvol and nread == 1):
|
if nread + nwrite == 1 or (self.rvol == self.wvol and nread == 1):
|
||||||
if nread == 1:
|
if nread == 1:
|
||||||
self.vpath = self.rvol[0]
|
vpath = self.rvol[0]
|
||||||
else:
|
else:
|
||||||
self.vpath = self.wvol[0]
|
vpath = self.wvol[0]
|
||||||
|
|
||||||
self.absolute_urls = True
|
self.redirect(vpath, flavor="redirecting to", use302=True)
|
||||||
|
return True
|
||||||
|
|
||||||
self.readable, self.writable = self.conn.auth.vfs.can_access(
|
self.readable, self.writable = self.conn.auth.vfs.can_access(
|
||||||
self.vpath, self.uname
|
self.vpath, self.uname
|
||||||
|
@ -692,14 +709,7 @@ class HttpCli(object):
|
||||||
raise Pebkac(500, "mkdir failed, check the logs")
|
raise Pebkac(500, "mkdir failed, check the logs")
|
||||||
|
|
||||||
vpath = "{}/{}".format(self.vpath, sanitized).lstrip("/")
|
vpath = "{}/{}".format(self.vpath, sanitized).lstrip("/")
|
||||||
esc_paths = [quotep(vpath), html_escape(vpath, crlf=True)]
|
self.redirect(vpath)
|
||||||
html = self.j2(
|
|
||||||
"msg",
|
|
||||||
h2='<a href="/{}">go to /{}</a>'.format(*esc_paths),
|
|
||||||
pre="aight",
|
|
||||||
click=True,
|
|
||||||
)
|
|
||||||
self.reply(html.encode("utf-8", "replace"))
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def handle_new_md(self):
|
def handle_new_md(self):
|
||||||
|
@ -726,15 +736,7 @@ class HttpCli(object):
|
||||||
f.write(b"`GRUNNUR`\n")
|
f.write(b"`GRUNNUR`\n")
|
||||||
|
|
||||||
vpath = "{}/{}".format(self.vpath, sanitized).lstrip("/")
|
vpath = "{}/{}".format(self.vpath, sanitized).lstrip("/")
|
||||||
html = self.j2(
|
self.redirect(vpath, "?edit")
|
||||||
"msg",
|
|
||||||
h2='<a href="/{}?edit">go to /{}?edit</a>'.format(
|
|
||||||
quotep(vpath), html_escape(vpath)
|
|
||||||
),
|
|
||||||
pre="aight",
|
|
||||||
click=True,
|
|
||||||
)
|
|
||||||
self.reply(html.encode("utf-8", "replace"))
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def handle_plain_upload(self):
|
def handle_plain_upload(self):
|
||||||
|
@ -835,14 +837,7 @@ class HttpCli(object):
|
||||||
).encode("utf-8")
|
).encode("utf-8")
|
||||||
)
|
)
|
||||||
|
|
||||||
html = self.j2(
|
self.redirect(self.vpath, msg=msg, flavor="return to")
|
||||||
"msg",
|
|
||||||
h2='<a href="/{}">return to /{}</a>'.format(
|
|
||||||
quotep(self.vpath), html_escape(self.vpath)
|
|
||||||
),
|
|
||||||
pre=msg,
|
|
||||||
)
|
|
||||||
self.reply(html.encode("utf-8", "replace"))
|
|
||||||
self.parser.drop()
|
self.parser.drop()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ HTTPCODE = {
|
||||||
200: "OK",
|
200: "OK",
|
||||||
204: "No Content",
|
204: "No Content",
|
||||||
206: "Partial Content",
|
206: "Partial Content",
|
||||||
|
302: "Found",
|
||||||
304: "Not Modified",
|
304: "Not Modified",
|
||||||
400: "Bad Request",
|
400: "Bad Request",
|
||||||
403: "Forbidden",
|
403: "Forbidden",
|
||||||
|
|
Loading…
Reference in a new issue