From 560d7b6672dc0509547ec07bc4d3ff2246d1165b Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 8 May 2024 21:12:14 +0000 Subject: [PATCH] option to add or change mimetype mappings --- copyparty/__main__.py | 7 +++++++ copyparty/authsrv.py | 9 +++++++++ tests/util.py | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index cca4d459..058ea491 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -43,6 +43,7 @@ from .util import ( DEF_MTH, IMPLICATIONS, JINJA_VER, + MIMES, PARTFTPY_VER, PY_DESC, PYFTPD_VER, @@ -838,6 +839,8 @@ def add_general(ap, nc, srvname): ap2.add_argument("--urlform", metavar="MODE", type=u, default="print,get", help="how to handle url-form POSTs; see \033[33m--help-urlform\033[0m") ap2.add_argument("--wintitle", metavar="TXT", type=u, default="cpp @ $pub", help="server terminal title, for example [\033[32m$ip-10.1.2.\033[0m] or [\033[32m$ip-]") ap2.add_argument("--name", metavar="TXT", type=u, default=srvname, help="server name (displayed topleft in browser and in mDNS)") + ap2.add_argument("--mime", metavar="EXT=MIME", type=u, action="append", help="map file \033[33mEXT\033[0mension to \033[33mMIME\033[0mtype, for example [\033[32mjpg=image/jpeg\033[0m]") + ap2.add_argument("--mimes", action="store_true", help="list default mimetype mapping and exit") ap2.add_argument("--license", action="store_true", help="show licenses and exit") ap2.add_argument("--version", action="store_true", help="show versions and exit") @@ -1444,6 +1447,10 @@ def main(argv: Optional[list[str]] = None, rsrc: Optional[str] = None) -> None: showlic() sys.exit(0) + if "--mimes" in argv: + print("\n".join("%8s %s" % (k, v) for k, v in sorted(MIMES.items()))) + sys.exit(0) + if EXE: print("pybin: {}\n".format(pybin), end="") diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index cef0ca82..5e44315d 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -17,7 +17,9 @@ from .bos import bos from .cfg import flagdescs, permdescs, vf_bmap, vf_cmap, vf_vmap from .pwhash import PWHash from .util import ( + EXTS, IMPLICATIONS, + MIMES, SQLITE_VER, UNPLICATIONS, UTC, @@ -2065,6 +2067,13 @@ class AuthSrv(object): self.re_pwd = re.compile(zs) + # to ensure it propagates into tcpsrv with mp on + if self.args.mime: + for zs in self.args.mime: + ext, mime = zs.split("=", 1) + MIMES[ext] = mime + EXTS.update({v: k for k, v in MIMES.items()}) + def setup_pwhash(self, acct: dict[str, str]) -> None: self.ah = PWHash(self.args) if not self.ah.on: diff --git a/tests/util.py b/tests/util.py index a7d453f5..cf510639 100644 --- a/tests/util.py +++ b/tests/util.py @@ -116,7 +116,7 @@ class Cfg(Namespace): ex = "dotpart dotsrch no_dhash no_fastboot no_rescan no_sendfile no_snap no_voldump re_dhash plain_ip" ka.update(**{k: True for k in ex.split()}) - ex = "ah_cli ah_gen css_browser hist js_browser no_forget no_hash no_idx nonsus_urls og_tpl og_ua" + ex = "ah_cli ah_gen css_browser hist js_browser mime mimes no_forget no_hash no_idx nonsus_urls og_tpl og_ua" ka.update(**{k: None for k in ex.split()}) ex = "hash_mt srch_time u2abort u2j"