mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 01:22:13 -06:00
don't embed huge docs (defer to ajax), closes #9
This commit is contained in:
parent
c110ccb9ae
commit
67c298e66b
|
@ -569,6 +569,7 @@ def run_argparse(argv, formatter):
|
|||
ap2.add_argument("--css-browser", metavar="L", type=u, help="URL to additional CSS to include")
|
||||
ap2.add_argument("--html-head", metavar="TXT", type=u, default="", help="text to append to the <head> of all HTML pages")
|
||||
ap2.add_argument("--textfiles", metavar="CSV", type=u, default="txt,nfo,diz,cue,readme", help="file extensions to present as plaintext")
|
||||
ap2.add_argument("--txt-max", metavar="KiB", type=int, default=64, help="max size of embedded textfiles on ?doc= (anything bigger will be lazy-loaded by JS)")
|
||||
ap2.add_argument("--doctitle", metavar="TXT", type=u, default="copyparty", help="title / service-name to show in html documents")
|
||||
|
||||
ap2 = ap.add_argument_group('debug options')
|
||||
|
|
|
@ -2438,14 +2438,19 @@ class HttpCli(object):
|
|||
if doc:
|
||||
doc = unquotep(doc.replace("+", " ").split("?")[0])
|
||||
j2a["docname"] = doc
|
||||
doctxt = None
|
||||
if next((x for x in files if x["name"] == doc), None):
|
||||
with open(os.path.join(abspath, doc), "rb") as f:
|
||||
doc = f.read().decode("utf-8", "replace")
|
||||
docpath = os.path.join(abspath, doc)
|
||||
sz = bos.path.getsize(docpath)
|
||||
if sz < 1024 * self.args.txt_max:
|
||||
with open(docpath, "rb") as f:
|
||||
doctxt = f.read().decode("utf-8", "replace")
|
||||
else:
|
||||
self.log("doc 404: [{}]".format(doc), c=6)
|
||||
doc = "( textfile not found )"
|
||||
doctxt = "( textfile not found )"
|
||||
|
||||
j2a["doc"] = doc
|
||||
if doctxt is not None:
|
||||
j2a["doc"] = doctxt
|
||||
|
||||
if not self.conn.hsrv.prism:
|
||||
j2a["no_prism"] = True
|
||||
|
|
|
@ -2441,6 +2441,14 @@ var showfile = (function () {
|
|||
var em = QS('#bdoc>pre');
|
||||
if (em)
|
||||
em = [r.sname(window.location.search), window.location.hash, em.textContent];
|
||||
else {
|
||||
var m = /[?&]doc=([^&]+)/.exec(window.location.search);
|
||||
if (m) {
|
||||
setTimeout(function () {
|
||||
r.show(uricom_dec(m[1])[0], true);
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
||||
r.setstyle = function () {
|
||||
if (window['no_prism'])
|
||||
|
@ -4166,6 +4174,7 @@ var treectl = (function () {
|
|||
xhr.open('GET', '/?am_js', true);
|
||||
xhr.send();
|
||||
|
||||
r.ls_cb = showfile.addlinks;
|
||||
return r.reqls(get_evpath(), false, true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue