opds: server config, volflags, permissions

This commit is contained in:
AppleTheGolden 2025-09-09 22:31:33 +02:00
parent 16d9a4d10c
commit 22b7db66f1
No known key found for this signature in database
GPG key ID: F6AC8A62154C42AA
4 changed files with 24 additions and 3 deletions

View file

@ -1432,6 +1432,10 @@ def add_smb(ap):
ap2.add_argument("--smbvv", action="store_true", help="verboser") ap2.add_argument("--smbvv", action="store_true", help="verboser")
ap2.add_argument("--smbvvv", action="store_true", help="verbosest") 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): def add_handlers(ap):
ap2 = ap.add_argument_group("handlers (see --help-handlers)") ap2 = ap.add_argument_group("handlers (see --help-handlers)")
@ -1856,6 +1860,7 @@ def run_argparse(
add_webdav(ap) add_webdav(ap)
add_tftp(ap) add_tftp(ap)
add_smb(ap) add_smb(ap)
add_opds(ap)
add_safety(ap) add_safety(ap)
add_salt(ap, fk_salt, dk_salt, ah_salt) add_salt(ap, fk_salt, dk_salt, ah_salt)
add_optouts(ap) add_optouts(ap)

View file

@ -52,6 +52,7 @@ def vf_bmap() -> dict[str, str]:
"og", "og",
"og_no_head", "og_no_head",
"og_s_title", "og_s_title",
"opds",
"rand", "rand",
"reflink", "reflink",
"rmagic", "rmagic",
@ -143,6 +144,7 @@ def vf_cmap() -> dict[str, str]:
"mte", "mte",
"mth", "mth",
"mtp", "mtp",
"opds_allowed",
"xac", "xac",
"xad", "xad",
"xar", "xar",
@ -327,6 +329,10 @@ flagcats = {
"og_no_head": "you want to add tags manually with og_tpl", "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", "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": { "textfiles": {
"md_no_br": "newline only on double-newline or two tailing spaces", "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", "md_hist": "where to put markdown backups; s=subfolder, v=volHist, n=nope",

View file

@ -6442,8 +6442,10 @@ class HttpCli(object):
is_js = False is_js = False
elif "opds1" in self.uparam: elif "opds1" in self.uparam:
# Display directory listing as OPDS v1.2 catalog feed # Display directory listing as OPDS v1.2 catalog feed
# TODO: Permissions if not (self.args.opds or "opds" in self.vn.flags):
# TODO: Server Config raise Pebkac(405, "OPDS is disabled in server config")
if not self.can_read:
raise Pebkac(401, "OPDS requires read permission")
is_opds = True is_opds = True
tpl = "opds1" tpl = "opds1"
is_js = False is_js = False
@ -6573,6 +6575,12 @@ class HttpCli(object):
no_zip = bool(self._can_zip(vf)) 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 = [] dirs = []
files = [] files = []
ptn_hr = RE_HR ptn_hr = RE_HR
@ -6636,6 +6644,8 @@ class HttpCli(object):
ext = ptn_hr.sub("@", fn.rsplit(".", 1)[1]) ext = ptn_hr.sub("@", fn.rsplit(".", 1)[1])
if len(ext) > 16: if len(ext) > 16:
ext = ext[:16] ext = ext[:16]
if is_opds and not opds_no_filter and ext not in self.args.opds_allowed:
continue
else: else:
ext = "%" ext = "%"