custom logue/md names; closes #1068, closes #1089

This commit is contained in:
ed
2025-12-13 22:05:29 +00:00
parent 594ec39481
commit 14bef85b87
5 changed files with 49 additions and 33 deletions

View File

@@ -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("--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("--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("--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("--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("--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") ap2.add_argument("--pb-url", metavar="URL", type=u, default=URL_PRJ, help="powered-by link; disable with \033[33m-nb\033[0m")

View File

@@ -2524,6 +2524,18 @@ class AuthSrv(object):
t = "WARNING: volume [/%s]: invalid value specified for ext-th: %s" t = "WARNING: volume [/%s]: invalid value specified for ext-th: %s"
self.log(t % (vol.vpath, etv), 3) 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 "") zs = str(vol.flags.get("html_head") or "")
if zs and zs[:1] in "%@": if zs and zs[:1] in "%@":
vol.flags["html_head_d"] = zs vol.flags["html_head_d"] = zs

View File

@@ -100,6 +100,7 @@ def vf_vmap() -> dict[str, str]:
"chmod_f", "chmod_f",
"dbd", "dbd",
"du_who", "du_who",
"epilogues",
"ufavico", "ufavico",
"forget_ip", "forget_ip",
"fsnt", "fsnt",
@@ -123,8 +124,11 @@ def vf_vmap() -> dict[str, str]:
"og_tpl", "og_tpl",
"og_ua", "og_ua",
"opds_exts", "opds_exts",
"prologues",
"preadmes",
"put_ck", "put_ck",
"put_name", "put_name",
"readmes",
"mv_retry", "mv_retry",
"rm_retry", "rm_retry",
"shr_who", "shr_who",
@@ -333,6 +337,10 @@ flagcats = {
"norobots": "kindly asks search engines to leave", "norobots": "kindly asks search engines to leave",
"unlistcr": "don't list read-access in controlpanel", "unlistcr": "don't list read-access in controlpanel",
"unlistcw": "don't list write-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_md": "disable js sandbox for markdown files",
"no_sb_lg": "disable js sandbox for prologue/epilogue", "no_sb_lg": "disable js sandbox for prologue/epilogue",
"sb_md": "enable js sandbox for markdown files (default)", "sb_md": "enable js sandbox for markdown files (default)",

View File

@@ -159,10 +159,6 @@ BADXFF2 = ". Some copyparty features are now disabled as a safety measure."
H_CONN_KEEPALIVE = "Connection: Keep-Alive" H_CONN_KEEPALIVE = "Connection: Keep-Alive"
H_CONN_CLOSE = "Connection: Close" 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"} RSS_SORT = {"m": "mt", "u": "at", "n": "fn", "s": "sz"}
A_FILE = os.stat_result( A_FILE = os.stat_result(
@@ -4133,40 +4129,36 @@ class HttpCli(object):
self, vn: VFS, abspath: str, lnames: Optional[dict[str, str]] self, vn: VFS, abspath: str, lnames: Optional[dict[str, str]]
) -> tuple[list[str], list[str]]: ) -> tuple[list[str], list[str]]:
logues = ["", ""] logues = ["", ""]
if not self.args.no_logues: for n, fns1, fns2 in [] if self.args.no_logues else vn.flags["emb_lgs"]:
for n, fn in LOGUES: for fn in fns1 if lnames is None else fns2:
if lnames is not None and fn not in lnames: if lnames is not None:
continue fn = lnames.get(fn)
if not fn:
continue
fn = "%s/%s" % (abspath, fn) fn = "%s/%s" % (abspath, fn)
if bos.path.isfile(fn): if not bos.path.isfile(fn):
logues[n] = read_utf8(self.log, fsenc(fn), False) continue
if "exp" in vn.flags: logues[n] = read_utf8(self.log, fsenc(fn), False)
logues[n] = self._expand( if "exp" in vn.flags:
logues[n], vn.flags.get("exp_lg") or [] logues[n] = self._expand(logues[n], vn.flags.get("exp_lg") or [])
) break
readmes = ["", ""] 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]: if logues[n]:
continue continue
elif lnames is None: for fn in fns1 if lnames is None else fns2:
pass if lnames is not None:
elif fns[0] in lnames: fn = lnames.get(fn.lower())
fns = [lnames[fns[0]]] if not fn:
else: continue
fns = []
txt = ""
for fn in fns:
fn = "%s/%s" % (abspath, fn) fn = "%s/%s" % (abspath, fn)
if bos.path.isfile(fn): if not bos.path.isfile(fn):
txt = read_utf8(self.log, fsenc(fn), False) continue
break readmes[n] = read_utf8(self.log, fsenc(fn), False)
if "exp" in vn.flags:
if txt and "exp" in vn.flags: readmes[n] = self._expand(readmes[n], vn.flags.get("exp_md") or [])
txt = self._expand(txt, vn.flags.get("exp_md") or []) break
readmes[n] = txt
return logues, readmes return logues, readmes

View File

@@ -1148,7 +1148,7 @@ class Up2k(object):
ft = "\033[0;32m{}{:.0}" ft = "\033[0;32m{}{:.0}"
ff = "\033[0;35m{}{:.0}" ff = "\033[0;35m{}{:.0}"
fv = "\033[0;36m{}:\033[90m{}" 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()) fx = set(zs.split())
fd = vf_bmap() fd = vf_bmap()
fd.update(vf_cmap()) fd.update(vf_cmap())