diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 6ea6288e..1bd0ec72 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -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 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') diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 6dccad48..fcbb2bc6 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -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 diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index d85c8e09..ad8a259d 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -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); }