Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: Use immutable types for constants #1392

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions backend/handler/filesystem/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
TAG_REGEX = re.compile(r"\(([^)]+)\)|\[([^]]+)\]")
EXTENSION_REGEX = re.compile(r"\.(([a-z]+\.)*\w+)$")

LANGUAGES = [
LANGUAGES = (
("Ar", "Arabic"),
("Da", "Danish"),
("De", "German"),
Expand All @@ -27,9 +27,9 @@
("Sv", "Swedish"),
("Zh", "Chinese"),
("nolang", "No Language"),
]
)

REGIONS = [
REGIONS = (
("A", "Australia"),
("AS", "Asia"),
("B", "Brazil"),
Expand Down Expand Up @@ -57,13 +57,13 @@
("UNK", "Unknown"),
("UNL", "Unlicensed"),
("W", "World"),
]
)

REGIONS_BY_SHORTCODE = {region[0].lower(): region[1] for region in REGIONS}
REGIONS_NAME_KEYS = [region[1].lower() for region in REGIONS]
REGIONS_NAME_KEYS = frozenset(region[1].lower() for region in REGIONS)

LANGUAGES_BY_SHORTCODE = {lang[0].lower(): lang[1] for lang in LANGUAGES}
LANGUAGES_NAME_KEYS = [lang[1].lower() for lang in LANGUAGES]
LANGUAGES_NAME_KEYS = frozenset(lang[1].lower() for lang in LANGUAGES)


class CoverSize(Enum):
Expand Down
38 changes: 21 additions & 17 deletions backend/handler/filesystem/roms_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,27 @@
FSHandler,
)

# list of known compressed file MIME types
COMPRESSED_MIME_TYPES: Final = [
"application/zip",
"application/x-tar",
"application/x-gzip",
"application/x-7z-compressed",
"application/x-bzip2",
]

# list of known file extensions that are compressed
COMPRESSED_FILE_EXTENSIONS = [
".zip",
".tar",
".gz",
".7z",
".bz2",
]
# Known compressed file MIME types
COMPRESSED_MIME_TYPES: Final = frozenset(
(
"application/x-7z-compressed",
"application/x-bzip2",
"application/x-gzip",
"application/x-tar",
"application/zip",
)
)

# Known file extensions that are compressed
COMPRESSED_FILE_EXTENSIONS = frozenset(
(
".7z",
".bz2",
".gz",
".tar",
".zip",
)
)

FILE_READ_CHUNK_SIZE = 1024 * 8

Expand Down
14 changes: 7 additions & 7 deletions backend/handler/metadata/igdb_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ async def get_oauth_token(self) -> str:
return token


PLATFORMS_FIELDS = [
PLATFORMS_FIELDS = (
"id",
"name",
"category",
Expand All @@ -730,9 +730,9 @@ async def get_oauth_token(self) -> str:
"platform_family.name",
"platform_family.slug",
"platform_logo.url",
]
)

GAMES_FIELDS = [
GAMES_FIELDS = (
"id",
"name",
"slug",
Expand Down Expand Up @@ -782,17 +782,17 @@ async def get_oauth_token(self) -> str:
"similar_games.cover.url",
"age_ratings.rating",
"videos.video_id",
]
)

SEARCH_FIELDS = ["game.id", "name"]
SEARCH_FIELDS = ("game.id", "name")

# Generated from the following code on https://www.igdb.com/platforms/:
# Array.from(document.querySelectorAll(".media-body a")).map(a => ({
# slug: a.href.split("/")[4],
# name: a.innerText
# }))

IGDB_PLATFORM_LIST = [
IGDB_PLATFORM_LIST = (
{"slug": "visionos", "name": "visionOS"},
{"slug": "meta-quest-3", "name": "Meta Quest 3"},
{"slug": "atari2600", "name": "Atari 2600"},
Expand Down Expand Up @@ -1009,7 +1009,7 @@ async def get_oauth_token(self) -> str:
{"slug": "onlive-game-system", "name": "OnLive Game System"},
{"slug": "vc", "name": "Virtual Console"},
{"slug": "airconsole", "name": "AirConsole"},
]
)

IGDB_PLATFORM_CATEGORIES: dict[int, str] = {
0: "Unknown",
Expand Down
58 changes: 30 additions & 28 deletions backend/handler/scan_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,36 @@
from models.rom import Rom
from models.user import User

NON_HASHABLE_PLATFORMS = [
"pc",
"win",
"mac",
"linux",
"switch",
"ps3",
"ps4",
"ps4--1",
"ps5",
"wiiu",
"xbox-360",
"xboxone",
"series-x",
"android",
"ios",
"ipad",
"amazon-alexa",
"amazon-fire-tv",
"gear-vr",
"meta-quest-2",
"meta-quest-3",
"oculus-go",
"oculus-quest",
"oculus-rift",
"psvr",
"psvr2",
]
NON_HASHABLE_PLATFORMS = frozenset(
(
"amazon-alexa",
"amazon-fire-tv",
"android",
"gear-vr",
"ios",
"ipad",
"linux",
"mac",
"meta-quest-2",
"meta-quest-3",
"oculus-go",
"oculus-quest",
"oculus-rift",
"pc",
"ps3",
"ps4",
"ps4--1",
"ps5",
"psvr",
"psvr2",
"series-x",
"switch",
"wiiu",
"win",
"xbox-360",
"xboxone",
)
)


class ScanType(Enum):
Expand Down
Loading