diff --git a/copyparty/__main__.py b/copyparty/__main__.py index f1881cc1..d8ec9246 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1814,6 +1814,10 @@ def add_ui(ap, retry: int): ap2.add_argument("--ih", action="store_true", help="if a folder contains index.html, show that instead of the directory listing by default (can be changed in the client settings UI, or add ?v to URL for override)") 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("--prologues", metavar="T,T", type=u, default=".prologue.html", help="comma-sep. list of filenames to scan for and use as prologues (embed above/before directory listing) (volflag=prologues)") + ap2.add_argument("--epilogues", metavar="T,T", type=u, default=".epilogue.html", help="comma-sep. list of filenames to scan for and use as epilogues (embed below/after directory listing) (volflag=epilogues)") + ap2.add_argument("--preadmes", metavar="T,T", type=u, default="preadme.md,PREADME.md", help="comma-sep. list of filenames to scan for and use as preadmes (embed above/before directory listing) (volflag=preadmes)") + ap2.add_argument("--readmes", metavar="T,T", type=u, default="readme.md,README.md", help="comma-sep. list of filenames to scan for and use as readmes (embed below/after directory listing) (volflag=readmes)") ap2.add_argument("--doctitle", metavar="TXT", type=u, default="copyparty @ --name", help="title / service-name to show in html documents") ap2.add_argument("--bname", metavar="TXT", type=u, default="--name", help="server name (displayed in filebrowser document title)") ap2.add_argument("--pb-url", metavar="URL", type=u, default=URL_PRJ, help="powered-by link; disable with \033[33m-nb\033[0m") diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index 27a7b401..ff3d2181 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -2524,6 +2524,18 @@ class AuthSrv(object): t = "WARNING: volume [/%s]: invalid value specified for ext-th: %s" self.log(t % (vol.vpath, etv), 3) + zsl1 = [x for x in vol.flags["preadmes"].split(",") if x] + zsl2 = [x for x in vol.flags["readmes"].split(",") if x] + zsl3 = list(set([x.lower() for x in zsl1])) + zsl4 = list(set([x.lower() for x in zsl2])) + vol.flags["emb_mds"] = [[0, zsl1, zsl3], [1, zsl2, zsl4]] + + zsl1 = [x for x in vol.flags["prologues"].split(",") if x] + zsl2 = [x for x in vol.flags["epilogues"].split(",") if x] + zsl3 = list(set([x.lower() for x in zsl1])) + zsl4 = list(set([x.lower() for x in zsl2])) + vol.flags["emb_lgs"] = [[0, zsl1, zsl3], [1, zsl2, zsl4]] + zs = str(vol.flags.get("html_head") or "") if zs and zs[:1] in "%@": vol.flags["html_head_d"] = zs diff --git a/copyparty/cfg.py b/copyparty/cfg.py index 69903225..d83b47f9 100644 --- a/copyparty/cfg.py +++ b/copyparty/cfg.py @@ -100,6 +100,7 @@ def vf_vmap() -> dict[str, str]: "chmod_f", "dbd", "du_who", + "epilogues", "ufavico", "forget_ip", "fsnt", @@ -123,8 +124,11 @@ def vf_vmap() -> dict[str, str]: "og_tpl", "og_ua", "opds_exts", + "prologues", + "preadmes", "put_ck", "put_name", + "readmes", "mv_retry", "rm_retry", "shr_who", @@ -333,6 +337,10 @@ flagcats = { "norobots": "kindly asks search engines to leave", "unlistcr": "don't list read-access in controlpanel", "unlistcw": "don't list write-access in controlpanel", + "prologues=.prologue.html": "files to embed above/before files", + "epilogues=.epilogue.html": "files to embed below/after files", + "readmes=readme.md,README.md": "files to embed as readmes", + "preadmes=preadme.md,PREADME.md": "files to embed as preadmes", "no_sb_md": "disable js sandbox for markdown files", "no_sb_lg": "disable js sandbox for prologue/epilogue", "sb_md": "enable js sandbox for markdown files (default)", diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index ff3f4b9a..2a36320e 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -159,10 +159,6 @@ BADXFF2 = ". Some copyparty features are now disabled as a safety measure." H_CONN_KEEPALIVE = "Connection: Keep-Alive" H_CONN_CLOSE = "Connection: Close" -LOGUES = [[0, ".prologue.html"], [1, ".epilogue.html"]] - -READMES = [[0, ["preadme.md", "PREADME.md"]], [1, ["readme.md", "README.md"]]] - RSS_SORT = {"m": "mt", "u": "at", "n": "fn", "s": "sz"} A_FILE = os.stat_result( @@ -4133,40 +4129,36 @@ class HttpCli(object): self, vn: VFS, abspath: str, lnames: Optional[dict[str, str]] ) -> tuple[list[str], list[str]]: logues = ["", ""] - if not self.args.no_logues: - for n, fn in LOGUES: - if lnames is not None and fn not in lnames: - continue + for n, fns1, fns2 in [] if self.args.no_logues else vn.flags["emb_lgs"]: + for fn in fns1 if lnames is None else fns2: + if lnames is not None: + fn = lnames.get(fn) + if not fn: + continue fn = "%s/%s" % (abspath, fn) - if bos.path.isfile(fn): - logues[n] = read_utf8(self.log, fsenc(fn), False) - if "exp" in vn.flags: - logues[n] = self._expand( - logues[n], vn.flags.get("exp_lg") or [] - ) + if not bos.path.isfile(fn): + continue + logues[n] = read_utf8(self.log, fsenc(fn), False) + if "exp" in vn.flags: + logues[n] = self._expand(logues[n], vn.flags.get("exp_lg") or []) + break readmes = ["", ""] - for n, fns in [] if self.args.no_readme else READMES: + for n, fns1, fns2 in [] if self.args.no_readme else vn.flags["emb_mds"]: if logues[n]: continue - elif lnames is None: - pass - elif fns[0] in lnames: - fns = [lnames[fns[0]]] - else: - fns = [] - - txt = "" - for fn in fns: + for fn in fns1 if lnames is None else fns2: + if lnames is not None: + fn = lnames.get(fn.lower()) + if not fn: + continue fn = "%s/%s" % (abspath, fn) - if bos.path.isfile(fn): - txt = read_utf8(self.log, fsenc(fn), False) - break - - if txt and "exp" in vn.flags: - txt = self._expand(txt, vn.flags.get("exp_md") or []) - - readmes[n] = txt + if not bos.path.isfile(fn): + continue + readmes[n] = read_utf8(self.log, fsenc(fn), False) + if "exp" in vn.flags: + readmes[n] = self._expand(readmes[n], vn.flags.get("exp_md") or []) + break return logues, readmes diff --git a/copyparty/up2k.py b/copyparty/up2k.py index a2c3b233..edcae7eb 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -1148,7 +1148,7 @@ class Up2k(object): ft = "\033[0;32m{}{:.0}" ff = "\033[0;35m{}{:.0}" fv = "\033[0;36m{}:\033[90m{}" - zs = "bcasechk du_iwho ext_th_d html_head html_head_d html_head_s put_name2 mv_re_r mv_re_t rm_re_r rm_re_t srch_re_dots srch_re_nodot zipmax zipmaxn_v zipmaxs_v" + zs = "bcasechk du_iwho emb_lgs emb_mds ext_th_d html_head html_head_d html_head_s put_name2 mv_re_r mv_re_t rm_re_r rm_re_t srch_re_dots srch_re_nodot zipmax zipmaxn_v zipmaxs_v" fx = set(zs.split()) fd = vf_bmap() fd.update(vf_cmap())