From 6e665af8ddc3ea210c41f73c5018a306fc430299 Mon Sep 17 00:00:00 2001 From: Zurdi Date: Fri, 19 Jan 2024 10:44:59 +0100 Subject: [PATCH 01/10] config file is created automatically if not exists at startup --- backend/config/config_manager.py | 42 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/backend/config/config_manager.py b/backend/config/config_manager.py index 8b87cfa96..ef2ad7395 100644 --- a/backend/config/config_manager.py +++ b/backend/config/config_manager.py @@ -1,14 +1,11 @@ import os import sys +from pathlib import Path from typing import Final from urllib.parse import quote_plus import pydash import yaml -from exceptions.config_exceptions import ( - ConfigNotWritableException, - ConfigNotReadableException, -) from config import ( DB_HOST, DB_NAME, @@ -19,10 +16,15 @@ from config import ( ROMM_BASE_PATH, ROMM_DB_DRIVER, ) +from exceptions.config_exceptions import ( + ConfigNotReadableException, + ConfigNotWritableException, +) from logger.logger import log from yaml.loader import SafeLoader -ROMM_USER_CONFIG_PATH: Final = f"{ROMM_BASE_PATH}/config.yml" +ROMM_USER_CONFIG_PATH: Final = f"{ROMM_BASE_PATH}/config" +ROMM_USER_CONFIG_FILE: Final = f"{ROMM_USER_CONFIG_PATH}/config.yml" SQLITE_DB_BASE_PATH: Final = f"{ROMM_BASE_PATH}/database" @@ -61,13 +63,13 @@ class ConfigManager: return cls._self # Tests require custom config path - def __init__(self, config_path: str = ROMM_USER_CONFIG_PATH): - self.config_path = config_path - if os.path.isdir(config_path): - log.critical( - f"Your config file {config_path} is a directory, not a file. Docker creates folders by default for binded files that doesn't exists in advance in the host system." - ) - raise FileNotFoundError() + def __init__(self, config_file: str = ROMM_USER_CONFIG_FILE): + self.config_file = config_file + # If config file doesn't exists, create an empty one + if not os.path.exists(config_file): + Path(ROMM_USER_CONFIG_PATH).mkdir(parents=True, exist_ok=True) + with open(config_file, "w") as file: + file.write("") try: self.read_config() except ConfigNotReadableException as e: @@ -96,7 +98,9 @@ class ConfigManager: # DEPRECATED if ROMM_DB_DRIVER == "sqlite": - log.critical("Sqlite is not supported anymore, change to MariaDB is needed.") + log.critical( + "Sqlite is not supported anymore, change to MariaDB is needed." + ) sys.exit(6) # DEPRECATED @@ -231,7 +235,7 @@ class ConfigManager: def read_config(self) -> None: try: - with open(self.config_path) as config_file: + with open(self.config_file) as config_file: self._raw_config = yaml.load(config_file, Loader=SafeLoader) or {} except FileNotFoundError: self._raw_config = {} @@ -243,7 +247,7 @@ class ConfigManager: def update_config(self) -> None: try: - with open(self.config_path, "w") as config_file: + with open(self.config_file, "w") as config_file: yaml.dump(self._raw_config, config_file) except FileNotFoundError: self._raw_config = {} @@ -254,6 +258,14 @@ class ConfigManager: self._parse_config() def add_binding(self, fs_slug: str, slug: str) -> None: + try: + _ = self._raw_config["system"] + except KeyError: + self._raw_config = {"system": {"platforms": {}}} + try: + _ = self._raw_config["system"]["platforms"] + except KeyError: + self._raw_config["system"]["platforms"] = {} self._raw_config["system"]["platforms"][fs_slug] = slug self.update_config() From e231d1b73ecbd297def8a36e41484fcd289a8e53 Mon Sep 17 00:00:00 2001 From: Zurdi Date: Fri, 19 Jan 2024 13:17:52 +0100 Subject: [PATCH 02/10] added platform versions support --- .gitignore | 1 + backend/config/config_manager.py | 32 +++++ backend/endpoints/config.py | 36 +++++ backend/endpoints/responses/config.py | 1 + backend/endpoints/responses/search.py | 4 +- backend/handler/igdb_handler.py | 38 +++-- backend/handler/scan_handler.py | 61 ++++++-- examples/docker-compose.example.yml | 2 +- frontend/src/__generated__/index.ts | 2 +- .../__generated__/models/ConfigResponse.ts | 1 + .../models/{IGDBRomType.ts => IGDBRom.ts} | 2 +- .../__generated__/models/RomSearchResponse.ts | 4 +- .../Dialog/Config/CreatePlatformVersion.vue | 104 ++++++++++++++ .../Dialog/Config/DeletePlatformVersion.vue | 97 +++++++++++++ .../Settings/Config/PlatformVersionsCard.vue | 133 ++++++++++++++++++ frontend/src/services/api_config.ts | 20 +++ frontend/src/stores/config.ts | 6 + frontend/src/types/emitter.d.ts | 8 ++ .../Settings/ControlPanel/Config/Base.vue | 2 + 19 files changed, 520 insertions(+), 34 deletions(-) rename frontend/src/__generated__/models/{IGDBRomType.ts => IGDBRom.ts} (90%) create mode 100644 frontend/src/components/Dialog/Config/CreatePlatformVersion.vue create mode 100644 frontend/src/components/Dialog/Config/DeletePlatformVersion.vue create mode 100644 frontend/src/components/Settings/Config/PlatformVersionsCard.vue diff --git a/.gitignore b/.gitignore index ac9ce7197..93aad4671 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ romm_mock # testing backend/romm_test/resources backend/romm_test/logs +backend/romm_test/config .pytest_cache # service worker diff --git a/backend/config/config_manager.py b/backend/config/config_manager.py index ef2ad7395..9933eeb49 100644 --- a/backend/config/config_manager.py +++ b/backend/config/config_manager.py @@ -36,6 +36,7 @@ class Config: EXCLUDED_MULTI_PARTS_EXT: list[str] EXCLUDED_MULTI_PARTS_FILES: list[str] PLATFORMS_BINDING: dict[str, str] + PLATFORMS_VERSIONS: dict[str, str] ROMS_FOLDER_NAME: str SAVES_FOLDER_NAME: str STATES_FOLDER_NAME: str @@ -128,6 +129,7 @@ class ConfigManager: self._raw_config, "exclude.roms.multi_file.parts.names", [] ), PLATFORMS_BINDING=pydash.get(self._raw_config, "system.platforms", {}), + PLATFORMS_VERSIONS=pydash.get(self._raw_config, "system.versions", {}), ROMS_FOLDER_NAME=pydash.get( self._raw_config, "filesystem.roms_folder", "roms" ), @@ -189,6 +191,17 @@ class ConfigManager: ) sys.exit(3) + if not isinstance(self.config.PLATFORMS_VERSIONS, dict): + log.critical("Invalid config.yml: system.versions must be a dictionary") + sys.exit(3) + else: + for fs_slug, slug in self.config.PLATFORMS_VERSIONS.items(): + if slug is None: + log.critical( + f"Invalid config.yml: system.versions.{fs_slug} must be a string" + ) + sys.exit(3) + if not isinstance(self.config.ROMS_FOLDER_NAME, str): log.critical("Invalid config.yml: filesystem.roms_folder must be a string") sys.exit(3) @@ -276,6 +289,25 @@ class ConfigManager: pass self.update_config() + def add_version(self, fs_slug: str, slug: str) -> None: + try: + _ = self._raw_config["system"] + except KeyError: + self._raw_config = {"system": {"versions": {}}} + try: + _ = self._raw_config["system"]["versions"] + except KeyError: + self._raw_config["system"]["versions"] = {} + self._raw_config["system"]["versions"][fs_slug] = slug + self.update_config() + + def remove_version(self, fs_slug: str) -> None: + try: + del self._raw_config["system"]["versions"][fs_slug] + except KeyError: + pass + self.update_config() + # def _get_exclude_path(self, exclude): # exclude_base = self._raw_config["exclude"] # exclusions = { diff --git a/backend/endpoints/config.py b/backend/endpoints/config.py index 54a19f688..e8c45ce3f 100644 --- a/backend/endpoints/config.py +++ b/backend/endpoints/config.py @@ -67,6 +67,42 @@ async def delete_platform_binding(request: Request, fs_slug: str) -> MessageResp return {"msg": f"{fs_slug} bind removed successfully!"} +@protected_route(router.post, "/config/system/versions", ["platforms.write"]) +async def add_platform_version(request: Request) -> MessageResponse: + """Add platform version to the configuration""" + + data = await request.json() + fs_slug = data["fs_slug"] + slug = data["slug"] + + try: + cm.add_version(fs_slug, slug) + except ConfigNotWritableException as e: + log.critical(e.message) + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=e.message + ) + + return {"msg": f"Added {fs_slug} as version of: {slug} successfully!"} + + +@protected_route( + router.delete, "/config/system/versions/{fs_slug}", ["platforms.write"] +) +async def delete_platform_version(request: Request, fs_slug: str) -> MessageResponse: + """Delete platform version from the configuration""" + + try: + cm.remove_version(fs_slug) + except ConfigNotWritableException as e: + log.critical(e.message) + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=e.message + ) + + return {"msg": f"{fs_slug} version removed successfully!"} + + # @protected_route(router.post, "/config/exclude", ["platforms.write"]) # async def add_exclusion(request: Request) -> MessageResponse: # """Add platform binding to the configuration""" diff --git a/backend/endpoints/responses/config.py b/backend/endpoints/responses/config.py index 9bc53ba08..e9714c932 100644 --- a/backend/endpoints/responses/config.py +++ b/backend/endpoints/responses/config.py @@ -9,6 +9,7 @@ class ConfigResponse(TypedDict): EXCLUDED_MULTI_PARTS_EXT: list[str] EXCLUDED_MULTI_PARTS_FILES: list[str] PLATFORMS_BINDING: dict[str, str] + PLATFORMS_VERSIONS: dict[str, str] ROMS_FOLDER_NAME: str SAVES_FOLDER_NAME: str STATES_FOLDER_NAME: str diff --git a/backend/endpoints/responses/search.py b/backend/endpoints/responses/search.py index 65e146e3e..68e08e71c 100644 --- a/backend/endpoints/responses/search.py +++ b/backend/endpoints/responses/search.py @@ -1,7 +1,7 @@ -from handler.igdb_handler import IGDBRomType +from handler.igdb_handler import IGDBRom from typing_extensions import TypedDict class RomSearchResponse(TypedDict): msg: str - roms: list[IGDBRomType] + roms: list[IGDBRom] diff --git a/backend/handler/igdb_handler.py b/backend/handler/igdb_handler.py index 18652c55b..78b85cfa5 100644 --- a/backend/handler/igdb_handler.py +++ b/backend/handler/igdb_handler.py @@ -43,12 +43,12 @@ SWITCH_PRODUCT_ID_FILE: Final = os.path.join( MAME_XML_FILE: Final = os.path.join(os.path.dirname(__file__), "fixtures", "mame.xml") -class IGDBPlatformType(TypedDict): +class IGDBPlatform(TypedDict): igdb_id: int name: str -class IGDBRomType(TypedDict): +class IGDBRom(TypedDict): igdb_id: int slug: str name: str @@ -60,6 +60,7 @@ class IGDBRomType(TypedDict): class IGDBHandler: def __init__(self) -> None: self.platform_url = "https://api.igdb.com/v4/platforms/" + self.platform_version_url = "https://api.igdb.com/v4/platform_versions/" self.games_url = "https://api.igdb.com/v4/games/" self.covers_url = "https://api.igdb.com/v4/covers/" self.screenshots_url = "https://api.igdb.com/v4/screenshots/" @@ -263,23 +264,36 @@ class IGDBHandler: return search_term @check_twitch_token - def get_platform(self, slug: str) -> IGDBPlatformType: + def get_platform(self, slug: str) -> IGDBPlatform: platforms = self._request( self.platform_url, data=f'fields id, name; where slug="{slug.lower()}";', ) platform = pydash.get(platforms, "[0]", None) - if not platform: - return IGDBPlatformType(igdb_id=None, name=slug.replace("-", " ").title()) - return IGDBPlatformType( + # Check if platform is a version if not found + if not platform: + platform_versions = self._request( + self.platform_version_url, + data=f'fields id, name; where slug="{slug.lower()}";', + ) + version = pydash.get(platform_versions, "[0]", None) + if not version: + return IGDBPlatform(igdb_id=None, igdb_id_base_platform=None, name=slug.replace("-", " ").title()) + + return IGDBPlatform( + igdb_id=version["id"], + name=version["name"], + ) + + return IGDBPlatform( igdb_id=platform["id"], name=platform["name"], ) @check_twitch_token - async def get_rom(self, file_name: str, platform_idgb_id: int) -> IGDBRomType: + async def get_rom(self, file_name: str, platform_idgb_id: int) -> IGDBRom: from handler import fs_rom_handler search_term = fs_rom_handler.get_file_name_with_no_tags(file_name) @@ -314,7 +328,7 @@ class IGDBHandler: ) igdb_id = res.get("id", None) - rom = IGDBRomType( + rom = IGDBRom( igdb_id=igdb_id, slug=res.get("slug", ""), name=res.get("name", search_term), @@ -330,7 +344,7 @@ class IGDBHandler: return rom @check_twitch_token - def get_rom_by_id(self, igdb_id: int) -> IGDBRomType: + def get_rom_by_id(self, igdb_id: int) -> IGDBRom: roms = self._request( self.games_url, f"fields slug, name, summary; where id={igdb_id};", @@ -347,7 +361,7 @@ class IGDBHandler: } @check_twitch_token - def get_matched_roms_by_id(self, igdb_id: int) -> list[IGDBRomType]: + def get_matched_roms_by_id(self, igdb_id: int) -> list[IGDBRom]: matched_rom = self.get_rom_by_id(igdb_id) matched_rom.update( url_cover=matched_rom["url_cover"].replace("t_thumb", "t_cover_big"), @@ -357,7 +371,7 @@ class IGDBHandler: @check_twitch_token def get_matched_roms_by_name( self, search_term: str, platform_idgb_id: int - ) -> list[IGDBRomType]: + ) -> list[IGDBRom]: if not platform_idgb_id: return [] @@ -371,7 +385,7 @@ class IGDBHandler: ) return [ - IGDBRomType( + IGDBRom( igdb_id=rom["id"], slug=rom["slug"], name=rom["name"], diff --git a/backend/handler/scan_handler.py b/backend/handler/scan_handler.py index 15390b07f..d75ee5f39 100644 --- a/backend/handler/scan_handler.py +++ b/backend/handler/scan_handler.py @@ -1,17 +1,38 @@ import os from typing import Any -import emoji +import emoji from config.config_manager import config_manager as cm -from handler import fs_asset_handler, igdb_handler, fs_resource_handler, fs_rom_handler, db_platform_handler +from handler import ( + db_platform_handler, + fs_asset_handler, + fs_resource_handler, + fs_rom_handler, + igdb_handler, +) from logger.logger import log +from models.assets import Save, Screenshot, State from models.platform import Platform from models.rom import Rom -from models.assets import Save, Screenshot, State -SWAPPED_PLATFORM_BINDINGS = dict( - (v, k) for k, v in cm.config.PLATFORMS_BINDING.items() -) +SWAPPED_PLATFORM_BINDINGS = dict((v, k) for k, v in cm.config.PLATFORMS_BINDING.items()) + + +def _get_main_platform_igdb_id(platform: Platform): + if platform.fs_slug in cm.config.PLATFORMS_VERSIONS.keys(): + main_platform_slug = cm.config.PLATFORMS_VERSIONS[platform.fs_slug] + main_platform = db_platform_handler.get_platform_by_slug(main_platform_slug) + if main_platform: + main_platform_igdb_id = main_platform.igdb_id + else: + main_platform_igdb_id = igdb_handler.get_platform(main_platform_slug)[ + "igdb_id" + ] + if not main_platform_igdb_id: + main_platform_igdb_id = platform.igdb_id + else: + main_platform_igdb_id = platform.igdb_id + return main_platform_igdb_id def scan_platform(fs_slug: str, fs_platforms) -> Platform: @@ -51,7 +72,9 @@ def scan_platform(fs_slug: str, fs_platforms) -> Platform: if platform["igdb_id"]: log.info(emoji.emojize(f" Identified as {platform['name']} :video_game:")) else: - log.warning(emoji.emojize(f" {platform_attrs['slug']} not found in IGDB :cross_mark:")) + log.warning( + emoji.emojize(f" {platform_attrs['slug']} not found in IGDB :cross_mark:") + ) platform_attrs.update(platform) @@ -85,8 +108,12 @@ async def scan_rom( "platform_id": platform.id, "file_path": roms_path, "file_name": rom_attrs["file_name"], - "file_name_no_tags": fs_rom_handler.get_file_name_with_no_tags(rom_attrs["file_name"]), - "file_extension": fs_rom_handler.parse_file_extension(rom_attrs["file_name"]), + "file_name_no_tags": fs_rom_handler.get_file_name_with_no_tags( + rom_attrs["file_name"] + ), + "file_extension": fs_rom_handler.parse_file_extension( + rom_attrs["file_name"] + ), "file_size_bytes": file_size, "multi": rom_attrs["multi"], "regions": regs, @@ -96,11 +123,13 @@ async def scan_rom( } ) + main_platform_igdb_id = _get_main_platform_igdb_id(platform) + # Search in IGDB igdb_handler_rom = ( igdb_handler.get_rom_by_id(int(r_igbd_id_search)) if r_igbd_id_search - else await igdb_handler.get_rom(rom_attrs["file_name"], platform.igdb_id) + else await igdb_handler.get_rom(rom_attrs["file_name"], main_platform_igdb_id) ) rom_attrs.update(igdb_handler_rom) @@ -108,11 +137,15 @@ async def scan_rom( # Return early if not found in IGDB if not igdb_handler_rom["igdb_id"]: log.warning( - emoji.emojize(f"\t {r_igbd_id_search or rom_attrs['file_name']} not found in IGDB :cross_mark:") + emoji.emojize( + f"\t {r_igbd_id_search or rom_attrs['file_name']} not found in IGDB :cross_mark:" + ) ) return Rom(**rom_attrs) - log.info(emoji.emojize(f"\t Identified as {igdb_handler_rom['name']} :alien_monster:")) + log.info( + emoji.emojize(f"\t Identified as {igdb_handler_rom['name']} :alien_monster:") + ) # Update properties from IGDB rom_attrs.update( @@ -180,6 +213,4 @@ def scan_screenshot(file_name: str, platform_slug: Platform = None) -> Screensho if platform_slug: return Screenshot(**_scan_asset(file_name, screenshots_path)) - return Screenshot( - **_scan_asset(file_name, cm.config.SCREENSHOTS_FOLDER_NAME) - ) + return Screenshot(**_scan_asset(file_name, cm.config.SCREENSHOTS_FOLDER_NAME)) diff --git a/examples/docker-compose.example.yml b/examples/docker-compose.example.yml index 56d379437..5af89a814 100644 --- a/examples/docker-compose.example.yml +++ b/examples/docker-compose.example.yml @@ -41,7 +41,7 @@ services: volumes: - "/path/to/library:/romm/library" - "/path/to/resources:/romm/resources" # [Optional] Path where roms metadata (covers) are stored - - "/path/to/config.yml:/romm/config.yml" # [Optional] Path where config is stored + - "/path/to/config:/romm/config" # [Optional] Path where config is stored - "/path/to/database:/romm/database" # [Optional] Only needed if ROMM_DB_DRIVER=sqlite or not set - "/path/to/logs:/romm/logs" # [Optional] Path where logs are stored ports: diff --git a/frontend/src/__generated__/index.ts b/frontend/src/__generated__/index.ts index 00e6a80f6..7b74bfcbb 100644 --- a/frontend/src/__generated__/index.ts +++ b/frontend/src/__generated__/index.ts @@ -15,7 +15,7 @@ export type { CursorPage_RomSchema_ } from './models/CursorPage_RomSchema_'; export type { EnhancedRomSchema } from './models/EnhancedRomSchema'; export type { HeartbeatResponse } from './models/HeartbeatResponse'; export type { HTTPValidationError } from './models/HTTPValidationError'; -export type { IGDBRomType } from './models/IGDBRomType'; +export type { IGDBRom } from './models/IGDBRom'; export type { MessageResponse } from './models/MessageResponse'; export type { PlatformSchema } from './models/PlatformSchema'; export type { Role } from './models/Role'; diff --git a/frontend/src/__generated__/models/ConfigResponse.ts b/frontend/src/__generated__/models/ConfigResponse.ts index 0a65c4f0f..b8d852fd6 100644 --- a/frontend/src/__generated__/models/ConfigResponse.ts +++ b/frontend/src/__generated__/models/ConfigResponse.ts @@ -11,6 +11,7 @@ export type ConfigResponse = { EXCLUDED_MULTI_PARTS_EXT: Array; EXCLUDED_MULTI_PARTS_FILES: Array; PLATFORMS_BINDING: Record; + PLATFORMS_VERSIONS: Record; ROMS_FOLDER_NAME: string; SAVES_FOLDER_NAME: string; STATES_FOLDER_NAME: string; diff --git a/frontend/src/__generated__/models/IGDBRomType.ts b/frontend/src/__generated__/models/IGDBRom.ts similarity index 90% rename from frontend/src/__generated__/models/IGDBRomType.ts rename to frontend/src/__generated__/models/IGDBRom.ts index cb0c1e221..8d23bfccb 100644 --- a/frontend/src/__generated__/models/IGDBRomType.ts +++ b/frontend/src/__generated__/models/IGDBRom.ts @@ -3,7 +3,7 @@ /* tslint:disable */ /* eslint-disable */ -export type IGDBRomType = { +export type IGDBRom = { igdb_id: number; slug: string; name: string; diff --git a/frontend/src/__generated__/models/RomSearchResponse.ts b/frontend/src/__generated__/models/RomSearchResponse.ts index 2d4261e63..cf5404a84 100644 --- a/frontend/src/__generated__/models/RomSearchResponse.ts +++ b/frontend/src/__generated__/models/RomSearchResponse.ts @@ -3,10 +3,10 @@ /* tslint:disable */ /* eslint-disable */ -import type { IGDBRomType } from './IGDBRomType'; +import type { IGDBRom } from './IGDBRom'; export type RomSearchResponse = { msg: string; - roms: Array; + roms: Array; }; diff --git a/frontend/src/components/Dialog/Config/CreatePlatformVersion.vue b/frontend/src/components/Dialog/Config/CreatePlatformVersion.vue new file mode 100644 index 000000000..f3292a8f1 --- /dev/null +++ b/frontend/src/components/Dialog/Config/CreatePlatformVersion.vue @@ -0,0 +1,104 @@ + + diff --git a/frontend/src/components/Dialog/Config/DeletePlatformVersion.vue b/frontend/src/components/Dialog/Config/DeletePlatformVersion.vue new file mode 100644 index 000000000..c52d15403 --- /dev/null +++ b/frontend/src/components/Dialog/Config/DeletePlatformVersion.vue @@ -0,0 +1,97 @@ + + diff --git a/frontend/src/components/Settings/Config/PlatformVersionsCard.vue b/frontend/src/components/Settings/Config/PlatformVersionsCard.vue new file mode 100644 index 000000000..d71e912ee --- /dev/null +++ b/frontend/src/components/Settings/Config/PlatformVersionsCard.vue @@ -0,0 +1,133 @@ + + + + diff --git a/frontend/src/services/api_config.ts b/frontend/src/services/api_config.ts index 200c0ea23..0a7507096 100644 --- a/frontend/src/services/api_config.ts +++ b/frontend/src/services/api_config.ts @@ -21,6 +21,24 @@ async function deletePlatformBindConfig({ return api.delete(`/config/system/platforms/${fsSlug}`); } +async function addPlatformVersionConfig({ + fsSlug, + slug, +}: { + fsSlug: string; + slug: string; +}): Promise<{ data: MessageResponse }> { + return api.post("/config/system/versions", { fs_slug: fsSlug, slug: slug }); +} + +async function deletePlatformVersionConfig({ + fsSlug, +}: { + fsSlug: string; +}): Promise<{ data: MessageResponse }> { + return api.delete(`/config/system/versions/${fsSlug}`); +} + async function addExclusion({ exclude, exclusion, @@ -37,5 +55,7 @@ async function addExclusion({ export default { addPlatformBindConfig, deletePlatformBindConfig, + addPlatformVersionConfig, + deletePlatformVersionConfig, addExclusion, }; diff --git a/frontend/src/stores/config.ts b/frontend/src/stores/config.ts index 814946763..d7a10abb7 100644 --- a/frontend/src/stores/config.ts +++ b/frontend/src/stores/config.ts @@ -17,5 +17,11 @@ export default defineStore("config", { removePlatformBinding(fsSlug: string) { delete this.value.PLATFORMS_BINDING[fsSlug]; }, + addPlatformVersion(fsSlug: string, slug: string) { + this.value.PLATFORMS_VERSIONS[fsSlug] = slug; + }, + removePlatformVersion(fsSlug: string) { + delete this.value.PLATFORMS_VERSIONS[fsSlug]; + }, }, }); diff --git a/frontend/src/types/emitter.d.ts b/frontend/src/types/emitter.d.ts index 79fa0c9b1..f4befdeb5 100644 --- a/frontend/src/types/emitter.d.ts +++ b/frontend/src/types/emitter.d.ts @@ -30,6 +30,14 @@ export type Events = { fsSlug: string; slug: string; }; + showCreatePlatformVersionDialog: { + fsSlug: string; + slug: string; + }; + showDeletePlatformVersionDialog: { + fsSlug: string; + slug: string; + }; showCreateExclusionDialog: { exclude: string }; showCreateUserDialog: null; showEditUserDialog: UserItem; diff --git a/frontend/src/views/Settings/ControlPanel/Config/Base.vue b/frontend/src/views/Settings/ControlPanel/Config/Base.vue index a56920f9e..7dfe4ea2b 100644 --- a/frontend/src/views/Settings/ControlPanel/Config/Base.vue +++ b/frontend/src/views/Settings/ControlPanel/Config/Base.vue @@ -1,9 +1,11 @@ From 720a9617bcb6863edae0c53b150cfc0fd4afecc9 Mon Sep 17 00:00:00 2001 From: Zurdi Date: Fri, 19 Jan 2024 15:10:01 +0100 Subject: [PATCH 03/10] fixed unit tests --- backend/config/empty_config.yml | 0 .../tests/fixtures/{ => config}/config.yml | 2 + .../tests/fixtures/config/empty_config.yml | 0 backend/config/tests/test_config_loader.py | 6 +- backend/handler/igdb_handler.py | 2 +- .../tests/cassettes/test_get_platform.yaml | 326 ++++++++++++++++-- .../tests/cassettes/test_get_ps2_opl_rom.yaml | 180 +++++----- .../tests/cassettes/test_scan_platform.yaml | 324 +++++++++++++++-- 8 files changed, 704 insertions(+), 136 deletions(-) create mode 100644 backend/config/empty_config.yml rename backend/config/tests/fixtures/{ => config}/config.yml (94%) create mode 100644 backend/config/tests/fixtures/config/empty_config.yml diff --git a/backend/config/empty_config.yml b/backend/config/empty_config.yml new file mode 100644 index 000000000..e69de29bb diff --git a/backend/config/tests/fixtures/config.yml b/backend/config/tests/fixtures/config/config.yml similarity index 94% rename from backend/config/tests/fixtures/config.yml rename to backend/config/tests/fixtures/config/config.yml index 9846fa7bd..a2abe91ba 100644 --- a/backend/config/tests/fixtures/config.yml +++ b/backend/config/tests/fixtures/config/config.yml @@ -23,6 +23,8 @@ exclude: system: platforms: gc: 'ngc' + versions: + naomi: 'arcade' filesystem: roms_folder: 'ROMS' diff --git a/backend/config/tests/fixtures/config/empty_config.yml b/backend/config/tests/fixtures/config/empty_config.yml new file mode 100644 index 000000000..e69de29bb diff --git a/backend/config/tests/test_config_loader.py b/backend/config/tests/test_config_loader.py index 50b5ce62a..35d563534 100644 --- a/backend/config/tests/test_config_loader.py +++ b/backend/config/tests/test_config_loader.py @@ -6,7 +6,7 @@ from config.config_manager import ConfigManager def test_config_loader(): loader = ConfigManager( - os.path.join(Path(__file__).resolve().parent, "fixtures", "config.yml") + os.path.join(Path(__file__).resolve().parent, "fixtures", "config/config.yml") ) assert loader.config.EXCLUDED_PLATFORMS == ["romm"] @@ -16,6 +16,7 @@ def test_config_loader(): assert loader.config.EXCLUDED_MULTI_PARTS_EXT == ["txt"] assert loader.config.EXCLUDED_MULTI_PARTS_FILES == ["data.xml"] assert loader.config.PLATFORMS_BINDING == {"gc": "ngc"} + assert loader.config.PLATFORMS_VERSIONS == {"naomi": "arcade"} assert loader.config.ROMS_FOLDER_NAME == "ROMS" assert loader.config.SAVES_FOLDER_NAME == "SAVES" assert loader.config.STATES_FOLDER_NAME == "STATES" @@ -23,7 +24,7 @@ def test_config_loader(): def test_empty_config_loader(): - loader = ConfigManager("") + loader = ConfigManager("config/empty_config.yml") assert loader.config.EXCLUDED_PLATFORMS == [] assert loader.config.EXCLUDED_SINGLE_EXT == [] @@ -32,6 +33,7 @@ def test_empty_config_loader(): assert loader.config.EXCLUDED_MULTI_PARTS_EXT == [] assert loader.config.EXCLUDED_MULTI_PARTS_FILES == [] assert loader.config.PLATFORMS_BINDING == {} + assert loader.config.PLATFORMS_VERSIONS == {} assert loader.config.ROMS_FOLDER_NAME == "roms" assert loader.config.SAVES_FOLDER_NAME == "saves" assert loader.config.STATES_FOLDER_NAME == "states" diff --git a/backend/handler/igdb_handler.py b/backend/handler/igdb_handler.py index 78b85cfa5..4d2bc754b 100644 --- a/backend/handler/igdb_handler.py +++ b/backend/handler/igdb_handler.py @@ -280,7 +280,7 @@ class IGDBHandler: ) version = pydash.get(platform_versions, "[0]", None) if not version: - return IGDBPlatform(igdb_id=None, igdb_id_base_platform=None, name=slug.replace("-", " ").title()) + return IGDBPlatform(igdb_id=None, name=slug.replace("-", " ").title()) return IGDBPlatform( igdb_id=version["id"], diff --git a/backend/handler/tests/cassettes/test_get_platform.yaml b/backend/handler/tests/cassettes/test_get_platform.yaml index bfa54cc67..21b9546a6 100644 --- a/backend/handler/tests/cassettes/test_get_platform.yaml +++ b/backend/handler/tests/cassettes/test_get_platform.yaml @@ -7,7 +7,114 @@ interactions: Accept-Encoding: - gzip, deflate Authorization: - - Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + - Bearer test_token + Client-ID: + - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Connection: + - keep-alive + Content-Length: + - '34' + User-Agent: + - python-requests/2.31.0 + method: POST + uri: https://api.igdb.com/v4/platforms/ + response: + body: + string: "{\n \"message\": \"Authorization Failure. Have you tried:\",\n \"Tip + 1\": \"Ensure you are sending Authorization and Client-ID as headers.\",\n + \ \"Tip 2\": \"Ensure Authorization value starts with 'Bearer ', including + the space\",\n \"Tip 3\": \"Ensure Authorization value ends with the App + Access Token you generated, NOT your Client Secret.\",\n \"Docs\": \"https://api-docs.igdb.com/#authentication\",\n + \ \"Discord\": \"https://discord.gg/FrvfwQg\"\n}\n" + headers: + CF-Cache-Status: + - DYNAMIC + CF-RAY: + - 847f78ab4a7a5aa7-VIE + Connection: + - keep-alive + Content-Length: + - '437' + Content-Type: + - application/json + Date: + - Fri, 19 Jan 2024 13:37:16 GMT + Server: + - cloudflare + Set-Cookie: + - __cf_bm=ZVbN2keB5NG5FaeoRyKaEvTQBmMdm6YLBvSWV5NgLKQ-1705671436-1-Aag20MSVQtClvha5FrIikBY1ZlgjwbLC9Gww0y/AREeyexQsUS7ppX9MgAzkE1IuM9uki15DGzUjl0+uJQYwXkE=; + path=/; expires=Fri, 19-Jan-24 14:07:16 GMT; domain=.igdb.com; HttpOnly; Secure; + SameSite=None + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Via: + - 1.1 ba761cfda8bfa6cbda2b6c433d6201f6.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - XecUo2xyRCkspvzhpxmMVNSXlvTjAnDL7NiycL747Ev0-SMhNnAUJA== + X-Amz-Cf-Pop: + - VIE50-C2 + X-Cache: + - Error from cloudfront + X-Content-Type-Options: + - nosniff + alt-svc: + - h3=":443"; ma=86400 + x-amz-apigw-id: + - Rygp8FT2PHcEUiw= + x-amzn-ErrorType: + - AccessDeniedException + x-amzn-RequestId: + - 95bd8829-ef4f-4432-bd7d-9ccaf436f56a + status: + code: 401 + message: Unauthorized +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + User-Agent: + - python-requests/2.31.0 + method: POST + uri: https://id.twitch.tv/oauth2/token?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials + response: + body: + string: '{"access_token":"88ukw5q2sqlhctxykq8s8t97iql9yo","expires_in":5080333,"token_type":"bearer"} + + ' + headers: + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '93' + Content-Type: + - application/json + Date: + - Fri, 19 Jan 2024 13:37:17 GMT + Server: + - nginx + X-Ctxlog-Logid: + - 1-65aa7b0d-4fe3b6b5219e294d30e2f68a + status: + code: 200 + message: OK +- request: + body: fields id, name; where slug="n64"; + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Authorization: + - Bearer test_token Client-ID: - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Connection: @@ -25,7 +132,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 7f126a00ff5536ff-YYZ + - 847f78b57cc05ad1-VIE Connection: - keep-alive Content-Encoding: @@ -33,23 +140,23 @@ interactions: Content-Type: - application/json Date: - - Thu, 03 Aug 2023 23:41:55 GMT + - Fri, 19 Jan 2024 13:37:18 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=YSU1kOOYgk2sBN2rEWxDlKrslGRW1UpK8RnA6l.zKh4-1691106115-0-AaN052HbCUAYRaiWZZWlUTi/7cT0S9NbwQ7OwjzwmE/heOVqTfhFSJlTsFv6KbnQWd7RDcWEQI1EyCpeYesnUG4=; - path=/; expires=Fri, 04-Aug-23 00:11:55 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=FUiEglz.RknY_2kFXKZpmx2WDCOZK3knWG44mWNZju0-1705671438-1-Aaizw6VrbK0SXWkYd2ivuE6KDp9ZHMMKSevd2n0+A4vebUcoB0Sk0zML1IaS33GzxKun+KPo+5Vq0IXAG2z/7f8=; + path=/; expires=Fri, 19-Jan-24 14:07:18 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Transfer-Encoding: - chunked Via: - - 1.1 9b4f2014232c90b3056e1fb1e00215fc.cloudfront.net (CloudFront) + - 1.1 a5feee427fe9cff4e87dc473d3d3e300.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - xhnv8ARLgZZoWZOYNyOKw2R9eORp9S7ZCmmvwShks2vAttJzZ_5eLA== + - UxH9BKAeSFcfhHV3VfJu_4LeorACi_x0NrDp2ACA5SDfnWqYSEvZEA== X-Amz-Cf-Pop: - - YUL62-C2 + - VIE50-C2 X-Cache: - Miss from cloudfront X-Content-Type-Options: @@ -59,13 +166,13 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - JG4yfEnzPHcF9xQ= + - RygqPEL5PHcESbg= x-amzn-Remapped-Content-Length: - '50' x-amzn-Remapped-Date: - - Thu, 03 Aug 2023 23:41:54 GMT + - Fri, 19 Jan 2024 13:37:18 GMT x-amzn-RequestId: - - 86e7521f-07de-4725-93ae-5945991b2f80 + - 81a7c41d-ba91-4740-b50f-01750f498682 status: code: 200 message: OK @@ -77,7 +184,114 @@ interactions: Accept-Encoding: - gzip, deflate Authorization: - - Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + - Bearer test_token + Client-ID: + - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Connection: + - keep-alive + Content-Length: + - '39' + User-Agent: + - python-requests/2.31.0 + method: POST + uri: https://api.igdb.com/v4/platforms/ + response: + body: + string: "{\n \"message\": \"Authorization Failure. Have you tried:\",\n \"Tip + 1\": \"Ensure you are sending Authorization and Client-ID as headers.\",\n + \ \"Tip 2\": \"Ensure Authorization value starts with 'Bearer ', including + the space\",\n \"Tip 3\": \"Ensure Authorization value ends with the App + Access Token you generated, NOT your Client Secret.\",\n \"Docs\": \"https://api-docs.igdb.com/#authentication\",\n + \ \"Discord\": \"https://discord.gg/FrvfwQg\"\n}\n" + headers: + CF-Cache-Status: + - DYNAMIC + CF-RAY: + - 847f78baabe25acf-VIE + Connection: + - keep-alive + Content-Length: + - '437' + Content-Type: + - application/json + Date: + - Fri, 19 Jan 2024 13:37:18 GMT + Server: + - cloudflare + Set-Cookie: + - __cf_bm=YzByNhOv.HvkvnHbwnntOLv56C7mh5R4WUmK061VZm0-1705671438-1-Ac+kZrgAttx0RTFabeaWmCVW53EoQxrWKNk0K+i63+ub/zdYYNyXdJcLN3LYN1jwVDiGbsmdZ1V8Ngn7NO+PAgg=; + path=/; expires=Fri, 19-Jan-24 14:07:18 GMT; domain=.igdb.com; HttpOnly; Secure; + SameSite=None + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Via: + - 1.1 659e81bfffb15e4b314a9b12d4db8946.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - rypdWtoibbAHhuaeJiMf2lEVNZJa3cVDhUfzudW6JJTg2rEEAx4HFw== + X-Amz-Cf-Pop: + - VIE50-C2 + X-Cache: + - Error from cloudfront + X-Content-Type-Options: + - nosniff + alt-svc: + - h3=":443"; ma=86400 + x-amz-apigw-id: + - RygqVFdIvHcEn1Q= + x-amzn-ErrorType: + - AccessDeniedException + x-amzn-RequestId: + - cfd88163-e5bb-4107-9244-711fb1aa034c + status: + code: 401 + message: Unauthorized +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + User-Agent: + - python-requests/2.31.0 + method: POST + uri: https://id.twitch.tv/oauth2/token?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials + response: + body: + string: '{"access_token":"l3btktkckysdzd6zlb314x4x32yna8","expires_in":5407872,"token_type":"bearer"} + + ' + headers: + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '93' + Content-Type: + - application/json + Date: + - Fri, 19 Jan 2024 13:37:20 GMT + Server: + - nginx + X-Ctxlog-Logid: + - 1-65aa7b10-745ccbbb55318a497e4c24ab + status: + code: 200 + message: OK +- request: + body: fields id, name; where slug="not-real"; + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Authorization: + - Bearer l3btktkckysdzd6zlb314x4x32yna8 Client-ID: - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Connection: @@ -95,7 +309,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 7f126a033dfe36d6-YYZ + - 847f78c9286b5abb-VIE Connection: - keep-alive Content-Length: @@ -103,21 +317,21 @@ interactions: Content-Type: - application/json Date: - - Thu, 03 Aug 2023 23:41:55 GMT + - Fri, 19 Jan 2024 13:37:21 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=C15lGKF9M7qAs3MgWG1Rdg1BBgoNTkXUtiHaTYm2.No-1691106115-0-AcXlYwi9KvmsVhZSGfPc+8QFPyJ8l75AmoGU1uIc08UsxgCqA0ebf/joGzEFDgKANOycFOVnm4SD0FBPe79QJIA=; - path=/; expires=Fri, 04-Aug-23 00:11:55 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=xJLCTNTRq9k6whzqynMFRRJli_Gjt1faJWfx.Ae1gvI-1705671441-1-AWU/X5sIGRg6L6Iw62fVfPdsA5uzMFgdLIUsuWqRC1AzNlqv4cVjhimnBRYwzVHWziwMXa+Hex+8SShophh698I=; + path=/; expires=Fri, 19-Jan-24 14:07:21 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Via: - - 1.1 b17b94cbc6db5cb82e8f8d6e55e1e85a.cloudfront.net (CloudFront) + - 1.1 8ce530783de74227d43f4646291541dc.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - lssR6fbnPthIZ3KymDK4XGpoy79m63sp3YG3feOCNlerg3MlqgSjMw== + - _V6x0Awmk0Xy12bWXipk8jF0Ce36ltBLkCfY7oGA3aojB5qIOV5QBw== X-Amz-Cf-Pop: - - YTO50-P1 + - VIE50-C2 X-Cache: - Miss from cloudfront X-Content-Type-Options: @@ -127,13 +341,81 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - JG4yiHcZPHcFydQ= + - RygqsH6rvHcEIlg= x-amzn-Remapped-Content-Length: - '2' x-amzn-Remapped-Date: - - Thu, 03 Aug 2023 23:41:55 GMT + - Fri, 19 Jan 2024 13:37:21 GMT x-amzn-RequestId: - - c4d171c7-91fb-4587-a7d4-2417fab3f265 + - c458910c-6008-4a3f-87f5-f4158bedd84b + status: + code: 200 + message: OK +- request: + body: fields id, name; where slug="not-real"; + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Authorization: + - Bearer l3btktkckysdzd6zlb314x4x32yna8 + Client-ID: + - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Connection: + - keep-alive + Content-Length: + - '39' + User-Agent: + - python-requests/2.31.0 + method: POST + uri: https://api.igdb.com/v4/platform_versions/ + response: + body: + string: '[]' + headers: + CF-Cache-Status: + - DYNAMIC + CF-RAY: + - 847f78ccaac55a9e-VIE + Connection: + - keep-alive + Content-Length: + - '2' + Content-Type: + - application/json + Date: + - Fri, 19 Jan 2024 13:37:21 GMT + Server: + - cloudflare + Set-Cookie: + - __cf_bm=G0tXKWtqGd.9I..1t5lxG6DQ1nTRcGJbXdPYV6oGr3I-1705671441-1-AZ82dbWtoyJTcgJKrAWOZ4rKukiH6JfCsSdKicQvdo4WT+lxkNOCtbpeVo8nYRPNtVEvURBUsFEzESxIDfR0d+s=; + path=/; expires=Fri, 19-Jan-24 14:07:21 GMT; domain=.igdb.com; HttpOnly; Secure; + SameSite=None + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Via: + - 1.1 95c9d51ed7176777d7ac8ca8cb233696.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - PLKO6r61VkL3kdn0oN0HnPKcMksqzV6itTEOJtaZ21tEZPsw_AxOqA== + X-Amz-Cf-Pop: + - VIE50-C2 + X-Cache: + - Miss from cloudfront + X-Content-Type-Options: + - nosniff + X-Count: + - '0' + alt-svc: + - h3=":443"; ma=86400 + x-amz-apigw-id: + - RygqxF-JvHcEhbQ= + x-amzn-Remapped-Content-Length: + - '2' + x-amzn-Remapped-Date: + - Fri, 19 Jan 2024 13:37:21 GMT + x-amzn-RequestId: + - 9702c7c2-606e-4e08-82af-70e7841e46b6 status: code: 200 message: OK diff --git a/backend/handler/tests/cassettes/test_get_ps2_opl_rom.yaml b/backend/handler/tests/cassettes/test_get_ps2_opl_rom.yaml index 62b29bf68..ad8241b9f 100644 --- a/backend/handler/tests/cassettes/test_get_ps2_opl_rom.yaml +++ b/backend/handler/tests/cassettes/test_get_ps2_opl_rom.yaml @@ -31,7 +31,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 840e1def59b553ef-YYZ + - 847f78d01d945a68-VIE Connection: - keep-alive Content-Length: @@ -39,21 +39,21 @@ interactions: Content-Type: - application/json Date: - - Fri, 05 Jan 2024 19:27:09 GMT + - Fri, 19 Jan 2024 13:37:22 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=UaS11VA2fB8atCFOx97aBLqoxkRUnsy_5rrNYIL3YoU-1704482829-1-AdzDyNg7l51RyROpA43PUQnVRrzVRtMP8CRdttBmqJFmha5lAkwAgZnY4Ph2NBm43oQ71fP5Tz8xSl3SeV4jfT4=; - path=/; expires=Fri, 05-Jan-24 19:57:09 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=_kOPxK15YR4iSYKsjblu8SJOiLI70wgQ7FOjvG27hXg-1705671442-1-ATULcbeLOsS/i3DKSecQWlBxz2qoIs0gw2ebsjEKw9Qmdq7dPp9HPCySt3FZZ8vM9LwXzxP93ox0QrXt++SJjow=; + path=/; expires=Fri, 19-Jan-24 14:07:22 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Via: - - 1.1 f7da5d3db9ee44e1812f138a4bdfd564.cloudfront.net (CloudFront) + - 1.1 530e9f4b5e6084726110986459f0c18c.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - cY3sSQbEy2b71uGVJZ8qt0KgtzDfyrJqc8WVhXjxCfPiztfGVWglGg== + - pLEOGpTtK4jBKry42XQ0jEFNtFMclP5_qTaPiyYCe9AtvesKjCKsxA== X-Amz-Cf-Pop: - - YUL62-C2 + - VIE50-C2 X-Cache: - Error from cloudfront X-Content-Type-Options: @@ -61,11 +61,11 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - RFKyDFjYPHcEgLw= + - Rygq3HrsPHcEaRA= x-amzn-ErrorType: - AccessDeniedException x-amzn-RequestId: - - 4db631d7-10ca-4505-99b0-000e64fab321 + - 572a740f-87ce-45c6-9096-fb30c9a03540 status: code: 401 message: Unauthorized @@ -86,7 +86,7 @@ interactions: uri: https://id.twitch.tv/oauth2/token?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials response: body: - string: '{"access_token":"ycmxc7vv0hesse6mjvg9hium4iku9s","expires_in":4762653,"token_type":"bearer"} + string: '{"access_token":"3oeeqb3l2oufuidp79c708gr8xwseh","expires_in":4828909,"token_type":"bearer"} ' headers: @@ -99,11 +99,11 @@ interactions: Content-Type: - application/json Date: - - Fri, 05 Jan 2024 19:27:09 GMT + - Fri, 19 Jan 2024 13:37:23 GMT Server: - nginx X-Ctxlog-Logid: - - 1-6598580d-72814aa35ddb1dba5cc27010 + - 1-65aa7b13-233b8db24633d23a3759fe1a status: code: 200 message: OK @@ -116,7 +116,7 @@ interactions: Accept-Encoding: - gzip, deflate Authorization: - - Bearer ycmxc7vv0hesse6mjvg9hium4iku9s + - Bearer 3oeeqb3l2oufuidp79c708gr8xwseh Client-ID: - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Connection: @@ -134,7 +134,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 840e1df61ff9a1e4-YYZ + - 847f78da1a425a71-VIE Connection: - keep-alive Content-Length: @@ -142,21 +142,21 @@ interactions: Content-Type: - application/json Date: - - Fri, 05 Jan 2024 19:27:10 GMT + - Fri, 19 Jan 2024 13:37:23 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=cBz3M1IzatwlfWTrENffjuZWUox3KdMY_ruN2OU8nT0-1704482830-1-AfBxgPXgQ/M/YsHGDYtUnb3VK8BHBhrI5of44hGUBp+KE03mKP2SH/Ui+s/O3vbcAmwr5cQdKCi7wvrP3MPpkL0=; - path=/; expires=Fri, 05-Jan-24 19:57:10 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=Lffs3gVHrcwjJ6hL6ckCIs8r6IEDWRKiDUjFBzPpAi8-1705671443-1-AbmAvDmsKM6FBdoFkxdaqZNV1FWdU4vpfpXwmHnEtQTRj36l9XYcgEX31cUIILCy1pzmZmoau5TITEZC8zly1sM=; + path=/; expires=Fri, 19-Jan-24 14:07:23 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Via: - - 1.1 5fa5e473f638d77357bb0fccef4ca526.cloudfront.net (CloudFront) + - 1.1 a5feee427fe9cff4e87dc473d3d3e300.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - mNE9nHzWA6zBTPOM0rq4pQC4IyRVgWBPIx7HGN6u8T8nv7cZLq5ZPg== + - vtfHJv1IXrt9dg17XtXAmCuFDqNmKO4bPK36DAcLWTpH6eXpFSSkOQ== X-Amz-Cf-Pop: - - YUL62-C2 + - VIE50-C2 X-Cache: - Miss from cloudfront X-Content-Type-Options: @@ -166,13 +166,13 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - RFKyNFyyvHcEKyA= + - RygrHHLzPHcETeg= x-amzn-Remapped-Content-Length: - '2' x-amzn-Remapped-Date: - - Fri, 05 Jan 2024 19:27:10 GMT + - Fri, 19 Jan 2024 13:37:23 GMT x-amzn-RequestId: - - ea9517b3-ad01-416d-99dd-7a9a73868337 + - ba00326d-56b5-4cdb-b381-890914f1f05d status: code: 200 message: OK @@ -186,7 +186,7 @@ interactions: Accept-Encoding: - gzip, deflate Authorization: - - Bearer ycmxc7vv0hesse6mjvg9hium4iku9s + - Bearer 3oeeqb3l2oufuidp79c708gr8xwseh Client-ID: - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Connection: @@ -204,7 +204,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 840e1df959f8a21d-YYZ + - 847f78dd1db35a44-VIE Connection: - keep-alive Content-Length: @@ -212,21 +212,21 @@ interactions: Content-Type: - application/json Date: - - Fri, 05 Jan 2024 19:27:10 GMT + - Fri, 19 Jan 2024 13:37:24 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=QiozKIK2Ap6T3BMS1.zFk9IfLGmrgDQV4tCC4mR5aVA-1704482830-1-AXm8pPyNZPolOcXxd2oXAtP/fZ+y+rwS2hHZL1ntRcWSpXMEmy3diGuqtZ61HzvH41ztaO0YBXA289em+GBAAV4=; - path=/; expires=Fri, 05-Jan-24 19:57:10 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=iQnfUHnJ5Ufwghyc7Mm8sOgaOSZXRSYGaWZr4jTRHSQ-1705671444-1-AQbNaTR4aNsOi4yogVUgsiwupAoF0THdvbLswX0npqkvUTeXK2C1z7Oyd1fm+0wIg9cCA5ChNoZyUPn/CKOJ/0g=; + path=/; expires=Fri, 19-Jan-24 14:07:24 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Via: - - 1.1 22068bada9db7a55ac57b9824fe6f9b4.cloudfront.net (CloudFront) + - 1.1 95c9d51ed7176777d7ac8ca8cb233696.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - vLFpUC9iRNUiBqE1P5BNBSEmzpZpYdY92TXSUGZ8tH-Zpc7AO13Kww== + - uCtbRR46oep4gC4Vadv3RRw6Q2XNTXk3dYWketup8W-TqncGpBZ-pA== X-Amz-Cf-Pop: - - YUL62-C2 + - VIE50-C2 X-Cache: - Miss from cloudfront X-Content-Type-Options: @@ -236,13 +236,13 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - RFKyTG7HPHcEpug= + - RygrPE0yPHcEcZQ= x-amzn-Remapped-Content-Length: - '2' x-amzn-Remapped-Date: - - Fri, 05 Jan 2024 19:27:10 GMT + - Fri, 19 Jan 2024 13:37:24 GMT x-amzn-RequestId: - - de9b5cba-2134-42cb-b13a-d0886acde238 + - dd57905d-8c5f-4c16-967b-0430b37bbdb6 status: code: 200 message: OK @@ -255,7 +255,7 @@ interactions: Accept-Encoding: - gzip, deflate Authorization: - - Bearer ycmxc7vv0hesse6mjvg9hium4iku9s + - Bearer 3oeeqb3l2oufuidp79c708gr8xwseh Client-ID: - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Connection: @@ -273,7 +273,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 840e1dfc9aa236c3-YYZ + - 847f78e21ea86c86-ZAG Connection: - keep-alive Content-Length: @@ -281,21 +281,21 @@ interactions: Content-Type: - application/json Date: - - Fri, 05 Jan 2024 19:27:11 GMT + - Fri, 19 Jan 2024 13:37:25 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=NmMjWGx_xEiiM1uaWbgA84EAXUBTNmuTz9ZbInymZ00-1704482831-1-AXNxQ3/n3pxXz7JDMQBCqUGP1kl/TA0WSkLvOGP9Casw5j1J9WLw6zbPg/CqUntFGmZlIZrnJ1xFi1aJSlm1Ps8=; - path=/; expires=Fri, 05-Jan-24 19:57:11 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=_16d8qit0KtY.bR8s7LswAB3jHn0M184DpZdm1hHWT4-1705671445-1-AQDCn8JjNm55+Uk8KPbFj2OG7QyU3PN/Hf5mIlIFVmUEGrODJxqNFVDTM6xw4XccrUp4YN8vTIEx3E3sZVludNo=; + path=/; expires=Fri, 19-Jan-24 14:07:25 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Via: - - 1.1 8422f3871db2552d4ad0cc9f31e22c2e.cloudfront.net (CloudFront) + - 1.1 a5feee427fe9cff4e87dc473d3d3e300.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - nNG-gTaYCZ5rpsGaE9w0Q6W7n0Zcgas_ijV_07HttzgZRJvFgewDyA== + - WNetlDy__DbtmH_i_bvOd0dLp0H6HN1fcv3YU3gGHaLU3-sD7XcJYw== X-Amz-Cf-Pop: - - YUL62-C2 + - VIE50-C2 X-Cache: - Miss from cloudfront X-Content-Type-Options: @@ -305,13 +305,13 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - RFKyZFsMvHcEs2A= + - RygrUE0VPHcERRQ= x-amzn-Remapped-Content-Length: - '2' x-amzn-Remapped-Date: - - Fri, 05 Jan 2024 19:27:11 GMT + - Fri, 19 Jan 2024 13:37:25 GMT x-amzn-RequestId: - - bda8994c-74ff-40b9-946b-5c291feba36c + - 9a70e744-3429-4b96-985a-92744d5be3cf status: code: 200 message: OK @@ -348,7 +348,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 840e1dffcff87119-YYZ + - 847f78e54989c208-ZAG Connection: - keep-alive Content-Length: @@ -356,21 +356,21 @@ interactions: Content-Type: - application/json Date: - - Fri, 05 Jan 2024 19:27:11 GMT + - Fri, 19 Jan 2024 13:37:25 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=08u9u5ApvfMie_jqiDNmXs9WL4bHaapgSVqf2xT_mLg-1704482831-1-AfJfmqIEV831rLFDaZg0D4C4D31H8oSfMR9ecWO7NIQo8pbw6LzbVBjWBZq6ryV3t/yGLxXtDjKMLnWifUaN4Bo=; - path=/; expires=Fri, 05-Jan-24 19:57:11 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=FtIGhsjzYIIsehRUwdXgO1EsNvVm9BV4Jga_ZE4zqCM-1705671445-1-AehcRuRferKqtUCpChjQegd40BjDxduRFP4jXFWhUXW6OuH5/ApuWVj3+c6dawoyNNAFY35q46Eq0GIW8daV7KU=; + path=/; expires=Fri, 19-Jan-24 14:07:25 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Via: - - 1.1 144825e0e5f4523d1f7ce8c9b62cd908.cloudfront.net (CloudFront) + - 1.1 4e3b2e1fa2acb7612ea516b89c06af70.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - oeRw1015Xc3mSJUL7mrLuCKk9m_myM3RDMip_0iodK7uFY32s66BwA== + - omwvkATR8iV09kN8O3NTlC0I1-CdoeaXzdyDNzgx0RgwM5pFcGjv1A== X-Amz-Cf-Pop: - - YUL62-C2 + - VIE50-C2 X-Cache: - Error from cloudfront X-Content-Type-Options: @@ -378,11 +378,11 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - RFKyeGWhvHcEPug= + - RygrZFygvHcEO0A= x-amzn-ErrorType: - AccessDeniedException x-amzn-RequestId: - - e8572348-415f-48ea-b3fa-15643a26b6f4 + - bdad4265-3048-46fb-b293-a5da8889d32d status: code: 401 message: Unauthorized @@ -403,7 +403,7 @@ interactions: uri: https://id.twitch.tv/oauth2/token?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials response: body: - string: '{"access_token":"9vv70shduosepkqte323j2sk7e5l16","expires_in":5478750,"token_type":"bearer"} + string: '{"access_token":"wey0sj7h4jksp02joebheczbjkxw0y","expires_in":5202483,"token_type":"bearer"} ' headers: @@ -416,11 +416,11 @@ interactions: Content-Type: - application/json Date: - - Fri, 05 Jan 2024 19:27:12 GMT + - Fri, 19 Jan 2024 13:37:26 GMT Server: - nginx X-Ctxlog-Logid: - - 1-65985810-32ff685c334e1d562685f667 + - 1-65aa7b16-4159a84625a1bec276e5fc0f status: code: 200 message: OK @@ -434,7 +434,7 @@ interactions: Accept-Encoding: - gzip, deflate Authorization: - - Bearer 9vv70shduosepkqte323j2sk7e5l16 + - Bearer wey0sj7h4jksp02joebheczbjkxw0y Client-ID: - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Connection: @@ -530,7 +530,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 840e1e062e8839f9-YYZ + - 847f78efcac45a4a-VIE Connection: - keep-alive Content-Encoding: @@ -540,21 +540,21 @@ interactions: Content-Type: - application/json Date: - - Fri, 05 Jan 2024 19:27:12 GMT + - Fri, 19 Jan 2024 13:37:27 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=SBQ0hfeNWLeVDi9u25Ycqjy0_y_lVOlQ6RUoOXpoUvE-1704482832-1-AX8irnnXyf/2o19KeyDM46YduN9meO/Qdwu0d/tDbrrtqL6M1ExPQqPN4J9DMGR9e6Gh2JtAV0DZTn8wlCe5B5E=; - path=/; expires=Fri, 05-Jan-24 19:57:12 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=8b3MbRlUf_cXtQrYJZGHA3rMoQ7VDbYZ1wS4NEK5.UQ-1705671447-1-AesmmpdP/BC2aBdD44z+9isv4H0hK8t+yU75PyJuCQdNvuheaDZBqD3IG4NUMh/yECYi4HHawzZSWJAMhYyO0rM=; + path=/; expires=Fri, 19-Jan-24 14:07:27 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Via: - - 1.1 f7da5d3db9ee44e1812f138a4bdfd564.cloudfront.net (CloudFront) + - 1.1 a4035907ac3c3ba8d1fd116b6b6b9a4c.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - 4QRv9SqNlv9c1l6rJlzTPHUwAvsoje8ZHFOL381FA2S-mPfChjzv7Q== + - WatxWH8uFhodIzj0McFJCYImtw9ehM7P8G2vz_qaWGi4q7WsT2E_Sw== X-Amz-Cf-Pop: - - YUL62-C2 + - VIE50-C2 X-Cache: - Miss from cloudfront X-Content-Type-Options: @@ -564,13 +564,13 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - RFKyoFdtPHcENCA= + - RygrqF3rvHcEnpg= x-amzn-Remapped-Content-Length: - '2424' x-amzn-Remapped-Date: - - Fri, 05 Jan 2024 19:27:12 GMT + - Fri, 19 Jan 2024 13:37:27 GMT x-amzn-RequestId: - - 1725c117-1e0b-4617-aaa3-e28514f91fc5 + - a17b1636-e8a9-40be-9c91-35379f66eb7d status: code: 200 message: OK @@ -582,7 +582,7 @@ interactions: Accept-Encoding: - gzip, deflate Authorization: - - Bearer 9vv70shduosepkqte323j2sk7e5l16 + - Bearer wey0sj7h4jksp02joebheczbjkxw0y Client-ID: - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Connection: @@ -601,7 +601,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 840e1e0928333701-YYZ + - 847f78f37ee25a50-VIE Connection: - keep-alive Content-Encoding: @@ -609,23 +609,23 @@ interactions: Content-Type: - application/json Date: - - Fri, 05 Jan 2024 19:27:13 GMT + - Fri, 19 Jan 2024 13:37:28 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=bI2hirE91RIdKvLGAuGYFmNDWo.7x186AGjRyaxu1w8-1704482833-1-AWDx/4zSK3tfOUw0nN7HIEAoOYngfUQlpngXXAjSghmK9lSyrCfAnhgaYSN4H+rWVNQxOZ31tuZLwOOisbiz/Zo=; - path=/; expires=Fri, 05-Jan-24 19:57:13 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=5ecjpD04TCwTlrH57YWF1w7277xy8jZryDcULP1MKs0-1705671448-1-AXAzh8GGgViKgB9gSNhdbACQOIN8C26nd5Kj4dDz6Wd7K0QFiNLM5RDm35qvOqqvaGe5l/3sQG/xBsbRC4oJI9w=; + path=/; expires=Fri, 19-Jan-24 14:07:28 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Transfer-Encoding: - chunked Via: - - 1.1 0df778cadb5eaa000de4f1d7838b16e0.cloudfront.net (CloudFront) + - 1.1 4de71b0a42267b098ed30fff0d8a660a.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - pJHvaV9ghiHsZMTQ_IcKG9EX2fXmnbLHRZQdBFPHA31DrhiJTcMAcQ== + - 3qugWTzNrbWm_0zVSD9uGE6qR4JHusZt0cj8a1-SWATPF1bQ-3ekZg== X-Amz-Cf-Pop: - - YUL62-C2 + - VIE50-C2 X-Cache: - Miss from cloudfront X-Content-Type-Options: @@ -635,13 +635,13 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - RFKysFlZvHcEQfQ= + - RygryG99vHcEVjQ= x-amzn-Remapped-Content-Length: - '97' x-amzn-Remapped-Date: - - Fri, 05 Jan 2024 19:27:13 GMT + - Fri, 19 Jan 2024 13:37:28 GMT x-amzn-RequestId: - - 391acfec-991b-4b11-8ec1-bc5ccc558a7c + - 680e91f5-50da-49f2-bade-44b9247fbd98 status: code: 200 message: OK @@ -653,7 +653,7 @@ interactions: Accept-Encoding: - gzip, deflate Authorization: - - Bearer 9vv70shduosepkqte323j2sk7e5l16 + - Bearer wey0sj7h4jksp02joebheczbjkxw0y Client-ID: - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Connection: @@ -676,7 +676,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 840e1e0c8e45a1da-YYZ + - 847f78f92ae85ae8-VIE Connection: - keep-alive Content-Encoding: @@ -684,23 +684,23 @@ interactions: Content-Type: - application/json Date: - - Fri, 05 Jan 2024 19:27:13 GMT + - Fri, 19 Jan 2024 13:37:29 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=_Lbr4oQE0LaNfBP5BiCrLEOHj.IXNE2El_O5u8FK.o4-1704482833-1-AQ5NVKvfJ9qNvAwufTD+7oNVvnlkcCbO0Qv+OIrYoYM4xPER/87JcGOd65ILQVduWMI7dX259NTaJe/oCgeTzZs=; - path=/; expires=Fri, 05-Jan-24 19:57:13 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=6X3Z2yBQwumpynWlLt9ocPpOYpl73BjMc.UcYpK6ffk-1705671449-1-AZ+1O4hCGxZIItvpLiUJh8VKfzTLfx00xBiQsSE9Q9GWHgdP2a7LITTX+dG0uiz070PKLR5UAz4iVYq3wX5Vywk=; + path=/; expires=Fri, 19-Jan-24 14:07:29 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Transfer-Encoding: - chunked Via: - - 1.1 f7da5d3db9ee44e1812f138a4bdfd564.cloudfront.net (CloudFront) + - 1.1 95c9d51ed7176777d7ac8ca8cb233696.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - L9J0t_WDbn0jZmgEBmKE7fN3m-ZQAHr2GpcHcZznMRsnJ1Su2BRQQA== + - y5xqVB4FhS0ZW1-OLBhrZ0wKfs_ze1YrMYd_o06UP4RvduEfkdA-lg== X-Amz-Cf-Pop: - - YUL62-C2 + - VIE50-C2 X-Cache: - Miss from cloudfront X-Content-Type-Options: @@ -710,13 +710,13 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - RFKyyGQhPHcEpHQ= + - Rygr8H8jvHcES2w= x-amzn-Remapped-Content-Length: - '477' x-amzn-Remapped-Date: - - Fri, 05 Jan 2024 19:27:13 GMT + - Fri, 19 Jan 2024 13:37:29 GMT x-amzn-RequestId: - - c3bcc7b4-bdfc-4c69-8a60-c8b5e6a7478b + - 605655b7-bab7-4f34-934e-3197221fb3f2 status: code: 200 message: OK diff --git a/backend/utils/tests/cassettes/test_scan_platform.yaml b/backend/utils/tests/cassettes/test_scan_platform.yaml index 77ccec558..3f48a5963 100644 --- a/backend/utils/tests/cassettes/test_scan_platform.yaml +++ b/backend/utils/tests/cassettes/test_scan_platform.yaml @@ -18,6 +18,113 @@ interactions: - python-requests/2.31.0 method: POST uri: https://api.igdb.com/v4/platforms/ + response: + body: + string: "{\n \"message\": \"Authorization Failure. Have you tried:\",\n \"Tip + 1\": \"Ensure you are sending Authorization and Client-ID as headers.\",\n + \ \"Tip 2\": \"Ensure Authorization value starts with 'Bearer ', including + the space\",\n \"Tip 3\": \"Ensure Authorization value ends with the App + Access Token you generated, NOT your Client Secret.\",\n \"Docs\": \"https://api-docs.igdb.com/#authentication\",\n + \ \"Discord\": \"https://discord.gg/FrvfwQg\"\n}\n" + headers: + CF-Cache-Status: + - DYNAMIC + CF-RAY: + - 847f7923eb415a68-VIE + Connection: + - keep-alive + Content-Length: + - '437' + Content-Type: + - application/json + Date: + - Fri, 19 Jan 2024 13:37:35 GMT + Server: + - cloudflare + Set-Cookie: + - __cf_bm=LuRKnzhlumMElLmukIXuVmMgCcXtW0XDpsH53Zw6xsg-1705671455-1-AX0/uq4rO9sT5PELhyDuZygY76dEEdTTCjMrqdCaT1H61LqJiH4K6nY4WvDX0wgUJe9+YFtwG9wuZ83ioARrOVs=; + path=/; expires=Fri, 19-Jan-24 14:07:35 GMT; domain=.igdb.com; HttpOnly; Secure; + SameSite=None + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Via: + - 1.1 a4035907ac3c3ba8d1fd116b6b6b9a4c.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - 1dq0DchR7bTMsHlc95R5clqE77jn2I5GP4gH8PfgSf2m3Tjs0l-eKg== + X-Amz-Cf-Pop: + - VIE50-C2 + X-Cache: + - Error from cloudfront + X-Content-Type-Options: + - nosniff + alt-svc: + - h3=":443"; ma=86400 + x-amz-apigw-id: + - Rygs9G6QPHcEp6Q= + x-amzn-ErrorType: + - AccessDeniedException + x-amzn-RequestId: + - f5db871a-286b-4678-90a1-f76e1b1f9589 + status: + code: 401 + message: Unauthorized +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + User-Agent: + - python-requests/2.31.0 + method: POST + uri: https://id.twitch.tv/oauth2/token?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials + response: + body: + string: '{"access_token":"f2e6dg9iq7t3ewie86rcphdb7xmrr4","expires_in":5446613,"token_type":"bearer"} + + ' + headers: + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '93' + Content-Type: + - application/json + Date: + - Fri, 19 Jan 2024 13:37:36 GMT + Server: + - nginx + X-Ctxlog-Logid: + - 1-65aa7b20-59ebf75d0a230ec439f79578 + status: + code: 200 + message: OK +- request: + body: fields id, name; where slug="n64"; + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Authorization: + - Bearer f2e6dg9iq7t3ewie86rcphdb7xmrr4 + Client-ID: + - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Connection: + - keep-alive + Content-Length: + - '34' + User-Agent: + - python-requests/2.31.0 + method: POST + uri: https://api.igdb.com/v4/platforms/ response: body: string: "[\n {\n \"id\": 4,\n \"name\": \"Nintendo 64\"\n }\n]" @@ -25,7 +132,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 7eff5636a99d36a1-YYZ + - 847f792da9eb5a68-VIE Connection: - keep-alive Content-Encoding: @@ -33,23 +140,23 @@ interactions: Content-Type: - application/json Date: - - Tue, 01 Aug 2023 16:07:54 GMT + - Fri, 19 Jan 2024 13:37:37 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=M6jV8IDBXuhn5koc54NIo92mpS_07Vq_YCS_Er_x8Ho-1690906074-0-Aatz9H75G6sex1NR59WNaayPhbzHq5bsGY69J802KkuOxTJIRVagK7kMa09OIayfKnTNr4nci8tkf4PwZtAPBCQ=; - path=/; expires=Tue, 01-Aug-23 16:37:54 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=UeR9THzl1BMESRswlbiF8O8HVtWbphaaVN.u1NJwYaU-1705671457-1-ARbJ6pvkJw05JjLlnzVW0agt1kIneTfVdFlNtN3wfXtsa6k2ebGmJNAjpyqHMLabokene6qJ1JvPWfhGB8Al/N8=; + path=/; expires=Fri, 19-Jan-24 14:07:37 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Transfer-Encoding: - chunked Via: - - 1.1 77f3bc2c9964f50671e7151896d06648.cloudfront.net (CloudFront) + - 1.1 ba761cfda8bfa6cbda2b6c433d6201f6.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - Q_HAeLD8jS46IJCOE7dnaNhMJy844TeELDlDwNXScyuwNEiQIqIUgw== + - MfgSRHijVQz7kKWEBEKwOWuUABiiDDo9zTBwaIavMBXPh0McT6UfWg== X-Amz-Cf-Pop: - - YUL62-C2 + - VIE50-C2 X-Cache: - Miss from cloudfront X-Content-Type-Options: @@ -59,13 +166,13 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - I_QaOHVMPHcFiCQ= + - RygtQH5QvHcEOWg= x-amzn-Remapped-Content-Length: - '50' x-amzn-Remapped-Date: - - Tue, 01 Aug 2023 16:07:54 GMT + - Fri, 19 Jan 2024 13:37:37 GMT x-amzn-RequestId: - - a5224844-883a-4a2b-9e5a-a1278adeaec3 + - e160c12d-050e-4ace-a78c-4119da0f995a status: code: 200 message: OK @@ -77,7 +184,114 @@ interactions: Accept-Encoding: - gzip, deflate Authorization: - - Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + - Bearer test_token + Client-ID: + - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Connection: + - keep-alive + Content-Length: + - '31' + User-Agent: + - python-requests/2.31.0 + method: POST + uri: https://api.igdb.com/v4/platforms/ + response: + body: + string: "{\n \"message\": \"Authorization Failure. Have you tried:\",\n \"Tip + 1\": \"Ensure you are sending Authorization and Client-ID as headers.\",\n + \ \"Tip 2\": \"Ensure Authorization value starts with 'Bearer ', including + the space\",\n \"Tip 3\": \"Ensure Authorization value ends with the App + Access Token you generated, NOT your Client Secret.\",\n \"Docs\": \"https://api-docs.igdb.com/#authentication\",\n + \ \"Discord\": \"https://discord.gg/FrvfwQg\"\n}\n" + headers: + CF-Cache-Status: + - DYNAMIC + CF-RAY: + - 847f7932eed55ab5-VIE + Connection: + - keep-alive + Content-Length: + - '437' + Content-Type: + - application/json + Date: + - Fri, 19 Jan 2024 13:37:38 GMT + Server: + - cloudflare + Set-Cookie: + - __cf_bm=5DrFN8rmd3MUbDV8GdtLxaEwZW.J9jcO_D97UUZd6qs-1705671458-1-ATJi7TaAzGqvZOtYHVUylDYcAagmfdS406NJfPFLaoTW/WKsVdMFQQKx+WQcX2D+PLlIQfgajycXBqqCWCcsy60=; + path=/; expires=Fri, 19-Jan-24 14:07:38 GMT; domain=.igdb.com; HttpOnly; Secure; + SameSite=None + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Via: + - 1.1 95c9d51ed7176777d7ac8ca8cb233696.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - 5l8kbnmcqoAaf0ZoxM790IfzpLld4nSsqvLJSBw4My5JZwvdZiDACg== + X-Amz-Cf-Pop: + - VIE50-C2 + X-Cache: + - Error from cloudfront + X-Content-Type-Options: + - nosniff + alt-svc: + - h3=":443"; ma=86400 + x-amz-apigw-id: + - RygtYGmVPHcEGcQ= + x-amzn-ErrorType: + - AccessDeniedException + x-amzn-RequestId: + - 45e46f02-4827-4250-a7af-6d78bcb39c8a + status: + code: 401 + message: Unauthorized +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + User-Agent: + - python-requests/2.31.0 + method: POST + uri: https://id.twitch.tv/oauth2/token?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials + response: + body: + string: '{"access_token":"dgnj5jacdcprwqcumxksdhz971u99l","expires_in":4848708,"token_type":"bearer"} + + ' + headers: + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '93' + Content-Type: + - application/json + Date: + - Fri, 19 Jan 2024 13:37:39 GMT + Server: + - nginx + X-Ctxlog-Logid: + - 1-65aa7b23-7c0c3f6b134dd92804e3f668 + status: + code: 200 + message: OK +- request: + body: fields id, name; where slug=""; + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Authorization: + - Bearer dgnj5jacdcprwqcumxksdhz971u99l Client-ID: - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Connection: @@ -95,7 +309,7 @@ interactions: CF-Cache-Status: - DYNAMIC CF-RAY: - - 7eff5637ea8e53ef-YYZ + - 847f793f1963248a-ZAG Connection: - keep-alive Content-Length: @@ -103,21 +317,21 @@ interactions: Content-Type: - application/json Date: - - Tue, 01 Aug 2023 16:07:55 GMT + - Fri, 19 Jan 2024 13:37:40 GMT Server: - cloudflare Set-Cookie: - - __cf_bm=gE4jVTITKRcjnyoGHaSakiXPFmrb2UPnGvjjliZc0NU-1690906075-0-AZJKx7NGH6ws1e8nUErmNIBGvc1tW4ATwpOgnX3lwXHds7EMTL3plHx8pdSpnvFINrX66SVa+Z1GmnGGfOc8HJ0=; - path=/; expires=Tue, 01-Aug-23 16:37:55 GMT; domain=.igdb.com; HttpOnly; Secure; + - __cf_bm=gnQoBfHXjnj1a_AqfUftviJ4YKJZPPaxvcpSorQwE6c-1705671460-1-ATX7U3THaIbbG/0WMjoSH0Txd3rapaVpAq8SEbuCNyMhLLwnBSMKHherISYXpVKn6hb4eUmZ1LZRZAPI5kbmaoA=; + path=/; expires=Fri, 19-Jan-24 14:07:40 GMT; domain=.igdb.com; HttpOnly; Secure; SameSite=None Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload Via: - - 1.1 d7e35fb15b3339fbd8a9457f22308ea0.cloudfront.net (CloudFront) + - 1.1 de5338eac881cf5d87f2d811c3b7417c.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - sSYuZMZMfaWt75JeV6cdJzVc5cGFHQ3LmMu7xU1USOVDSQdjM-z44w== + - B0LrRDTakDPE14xovQLLMpdJ5WguGkZcc203pPEdUNM-SCGZk4fxHw== X-Amz-Cf-Pop: - - YTO50-P1 + - VIE50-C2 X-Cache: - Miss from cloudfront X-Content-Type-Options: @@ -127,13 +341,81 @@ interactions: alt-svc: - h3=":443"; ma=86400 x-amz-apigw-id: - - I_QaQEcrvHcF0Ig= + - RygtpE1GPHcELaQ= x-amzn-Remapped-Content-Length: - '2' x-amzn-Remapped-Date: - - Tue, 01 Aug 2023 16:07:54 GMT + - Fri, 19 Jan 2024 13:37:40 GMT x-amzn-RequestId: - - ad21ab8d-30f2-4d81-b3bf-1a241b6379a2 + - 5a7437cf-1dc1-4ff4-8d2b-4b6e73599c8c + status: + code: 200 + message: OK +- request: + body: fields id, name; where slug=""; + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Authorization: + - Bearer dgnj5jacdcprwqcumxksdhz971u99l + Client-ID: + - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Connection: + - keep-alive + Content-Length: + - '31' + User-Agent: + - python-requests/2.31.0 + method: POST + uri: https://api.igdb.com/v4/platform_versions/ + response: + body: + string: '[]' + headers: + CF-Cache-Status: + - DYNAMIC + CF-RAY: + - 847f7942ec945abd-VIE + Connection: + - keep-alive + Content-Length: + - '2' + Content-Type: + - application/json + Date: + - Fri, 19 Jan 2024 13:37:40 GMT + Server: + - cloudflare + Set-Cookie: + - __cf_bm=.GvAgzuLBUILPOAU4qzTnt9ru4GlltXhurSbrvmoEwU-1705671460-1-Af5jCakYhp8BPH3bSIxKWa6hqLNlBHgZ0rPiA7yI55SXBfnwuouu2eg2n1iPydZoKnsoSzVNJyHoB165b5A30K4=; + path=/; expires=Fri, 19-Jan-24 14:07:40 GMT; domain=.igdb.com; HttpOnly; Secure; + SameSite=None + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Via: + - 1.1 659e81bfffb15e4b314a9b12d4db8946.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - -U2SQuL1999EN_LGz7wkPV29-blNIdlv5CszU5qxq6Dr4JOMB4HZbQ== + X-Amz-Cf-Pop: + - VIE50-C2 + X-Cache: + - Miss from cloudfront + X-Content-Type-Options: + - nosniff + X-Count: + - '0' + alt-svc: + - h3=":443"; ma=86400 + x-amz-apigw-id: + - RygtvFBBPHcEJBQ= + x-amzn-Remapped-Content-Length: + - '2' + x-amzn-Remapped-Date: + - Fri, 19 Jan 2024 13:37:40 GMT + x-amzn-RequestId: + - ce901324-4bde-4c6d-adbf-195a8363ece2 status: code: 200 message: OK From fe0772a0a9fe1f84d51f636222b58dccab51065d Mon Sep 17 00:00:00 2001 From: Zurdi Date: Fri, 19 Jan 2024 16:47:35 +0100 Subject: [PATCH 04/10] updated DEVELOPER-SETUP --- DEVELOPER-SETUP.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DEVELOPER-SETUP.md b/DEVELOPER-SETUP.md index 43f81565e..d5c664630 100644 --- a/DEVELOPER-SETUP.md +++ b/DEVELOPER-SETUP.md @@ -8,6 +8,7 @@ mkdir -p romm_mock/library/roms/switch touch romm_mock/library/roms/switch/metroid.xci mkdir -p romm_mock/resources +mkdir -p romm_mock/config touch romm_mock/config.yml ``` From 2164a937ee1f384e156b7d4b7d68118a6a4d02e0 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 19 Jan 2024 16:01:14 -0500 Subject: [PATCH 05/10] get interface working --- frontend/src/types/main.d.ts | 20 -------------------- frontend/src/views/Play/Base.vue | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/frontend/src/types/main.d.ts b/frontend/src/types/main.d.ts index e8d4f3bf6..800b452b7 100644 --- a/frontend/src/types/main.d.ts +++ b/frontend/src/types/main.d.ts @@ -3,23 +3,3 @@ declare module "*.vue" { const Component: ReturnType; export default Component; } - -declare global { - interface Window { - EJS_player: string; - EJS_pathtodata: string; - EJS_color: string; - EJS_defaultOptions: object; - EJS_gameID: number; - EJS_gameName: string; - EJS_backgroundImage: string; - EJS_gameUrl: string; - EJS_loadStateURL: string; - EJS_cheats: string; - EJS_gamePatchUrl: string; - EJS_netplayServer: string; - EJS_onGameStart: () => void; - EJS_onSaveState: (args: { screenshot: File, state: File}) => void; - EJS_onLoadState: () => void; - } -} diff --git a/frontend/src/views/Play/Base.vue b/frontend/src/views/Play/Base.vue index 3516c461b..e08c5af26 100644 --- a/frontend/src/views/Play/Base.vue +++ b/frontend/src/views/Play/Base.vue @@ -13,8 +13,36 @@ const saveRef = ref(null); const stateRef = ref(null); const gameRunning = ref(false); +// Uses a different regex for jaavscript const EXTENSION_REGEX = new RegExp("\.(([a-z]+\.)*)$"); +// Declare global variables for EmulatorJS +declare global { + interface Window { + EJS_core: string; + EJS_player: string; + EJS_pathtodata: string; + EJS_color: string; + EJS_defaultOptions: object; + EJS_gameID: number; + EJS_gameName: string; + EJS_backgroundImage: string; + EJS_gameUrl: string; + EJS_loadStateURL: string | null; + EJS_cheats: string; + EJS_gamePatchUrl: string; + EJS_netplayServer: string; + EJS_alignStartButton: string; + EJS_startOnLoaded: boolean; + EJS_fullscreenOnLoaded: boolean; + EJS_emulator: any; + EJS_onGameStart: () => void; + EJS_onSaveState: (args: { screenshot: File; state: File }) => void; + EJS_onLoadState: () => void; + } +} + + const script = document.createElement("script"); script.src = "/assets/emulatorjs/loader.js"; script.async = true; @@ -82,7 +110,7 @@ window.EJS_onSaveState = function ({ }) .then(({ data }) => { if (rom.value) rom.value.states = data.states; - stateRef.value = data.states.pop(); + stateRef.value = data.states.pop() ?? null; }); } }; @@ -98,9 +126,9 @@ onMounted(() => { rom.value = response.data; window.EJS_core = rom.value.platform_slug; window.EJS_gameID = rom.value.id; - window.EJS_gameName = rom.value.name; window.EJS_backgroundImage = `/assets/romm/resources/${rom.value.path_cover_l}`; window.EJS_gameUrl = rom.value.download_path; + if (rom.value.name) window.EJS_gameName = rom.value.name; }) .catch((error) => { console.log(error); From 3bfcaabee3e97fa15dd6c4becb15a49dec8f2c9e Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 19 Jan 2024 17:30:25 -0500 Subject: [PATCH 06/10] experiments with saves --- backend/endpoints/saves.py | 28 +++++-- backend/models/assets.py | 3 +- backend/models/rom.py | 3 +- frontend/package-lock.json | 4 +- frontend/package.json | 2 +- .../components/Dialog/Asset/DeleteAssets.vue | 9 +- frontend/src/services/api/save.ts | 14 ++++ frontend/src/views/Play/Base.vue | 84 ++++++++++++++++++- 8 files changed, 132 insertions(+), 15 deletions(-) diff --git a/backend/endpoints/saves.py b/backend/endpoints/saves.py index bd7de7cba..34d501a0f 100644 --- a/backend/endpoints/saves.py +++ b/backend/endpoints/saves.py @@ -1,11 +1,12 @@ from config.config_manager import config_manager as cm from decorators.auth import protected_route from endpoints.responses import MessageResponse -from endpoints.responses.assets import UploadedSavesResponse +from endpoints.responses.assets import UploadedSavesResponse, SaveSchema from fastapi import APIRouter, File, HTTPException, Request, UploadFile, status from handler import db_save_handler, fs_asset_handler, db_rom_handler from handler.scan_handler import scan_save from logger.logger import log +from config import LIBRARY_BASE_PATH router = APIRouter() @@ -55,9 +56,24 @@ def add_saves( # pass -# @protected_route(router.put, "/saves/{id}", ["assets.write"]) -# def update_save(request: Request, id: int) -> MessageResponse: -# pass +@protected_route(router.put, "/saves/{id}", ["assets.write"]) +async def update_save(request: Request, id: int) -> SaveSchema: + data = await request.form() + + db_save = db_save_handler.get_save(id) + if not db_save: + error = f"Save with ID {id} not found" + log.error(error) + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=error) + + if "file" in data: + file: UploadFile = data["file"] + fs_asset_handler._write_file( + file=file, path=f"{LIBRARY_BASE_PATH}/{db_save.file_path}" + ) + db_save_handler.update_save(db_save.id, {"file_size_bytes": file.size}) + + return db_save @protected_route(router.post, "/saves/delete", ["assets.write"]) @@ -84,7 +100,9 @@ async def delete_saves(request: Request) -> MessageResponse: log.info(f"Deleting {save.file_name} from filesystem") try: - fs_asset_handler.remove_file(file_name=save.file_name, file_path=save.file_path) + fs_asset_handler.remove_file( + file_name=save.file_name, file_path=save.file_path + ) except FileNotFoundError: error = f"Save file {save.file_name} not found for platform {save.rom.platform_slug}" log.error(error) diff --git a/backend/models/assets.py b/backend/models/assets.py index d3820a468..156206b1b 100644 --- a/backend/models/assets.py +++ b/backend/models/assets.py @@ -1,3 +1,4 @@ +import secrets from functools import cached_property from models.base import BaseModel @@ -33,7 +34,7 @@ class BaseAsset(BaseModel): @cached_property def download_path(self) -> str: - return f"/api/raw/{self.full_path}?timestamp={self.updated_at}" + return f"/api/raw/{self.full_path}?s={secrets.token_hex(8)}" class Save(BaseAsset): diff --git a/backend/models/rom.py b/backend/models/rom.py index e999c7c82..34f22d684 100644 --- a/backend/models/rom.py +++ b/backend/models/rom.py @@ -1,4 +1,5 @@ import re +import secrets from functools import cached_property from config import ( @@ -85,7 +86,7 @@ class Rom(BaseModel): @cached_property def download_path(self) -> str: - return f"/api/raw/{self.full_path}" + return f"/api/raw/{self.full_path}?s={secrets.token_hex(8)}" @cached_property def has_cover(self) -> bool: diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 675f816d7..c5bd05647 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -12,7 +12,7 @@ "axios": "^1.6.0", "core-js": "^3.8.3", "cronstrue": "^2.31.0", - "emulatorjs": "github:GAntoine/emulatorjs", + "emulatorjs": "github:GAntoine/emulatorjs#main", "file-saver": "^2.0.5", "js-cookie": "^3.0.5", "jszip": "^3.10.1", @@ -3191,7 +3191,7 @@ }, "node_modules/emulatorjs": { "version": "4.0.6", - "resolved": "git+ssh://git@github.com/GAntoine/emulatorjs.git#8015836f1dbed7d75b7ab77bf94669e58a77bee0", + "resolved": "git+ssh://git@github.com/GAntoine/emulatorjs.git#8dfbfb0f32e94c77d49492fa34d27723a29d175e", "license": "GPL-3.0", "dependencies": { "http-server": "^14.1.1" diff --git a/frontend/package.json b/frontend/package.json index e3185a5ff..72732d422 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -15,7 +15,7 @@ "axios": "^1.6.0", "core-js": "^3.8.3", "cronstrue": "^2.31.0", - "emulatorjs": "github:GAntoine/emulatorjs", + "emulatorjs": "github:GAntoine/emulatorjs#main", "file-saver": "^2.0.5", "js-cookie": "^3.0.5", "jszip": "^3.10.1", diff --git a/frontend/src/components/Dialog/Asset/DeleteAssets.vue b/frontend/src/components/Dialog/Asset/DeleteAssets.vue index 90f4828c9..8ce5ed30d 100644 --- a/frontend/src/components/Dialog/Asset/DeleteAssets.vue +++ b/frontend/src/components/Dialog/Asset/DeleteAssets.vue @@ -47,9 +47,12 @@ async function deleteAssets() { }); result - .then(({ data }) => { - if (romRef.value) { - romRef.value[assetType.value] = data; + .then(() => { + if (romRef.value?.[assetType.value]) { + const deletedAssetIds = assets.value.map((asset) => asset.id); + romRef.value[assetType.value] = romRef.value[assetType.value].filter( + (asset) => !deletedAssetIds.includes(asset.id) + ); romsStore.update(romRef.value); emitter?.emit("romUpdated", romRef.value); } diff --git a/frontend/src/services/api/save.ts b/frontend/src/services/api/save.ts index 1006f66cf..373ecda05 100644 --- a/frontend/src/services/api/save.ts +++ b/frontend/src/services/api/save.ts @@ -15,6 +15,19 @@ async function uploadSaves({ rom, saves }: { rom: Rom; saves: File[] }) { }); } +async function updateSave({ + save, + file, +}: { + save: SaveSchema; + file: File; +}): Promise<{ data: SaveSchema }> { + var formData = new FormData(); + formData.append("file", file); + + return api.put(`/saves/${save.id}`, formData); +} + async function deleteSaves({ saves, deleteFromFs, @@ -30,5 +43,6 @@ async function deleteSaves({ export default { deleteSaves, + updateSave, uploadSaves, }; diff --git a/frontend/src/views/Play/Base.vue b/frontend/src/views/Play/Base.vue index e08c5af26..bbfce178a 100644 --- a/frontend/src/views/Play/Base.vue +++ b/frontend/src/views/Play/Base.vue @@ -3,6 +3,7 @@ import { ref, onMounted } from "vue"; import { useRoute } from "vue-router"; import romApi from "@/services/api/rom"; import stateApi from "@/services/api/state"; +import saveApi, { saveApi as api } from "@/services/api/save"; import type { Rom } from "@/stores/roms"; import type { SaveSchema, StateSchema } from "@/__generated__"; import { formatBytes } from "@/utils"; @@ -39,6 +40,8 @@ declare global { EJS_onGameStart: () => void; EJS_onSaveState: (args: { screenshot: File; state: File }) => void; EJS_onLoadState: () => void; + EJS_onSaveSave: (args: { screenshot: File; save: File }) => void; + EJS_onLoadSave: () => void; } } @@ -51,7 +54,7 @@ window.EJS_pathtodata = "/assets/emulatorjs/"; window.EJS_color = "#A453FF"; window.EJS_alignStartButton = "center"; window.EJS_startOnLoaded = true; -window.EJS_fullscreenOnLoaded = true; +window.EJS_fullscreenOnLoaded = false; window.EJS_defaultOptions = { "save-state-location": "browser", }; @@ -72,6 +75,22 @@ function buildStateName(rom: Rom): string { return stateName; } +function buildSaveName(rom: Rom): string { + const saves = rom.saves.map((s) => s.file_name); + const romName = rom.file_name.replace(EXTENSION_REGEX, "").trim(); + let saveName = `${romName}.srm`; + if (!saves.includes(saveName)) return saveName; + + let i = 2; + saveName = `${romName} (${i}).srm`; + while (saves.includes(saveName)) { + i++; + saveName = `${romName} (${i}).srm`; + } + + return saveName; +} + window.EJS_onSaveState = function ({ state, }: { @@ -115,7 +134,69 @@ window.EJS_onSaveState = function ({ } }; +async function getSave(): Promise { + if (saveRef.value) { + const { data } = await api.get(saveRef.value.download_path.replace("/api", "")); + var enc = new TextEncoder(); + return enc.encode(data); + } else { + const file = await window.EJS_emulator.selectFile(); + return new Uint8Array(await file.arrayBuffer()); + } +}; + +window.EJS_onLoadSave = async function () { + const sav = await getSave(); + const FS = window.EJS_emulator.Module.FS; + const path = window.EJS_emulator.gameManager.getSaveFilePath(); + const paths = path.split("/"); + let cp = ""; + for (let i=0; i { + saveRef.value = data; + }); + } else if (rom.value) { + saveApi + .uploadSaves({ + rom: rom.value, + saves: [ + new File([save], buildSaveName(rom.value), { + type: "application/octet-stream", + }), + ], + }) + .then(({ data }) => { + if (rom.value) rom.value.saves = data.saves; + saveRef.value = data.saves.pop() ?? null; + }); + } +}; + window.EJS_onGameStart = () => { + if (saveRef.value) window.EJS_onLoadSave(); gameRunning.value = true; }; @@ -147,7 +228,6 @@ function onPlay() { { + closeDialog(); }); - - closeDialog(); } function closeDialog() { From 9fba1d1a643aba0daede7d29ffb3dbc43d5e24b8 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 19 Jan 2024 18:09:51 -0500 Subject: [PATCH 08/10] get save workgin on load --- backend/endpoints/responses/assets.py | 3 ++ backend/endpoints/saves.py | 2 + backend/endpoints/states.py | 1 + .../src/__generated__/models/SaveSchema.ts | 2 + .../__generated__/models/ScreenshotSchema.ts | 2 + .../src/__generated__/models/StateSchema.ts | 2 + frontend/src/views/Play/Base.vue | 41 ++++++++++--------- 7 files changed, 34 insertions(+), 19 deletions(-) diff --git a/backend/endpoints/responses/assets.py b/backend/endpoints/responses/assets.py index 1ea810127..86129311a 100644 --- a/backend/endpoints/responses/assets.py +++ b/backend/endpoints/responses/assets.py @@ -1,3 +1,4 @@ +from datetime import datetime from typing import Optional from pydantic import BaseModel @@ -13,6 +14,8 @@ class BaseAsset(BaseModel): file_size_bytes: int full_path: str download_path: str + created_at: datetime + updated_at: datetime class Config: from_attributes = True diff --git a/backend/endpoints/saves.py b/backend/endpoints/saves.py index 34d501a0f..0a8ad0b3f 100644 --- a/backend/endpoints/saves.py +++ b/backend/endpoints/saves.py @@ -43,6 +43,7 @@ def add_saves( scanned_save.rom_id = rom.id db_save_handler.add_save(scanned_save) + rom = db_rom_handler.get_roms(rom_id) return {"uploaded": len(saves), "saves": rom.saves} @@ -73,6 +74,7 @@ async def update_save(request: Request, id: int) -> SaveSchema: ) db_save_handler.update_save(db_save.id, {"file_size_bytes": file.size}) + db_save = db_save_handler.get_save(id) return db_save diff --git a/backend/endpoints/states.py b/backend/endpoints/states.py index 899a74d46..bdc6d3afc 100644 --- a/backend/endpoints/states.py +++ b/backend/endpoints/states.py @@ -74,6 +74,7 @@ async def update_state(request: Request, id: int) -> StateSchema: ) db_state_handler.update_state(db_state.id, {"file_size_bytes": file.size}) + db_state = db_state_handler.get_state(id) return db_state diff --git a/frontend/src/__generated__/models/SaveSchema.ts b/frontend/src/__generated__/models/SaveSchema.ts index 0e45c8009..74f751311 100644 --- a/frontend/src/__generated__/models/SaveSchema.ts +++ b/frontend/src/__generated__/models/SaveSchema.ts @@ -12,6 +12,8 @@ export type SaveSchema = { file_size_bytes: number; full_path: string; download_path: string; + created_at: string; + updated_at: string; rom_id: number; emulator: (string | null); }; diff --git a/frontend/src/__generated__/models/ScreenshotSchema.ts b/frontend/src/__generated__/models/ScreenshotSchema.ts index 453277de7..be8239e2c 100644 --- a/frontend/src/__generated__/models/ScreenshotSchema.ts +++ b/frontend/src/__generated__/models/ScreenshotSchema.ts @@ -12,6 +12,8 @@ export type ScreenshotSchema = { file_size_bytes: number; full_path: string; download_path: string; + created_at: string; + updated_at: string; rom_id: number; }; diff --git a/frontend/src/__generated__/models/StateSchema.ts b/frontend/src/__generated__/models/StateSchema.ts index e118a443c..a65febd3f 100644 --- a/frontend/src/__generated__/models/StateSchema.ts +++ b/frontend/src/__generated__/models/StateSchema.ts @@ -12,6 +12,8 @@ export type StateSchema = { file_size_bytes: number; full_path: string; download_path: string; + created_at: string; + updated_at: string; rom_id: number; emulator: (string | null); }; diff --git a/frontend/src/views/Play/Base.vue b/frontend/src/views/Play/Base.vue index bbfce178a..b59b154ac 100644 --- a/frontend/src/views/Play/Base.vue +++ b/frontend/src/views/Play/Base.vue @@ -45,7 +45,6 @@ declare global { } } - const script = document.createElement("script"); script.src = "/assets/emulatorjs/loader.js"; script.async = true; @@ -128,22 +127,25 @@ window.EJS_onSaveState = function ({ ], }) .then(({ data }) => { - if (rom.value) rom.value.states = data.states; - stateRef.value = data.states.pop() ?? null; + const allStates = data.states.sort((a: StateSchema, b: StateSchema) => a.id - b.id); + if (rom.value) rom.value.states = allStates; + stateRef.value = allStates.pop() ?? null; }); } }; async function getSave(): Promise { if (saveRef.value) { - const { data } = await api.get(saveRef.value.download_path.replace("/api", "")); + const { data } = await api.get( + saveRef.value.download_path.replace("/api", "") + ); var enc = new TextEncoder(); return enc.encode(data); } else { const file = await window.EJS_emulator.selectFile(); return new Uint8Array(await file.arrayBuffer()); } -}; +} window.EJS_onLoadSave = async function () { const sav = await getSave(); @@ -151,22 +153,17 @@ window.EJS_onLoadSave = async function () { const path = window.EJS_emulator.gameManager.getSaveFilePath(); const paths = path.split("/"); let cp = ""; - for (let i=0; i { - if (rom.value) rom.value.saves = data.saves; - saveRef.value = data.saves.pop() ?? null; + const allSaves = data.saves.sort((a: SaveSchema, b: SaveSchema) => a.id - b.id); + if (rom.value) rom.value.saves = allSaves; + saveRef.value = allSaves.pop() ?? null; }); } }; -window.EJS_onGameStart = () => { - if (saveRef.value) window.EJS_onLoadSave(); +window.EJS_onGameStart = async () => { + setTimeout(() => { + if (stateRef.value) { + window.EJS_onLoadSave(); + window.EJS_emulator.gameManager.restart(); + } + }, 1000); gameRunning.value = true; }; From 2699c2ee8e8f1a75b353b319df203fd2102d8eff Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 19 Jan 2024 20:27:18 -0500 Subject: [PATCH 09/10] discting player component --- backend/models/assets.py | 3 +- backend/models/rom.py | 3 +- frontend/src/components/Details/Emulation.vue | 158 ++------ frontend/src/components/Details/States.vue | 4 +- frontend/src/plugins/router.ts | 19 +- frontend/src/views/Play/Base.vue | 346 +++++------------- frontend/src/views/Play/Player.vue | 242 ++++++++++++ 7 files changed, 357 insertions(+), 418 deletions(-) create mode 100644 frontend/src/views/Play/Player.vue diff --git a/backend/models/assets.py b/backend/models/assets.py index 156206b1b..d3820a468 100644 --- a/backend/models/assets.py +++ b/backend/models/assets.py @@ -1,4 +1,3 @@ -import secrets from functools import cached_property from models.base import BaseModel @@ -34,7 +33,7 @@ class BaseAsset(BaseModel): @cached_property def download_path(self) -> str: - return f"/api/raw/{self.full_path}?s={secrets.token_hex(8)}" + return f"/api/raw/{self.full_path}?timestamp={self.updated_at}" class Save(BaseAsset): diff --git a/backend/models/rom.py b/backend/models/rom.py index 34f22d684..e999c7c82 100644 --- a/backend/models/rom.py +++ b/backend/models/rom.py @@ -1,5 +1,4 @@ import re -import secrets from functools import cached_property from config import ( @@ -86,7 +85,7 @@ class Rom(BaseModel): @cached_property def download_path(self) -> str: - return f"/api/raw/{self.full_path}?s={secrets.token_hex(8)}" + return f"/api/raw/{self.full_path}" @cached_property def has_cover(self) -> bool: diff --git a/frontend/src/components/Details/Emulation.vue b/frontend/src/components/Details/Emulation.vue index ffa762b09..78648f3f0 100644 --- a/frontend/src/components/Details/Emulation.vue +++ b/frontend/src/components/Details/Emulation.vue @@ -1,144 +1,54 @@ + - - - - - - - - - - - - - - diff --git a/frontend/src/components/Details/States.vue b/frontend/src/components/Details/States.vue index 997b6cdae..cb0cd4138 100644 --- a/frontend/src/components/Details/States.vue +++ b/frontend/src/components/Details/States.vue @@ -5,11 +5,11 @@ import type { Emitter } from "mitt"; import type { Events } from "@/types/emitter"; import { formatBytes } from "@/utils"; import stateApi from "@/services/api/state"; -import storeRoms from "@/stores/roms"; +import storeRoms, { type Rom } from "@/stores/roms"; import type { StateSchema } from "@/__generated__"; -const props = defineProps(["rom"]); +const props = defineProps<{ rom: Rom }>(); const statesToUpload = ref([]); const selectedStates = ref([]); const emitter = inject>("emitter"); diff --git a/frontend/src/plugins/router.ts b/frontend/src/plugins/router.ts index 2960edb3a..0d3580d59 100644 --- a/frontend/src/plugins/router.ts +++ b/frontend/src/plugins/router.ts @@ -36,23 +36,6 @@ const routes = [ path: "/settings/control-panel/", name: "controlPanel", component: () => import("@/views/Settings/ControlPanel/Base.vue"), - // children: [ - // { - // path: "/settings/control-panel/general", - // name: "controlPanelGeneral", - // component: () => import("@/views/Settings/ControlPanel/General/Base.vue"), - // }, - // { - // path: "/settings/control-panel/config", - // name: "controlPanelConfig", - // component: () => import("@/views/Settings/ControlPanel/Config/Base.vue"), - // }, - // { - // path: "/settings/control-panel/users", - // name: "controlPanelUsers", - // component: () => import("@/views/Settings/ControlPanel/Users/Base.vue"), - // } - // ] }, { path: "/:pathMatch(.*)*", @@ -63,7 +46,7 @@ const routes = [ }, { path: "/play/:rom", - component: () => import("@/components/Details/Emulation.vue"), + component: () => import("@/views/Play/Base.vue"), }, ]; diff --git a/frontend/src/views/Play/Base.vue b/frontend/src/views/Play/Base.vue index 42bc31f65..92cc80865 100644 --- a/frontend/src/views/Play/Base.vue +++ b/frontend/src/views/Play/Base.vue @@ -1,301 +1,123 @@ - - - - - - - - - - - - - - diff --git a/frontend/src/views/Play/Player.vue b/frontend/src/views/Play/Player.vue new file mode 100644 index 000000000..16b190f6c --- /dev/null +++ b/frontend/src/views/Play/Player.vue @@ -0,0 +1,242 @@ + + + + + + + + + + + + + + + + + + + From eb23cec6b9432dcbc8de2d46102660efd18715f1 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 19 Jan 2024 21:35:43 -0500 Subject: [PATCH 10/10] working save and state loading --- frontend/src/views/Play/Player.vue | 36 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/frontend/src/views/Play/Player.vue b/frontend/src/views/Play/Player.vue index 16b190f6c..6d33f1ed4 100644 --- a/frontend/src/views/Play/Player.vue +++ b/frontend/src/views/Play/Player.vue @@ -91,13 +91,13 @@ function buildSaveName(): string { return saveName; } -async function fetchAsset( - asset: SaveSchema | StateSchema | null -): Promise { - if (asset) { - const { data } = await api.get(asset.download_path.replace("/api", "")); - var enc = new TextEncoder(); - return enc.encode(data); +async function fetchState(): Promise { + if (stateRef.value) { + const { data } = await api.get( + stateRef.value.download_path.replace("/api", ""), + { responseType: "arraybuffer" } + ); + return new Uint8Array(data); } else if (window.EJS_emulator.saveInBrowserSupported()) { const data = await window.EJS_emulator.storage.states.get( window.EJS_emulator.getBaseFileName() + ".state" @@ -108,7 +108,7 @@ async function fetchAsset( } window.EJS_onLoadState = async function () { - const stat = await fetchAsset(stateRef.value); + const stat = await fetchState(); window.EJS_emulator.gameManager.loadState(stat); window.EJS_emulator.displayMessage("LOADED FROM ROMM"); }; @@ -157,8 +157,21 @@ window.EJS_onSaveState = function ({ } }; +async function fetchSave(): Promise { + if (saveRef.value) { + const { data } = await api.get( + saveRef.value.download_path.replace("/api", ""), + { responseType: "arraybuffer" } + ); + return new Uint8Array(data); + } + + const file = await window.EJS_emulator.selectFile(); + return new Uint8Array(await file.arrayBuffer()); +} + window.EJS_onLoadSave = async function () { - const sav = await fetchAsset(saveRef.value); + const sav = await fetchSave(); const FS = window.EJS_emulator.Module.FS; const path = window.EJS_emulator.gameManager.getSaveFilePath(); const paths = path.split("/"); @@ -210,10 +223,9 @@ window.EJS_onGameStart = async () => { stateRef.value = props.state; setTimeout(() => { - if (saveRef.value) window.EJS_onLoadSave(); - window.EJS_emulator.gameManager.restart(); if (stateRef.value) window.EJS_onLoadState(); - }, 500); + if (saveRef.value) window.EJS_onLoadSave(); + }, 10); };