add env to disable auth on download endpoint

This commit is contained in:
Georges-Antoine Assi
2024-04-04 15:25:00 -04:00
parent a573780a92
commit eda6d78c4b
3 changed files with 31 additions and 9 deletions

View File

@@ -54,6 +54,9 @@ ROMM_AUTH_SECRET_KEY: Final = os.environ.get(
"ROMM_AUTH_SECRET_KEY", secrets.token_hex(32)
)
DISABLE_CSRF_PROTECTION = os.environ.get("DISABLE_CSRF_PROTECTION", "false") == "true"
DISABLE_DOWNLOAD_ENDPOINT_AUTH = (
os.environ.get("DISABLE_DOWNLOAD_ENDPOINT_AUTH", "false") == "true"
)
# SCANS
SCAN_TIMEOUT: Final = int(os.environ.get("SCAN_TIMEOUT", 60 * 60 * 4)) # 4 hours

View File

@@ -1,4 +1,4 @@
from config import ROMM_HOST
from config import ROMM_HOST, DISABLE_DOWNLOAD_ENDPOINT_AUTH
from decorators.auth import protected_route
from models.rom import Rom
from fastapi import APIRouter, Request
@@ -13,7 +13,11 @@ from .responses.feeds import (
router = APIRouter()
@protected_route(router.get, "/webrcade/feed", ["roms.read"])
@protected_route(
router.get,
"/webrcade/feed",
[] if DISABLE_DOWNLOAD_ENDPOINT_AUTH else ["roms.read"],
)
def platforms_webrcade_feed(request: Request) -> WebrcadeFeedSchema:
"""Get webrcade feed endpoint
@@ -47,9 +51,13 @@ def platforms_webrcade_feed(request: Request) -> WebrcadeFeedSchema:
"type": WEBRCADE_SLUG_TO_TYPE_MAP.get(p.slug, p.slug),
"thumbnail": f"{ROMM_HOST}/assets/romm/resources/{rom.path_cover_s}",
"background": f"{ROMM_HOST}/assets/romm/resources/{rom.path_cover_l}",
"props": {"rom": f"{ROMM_HOST}/api/roms/{rom.id}/content/{rom.file_name}"},
"props": {
"rom": f"{ROMM_HOST}/api/roms/{rom.id}/content/{rom.file_name}"
},
}
for rom in session.scalars(db_rom_handler.get_roms(platform_id=p.id)).all()
for rom in session.scalars(
db_rom_handler.get_roms(platform_id=p.id)
).all()
],
}
for p in platforms
@@ -57,6 +65,7 @@ def platforms_webrcade_feed(request: Request) -> WebrcadeFeedSchema:
],
}
@protected_route(router.get, "/tinfoil/feed", ["roms.read"])
def tinfoil_index_feed(request: Request, slug: str = "switch") -> TinfoilFeedSchema:
"""Get tinfoil custom index feed endpoint
@@ -71,7 +80,9 @@ def tinfoil_index_feed(request: Request, slug: str = "switch") -> TinfoilFeedSch
"""
switch = db_platform_handler.get_platform_by_fs_slug(slug)
with db_rom_handler.session.begin() as session:
files: list[Rom] = session.scalars(db_rom_handler.get_roms(platform_id=switch.id)).all()
files: list[Rom] = session.scalars(
db_rom_handler.get_roms(platform_id=switch.id)
).all()
return {
"files": [
@@ -82,5 +93,5 @@ def tinfoil_index_feed(request: Request, slug: str = "switch") -> TinfoilFeedSch
for file in files
],
"directories": [],
"success": "RomM Switch Library"
"success": "RomM Switch Library",
}

View File

@@ -3,7 +3,7 @@ from datetime import datetime
from stat import S_IFREG
from typing import Annotated, Optional
from config import LIBRARY_BASE_PATH
from config import LIBRARY_BASE_PATH, DISABLE_DOWNLOAD_ENDPOINT_AUTH
from decorators.auth import protected_route
from endpoints.responses import MessageResponse
from endpoints.responses.rom import (
@@ -118,7 +118,11 @@ def get_roms(
return paginate(session, qq, cursor_params)
@protected_route(router.get, "/roms/{id}", ["roms.read"])
@protected_route(
router.get,
"/roms/{id}",
[] if DISABLE_DOWNLOAD_ENDPOINT_AUTH else ["roms.read"],
)
def get_rom(request: Request, id: int) -> RomSchema:
"""Get rom endpoint
@@ -132,7 +136,11 @@ def get_rom(request: Request, id: int) -> RomSchema:
return RomSchema.from_orm_with_request(db_rom_handler.get_roms(id), request)
@protected_route(router.head, "/roms/{id}/content/{file_name}", ["roms.read"])
@protected_route(
router.head,
"/roms/{id}/content/{file_name}",
[] if DISABLE_DOWNLOAD_ENDPOINT_AUTH else ["roms.read"],
)
def head_rom_content(request: Request, id: int, file_name: str):
"""Head rom content endpoint