diff --git a/backend/main.py b/backend/main.py index 9193acc45..9fbce5397 100644 --- a/backend/main.py +++ b/backend/main.py @@ -26,7 +26,7 @@ from handler import dbh from starlette.middleware.authentication import AuthenticationMiddleware from starlette.middleware.sessions import SessionMiddleware from typing_extensions import TypedDict -from utils import get_version +from utils import check_new_version, get_version from utils.auth import ( CustomCSRFMiddleware, HybridAuthBackend, @@ -34,7 +34,7 @@ from utils.auth import ( ) from utils.socket import socket_app -app = FastAPI(title="RomM API", version="0.1.0") +app = FastAPI(title="RomM API", version=get_version()) app.add_middleware( CORSMiddleware, @@ -95,6 +95,7 @@ class SchedulerDict(TypedDict): class HeartbeatReturn(TypedDict): VERSION: str + NEW_VERSION: str | None ROMM_AUTH_ENABLED: bool WATCHER: WatcherDict SCHEDULER: SchedulerDict @@ -110,6 +111,7 @@ def heartbeat() -> HeartbeatReturn: """ return { "VERSION": get_version(), + "NEW_VERSION": check_new_version(), "ROMM_AUTH_ENABLED": ROMM_AUTH_ENABLED, "WATCHER": { "ENABLED": ENABLE_RESCAN_ON_FILESYSTEM_CHANGE, diff --git a/backend/utils/__init__.py b/backend/utils/__init__.py index 5d2956445..f00112d33 100644 --- a/backend/utils/__init__.py +++ b/backend/utils/__init__.py @@ -1,7 +1,9 @@ import re import subprocess as sp +import requests from __version__ import __version__ +from packaging.version import InvalidVersion, parse LANGUAGES = [ ("Ar", "Arabic"), @@ -126,11 +128,11 @@ def normalize_search_term(search_term: str) -> str: def get_file_extension(rom: dict) -> str: - return ( - re.search(EXTENSION_REGEX, rom["file_name"]).group(1) - if not rom["multi"] - else "" - ) + if rom["multi"]: + return "" + + match = re.search(EXTENSION_REGEX, rom["file_name"]) + return match.group(1) if match else "" def get_version() -> str | None: @@ -144,3 +146,19 @@ def get_version() -> str | None: return None branch = [a for a in output.split("\n") if a.find("*") >= 0][0] return branch[branch.find("*") + 2 :] + + +def check_new_version() -> str | None: + response = requests.get( + "https://api.github.com/repos/zurdi15/romm/releases/latest", timeout=0.5 + ) + try: + last_version = response.json()["name"][1:] # remove leading 'v' from 'vX.X.X' + except KeyError: # rate limit reached + return None + try: + if parse(get_version()) < parse(last_version): + return last_version + except InvalidVersion: + pass + return None diff --git a/backend/utils/fs.py b/backend/utils/fs.py index 69fdefe26..ba091ad7b 100644 --- a/backend/utils/fs.py +++ b/backend/utils/fs.py @@ -23,7 +23,6 @@ from config import ( ) from config.config_loader import config from exceptions.fs_exceptions import ( - PlatformNotFoundException, PlatformsNotFoundException, RomAlreadyExistsException, RomNotFoundError, @@ -31,6 +30,8 @@ from exceptions.fs_exceptions import ( ) from PIL import Image +from . import get_file_extension + # ========= Resources utils ========= class CoverSize(Enum): @@ -230,26 +231,26 @@ def get_roms_structure(fs_slug: str): def _exclude_files(files, filetype) -> list[str]: excluded_extensions = config[f"EXCLUDED_{filetype.upper()}_EXT"] excluded_names = config[f"EXCLUDED_{filetype.upper()}_FILES"] - filtered_files: list = [] + excluded_files: list = [] for file in files: # Split the file name to get the extension. - parts = file.split(".") + ext = get_file_extension({"file_name": file, "multi": False}) # Exclude the file if it has no extension or the extension is in the excluded list. - if len(parts) == 1 or parts[-1] in excluded_extensions: - filtered_files.append(file) + if not ext or ext in excluded_extensions: + excluded_files.append(file) # Additionally, check if the file name mathes a pattern in the excluded list. if len(excluded_names) > 0: [ - filtered_files.append(file) + excluded_files.append(file) for name in excluded_names if file == name or fnmatch.fnmatch(file, name) ] # Return files that are not in the filtered list. - return [f for f in files if f not in filtered_files] + return [f for f in files if f not in excluded_files] def _exclude_multi_roms(roms) -> list[str]: diff --git a/frontend/src/components/Drawer/Footer.vue b/frontend/src/components/Drawer/Footer.vue index d87347412..39100c97e 100644 --- a/frontend/src/components/Drawer/Footer.vue +++ b/frontend/src/components/Drawer/Footer.vue @@ -1,11 +1,11 @@