Files
romm/backend/endpoints/responses/feeds.py
Michael Manganiello 95a66a182e misc: Improve typing for feed schemas
* Add typing for nested objects in Tinfoil and Webrcade feed schemas.
* Do not send Rom background and thumbnail, if not available.
* Correctly build URLs using `starlette` utils.
* Deprecate the `ROMM_HOST` setting, no longer needed.
* Fix FastAPI custom router to prefer routes without trailing slash.
* Fix Webrcade background URL pointing to gallery screenshot.
2024-08-07 22:56:16 -03:00

112 lines
2.4 KiB
Python

from typing import NotRequired
from typing_extensions import TypedDict
WEBRCADE_SUPPORTED_PLATFORM_SLUGS = frozenset(
(
"3do",
"arcade",
"atari2600",
"atari5200",
"atari7800",
"colecovision",
"gamegear",
"gb",
"gba",
"gbc",
"genesis-slash-megadrive",
"lynx",
"n64",
"neo-geo-cd",
"neo-geo-pocket",
"neo-geo-pocket-color",
"neogeoaes",
"neogeomvs",
"nes",
"pc-fx",
"ps",
"segacd",
"sg1000",
"sms",
"snes",
"supergrafx",
"turbografx-16-slash-pc-engine-cd",
"turbografx16--1",
"virtualboy",
"wonderswan",
"wonderswan-color",
)
)
WEBRCADE_SLUG_TO_TYPE_MAP = {
"atari2600": "2600",
"atari5200": "5200",
"atari7800": "7800",
"lynx": "lnx",
"turbografx16--1": "pce",
"turbografx-16-slash-pc-engine-cd": "pce",
"supergrafx": "sgx",
"pc-fx": "pcfx",
"virtualboy": "vb",
"genesis-slash-megadrive": "genesis",
"gamegear": "gg",
"neogeoaes": "neogeo",
"neogeomvs": "neogeo",
"neo-geo-cd": "neogeocd",
"neo-geo-pocket": "ngp",
"neo-geo-pocket-color": "ngc",
"ps": "psx",
}
# Webrcade feed format
# Source: https://docs.webrcade.com/feeds/format/
class WebrcadeFeedItemPropsSchema(TypedDict):
rom: str
class WebrcadeFeedItemSchema(TypedDict):
title: str
longTitle: NotRequired[str]
description: NotRequired[str]
type: str
thumbnail: NotRequired[str]
background: NotRequired[str]
props: WebrcadeFeedItemPropsSchema
class WebrcadeFeedCategorySchema(TypedDict):
title: str
longTitle: NotRequired[str]
background: NotRequired[str]
thumbnail: NotRequired[str]
description: NotRequired[str]
items: list[WebrcadeFeedItemSchema]
class WebrcadeFeedSchema(TypedDict):
title: str
longTitle: NotRequired[str]
description: NotRequired[str]
thumbnail: NotRequired[str]
background: NotRequired[str]
categories: list[WebrcadeFeedCategorySchema]
# Tinfoil feed format
# Source: https://blawar.github.io/tinfoil/custom_index/
class TinfoilFeedFileSchema(TypedDict):
url: str
size: int
class TinfoilFeedSchema(TypedDict):
files: list[TinfoilFeedFileSchema]
directories: list[str]
success: NotRequired[str]
error: NotRequired[str]