fix(serve): allow remote-only mode without output_template and fix CORS/auth for Cloudflare

Move output_template validation from config init to dl command so serve, search, and other non-download commands work without it configured. Fix CORS header to use X-Secret-Key (matching actual auth header). Exempt /api/health from auth for Cloudflare tunnel health checks.
This commit is contained in:
imSp4rky
2026-03-30 04:36:23 +00:00
parent 3d5e46a2e3
commit 1a6f2c5b7e
4 changed files with 12 additions and 9 deletions
+7
View File
@@ -567,6 +567,13 @@ class dl:
self.log = logging.getLogger("download") self.log = logging.getLogger("download")
if not config.output_template:
raise click.ClickException(
"No 'output_template' configured in your unshackle.yaml.\n"
"Please add an 'output_template' section with movies, series, and songs templates.\n"
"See unshackle-example.yaml for examples."
)
self.service = Services.get_tag(ctx.invoked_subcommand) self.service = Services.get_tag(ctx.invoked_subcommand)
service_dl_config = config.services.get(self.service, {}).get("dl", {}) service_dl_config = config.services.get(self.service, {}).get("dl", {})
if service_dl_config: if service_dl_config:
+2
View File
@@ -130,6 +130,8 @@ def serve(
@web.middleware @web.middleware
async def api_key_authentication(request: web.Request, handler) -> web.Response: async def api_key_authentication(request: web.Request, handler) -> web.Response:
"""Authenticate API requests using X-Secret-Key header.""" """Authenticate API requests using X-Secret-Key header."""
if request.path == "/api/health":
return await handler(request)
secret_key = request.headers.get("X-Secret-Key") secret_key = request.headers.get("X-Secret-Key")
if not secret_key: if not secret_key:
return web.json_response({"status": 401, "message": "Secret Key is Empty."}, status=401) return web.json_response({"status": 401, "message": "Secret Key is Empty."}, status=401)
+1 -1
View File
@@ -29,7 +29,7 @@ async def cors_middleware(request: web.Request, handler):
# Add CORS headers # Add CORS headers
response.headers["Access-Control-Allow-Origin"] = "*" response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS" response.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS"
response.headers["Access-Control-Allow-Headers"] = "Content-Type, X-API-Key, Authorization" response.headers["Access-Control-Allow-Headers"] = "Content-Type, X-Secret-Key, Authorization"
response.headers["Access-Control-Max-Age"] = "3600" response.headers["Access-Control-Max-Age"] = "3600"
return response return response
+2 -8
View File
@@ -108,14 +108,8 @@ class Config:
"See unshackle-example.yaml for examples." "See unshackle-example.yaml for examples."
) )
if not self.output_template: if self.output_template:
raise SystemExit( self._validate_output_templates()
"ERROR: No 'output_template' configured in your unshackle.yaml.\n"
"Please add an 'output_template' section with movies, series, and songs templates.\n"
"See unshackle-example.yaml for examples."
)
self._validate_output_templates()
self.unicode_filenames: bool = kwargs.get("unicode_filenames", False) self.unicode_filenames: bool = kwargs.get("unicode_filenames", False)