From 22b7db66f19fa9515e3e6fc7c64763dfc066ce2a Mon Sep 17 00:00:00 2001 From: AppleTheGolden Date: Tue, 9 Sep 2025 22:31:33 +0200 Subject: [PATCH] opds: server config, volflags, permissions --- copyparty/__main__.py | 5 +++++ copyparty/cfg.py | 6 ++++++ copyparty/httpcli.py | 14 ++++++++++++-- copyparty/web/opds1.html | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 074f865f..cc87685c 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1432,6 +1432,10 @@ def add_smb(ap): ap2.add_argument("--smbvv", action="store_true", help="verboser") ap2.add_argument("--smbvvv", action="store_true", help="verbosest") +def add_opds(ap): + ap2 = ap.add_argument_group("OPDS options") + ap2.add_argument("--opds", action="store_true", help="enable opds -- allows e-book readers to browse and download files (volflag=opds)") + ap2.add_argument("--opds-allowed", metavar="T,T", type=u, default="epub,cbz,pdf", help="file formats to list in OPDS feeds; leave empty to show everything (volflag=opds_allowed)") def add_handlers(ap): ap2 = ap.add_argument_group("handlers (see --help-handlers)") @@ -1856,6 +1860,7 @@ def run_argparse( add_webdav(ap) add_tftp(ap) add_smb(ap) + add_opds(ap) add_safety(ap) add_salt(ap, fk_salt, dk_salt, ah_salt) add_optouts(ap) diff --git a/copyparty/cfg.py b/copyparty/cfg.py index 2fcb3d4e..b9819496 100644 --- a/copyparty/cfg.py +++ b/copyparty/cfg.py @@ -52,6 +52,7 @@ def vf_bmap() -> dict[str, str]: "og", "og_no_head", "og_s_title", + "opds", "rand", "reflink", "rmagic", @@ -143,6 +144,7 @@ def vf_cmap() -> dict[str, str]: "mte", "mth", "mtp", + "opds_allowed", "xac", "xad", "xar", @@ -327,6 +329,10 @@ flagcats = { "og_no_head": "you want to add tags manually with og_tpl", "og_ua": "if defined: only send OG html if useragent matches this regex", }, + "opds": { + "opds": "enable OPDS", + "opds_allowed": "file formats to list in OPDS feeds; leave empty to show everything" + }, "textfiles": { "md_no_br": "newline only on double-newline or two tailing spaces", "md_hist": "where to put markdown backups; s=subfolder, v=volHist, n=nope", diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 3746bc93..1fdc2a26 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -6442,8 +6442,10 @@ class HttpCli(object): is_js = False elif "opds1" in self.uparam: # Display directory listing as OPDS v1.2 catalog feed - # TODO: Permissions - # TODO: Server Config + if not (self.args.opds or "opds" in self.vn.flags): + raise Pebkac(405, "OPDS is disabled in server config") + if not self.can_read: + raise Pebkac(401, "OPDS requires read permission") is_opds = True tpl = "opds1" is_js = False @@ -6573,6 +6575,12 @@ class HttpCli(object): no_zip = bool(self._can_zip(vf)) + volflag_opds_allowed = vf.get("opds_allowed") + if volflag_opds_allowed is not None: + opds_no_filter = len(volflag_opds_allowed) == 0 + else: + opds_no_filter = len(self.args.opds_allowed) == 0 + dirs = [] files = [] ptn_hr = RE_HR @@ -6636,6 +6644,8 @@ class HttpCli(object): ext = ptn_hr.sub("@", fn.rsplit(".", 1)[1]) if len(ext) > 16: ext = ext[:16] + if is_opds and not opds_no_filter and ext not in self.args.opds_allowed: + continue else: ext = "%" diff --git a/copyparty/web/opds1.html b/copyparty/web/opds1.html index e4894e18..fb22371c 100644 --- a/copyparty/web/opds1.html +++ b/copyparty/web/opds1.html @@ -4,7 +4,7 @@ {{ d.name }} {{ d.iso8601 }}