From 00d34d7388ef5bd3279e84edb0bfe482fcdfe32d Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 30 Aug 2024 14:35:37 -0400 Subject: [PATCH 01/13] hack to get emujs working in dev mode --- backend/config/__init__.py | 5 +++-- backend/endpoints/rom.py | 15 +++++++++++++++ env.template | 2 +- frontend/vite.config.js | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/backend/config/__init__.py b/backend/config/__init__.py index d48134a00..1ac80f1e6 100644 --- a/backend/config/__init__.py +++ b/backend/config/__init__.py @@ -12,8 +12,9 @@ def str_to_bool(value: str) -> bool: # GUNICORN -DEV_PORT: Final = int(os.environ.get("VITE_BACKEND_DEV_PORT", "5000")) -DEV_HOST: Final = "127.0.0.1" +DEV_MODE: Final = str_to_bool(os.environ.get("DEV_MODE", "false")) +DEV_HOST: Final = os.environ.get("DEV_HOST", "127.0.0.1") +DEV_PORT: Final = int(os.environ.get("DEV_PORT", "5000")) GUNICORN_WORKERS: Final = int(os.environ.get("GUNICORN_WORKERS", 2)) # PATHS diff --git a/backend/endpoints/rom.py b/backend/endpoints/rom.py index 86455e681..c5a361e3a 100644 --- a/backend/endpoints/rom.py +++ b/backend/endpoints/rom.py @@ -6,6 +6,7 @@ from anyio import Path, open_file from config import ( + DEV_MODE, DISABLE_DOWNLOAD_ENDPOINT_AUTH, LIBRARY_BASE_PATH, RESOURCES_BASE_PATH, @@ -23,6 +24,7 @@ from handler.metadata import meta_igdb_handler, meta_moby_handler from logger.logger import log from starlette.requests import ClientDisconnect +from starlette.responses import FileResponse from streaming_form_data import StreamingFormDataParser from streaming_form_data.targets import FileTarget, NullTarget from utils.filesystem import sanitize_filename @@ -178,9 +180,22 @@ async def head_rom_content( if not rom: raise RomNotFoundInDatabaseException(id) + rom_path = f"{LIBRARY_BASE_PATH}/{rom.full_path}" files_to_check = files or [r["filename"] for r in rom.files] if not rom.multi: + # Serve the file directly in development mode for emulatorjs + if DEV_MODE: + return FileResponse( + path=rom_path, + filename=rom.file_name, + headers={ + "Content-Disposition": f'attachment; filename="{quote(rom.file_name)}"', + "Content-Type": "application/octet-stream", + "Content-Length": str(rom.file_size_bytes), + }, + ) + return Response( media_type="application/octet-stream", headers={ diff --git a/env.template b/env.template index 76dd91517..138da2fcf 100644 --- a/env.template +++ b/env.template @@ -1,5 +1,5 @@ ROMM_BASE_PATH=/path/to/romm_mock -VITE_BACKEND_DEV_PORT=5000 +DEV_MODE=true # Gunicorn (optional) GUNICORN_WORKERS=4 # (2 × CPU cores) + 1 diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 749cf0398..51abd248c 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -12,7 +12,7 @@ import { defineConfig, loadEnv } from "vite"; export default defineConfig(({ mode }) => { // Load ENV variables from the parent directory and the current directory. const env = { ...loadEnv(mode, "../"), ...loadEnv(mode, "./") }; - const backendPort = env.VITE_BACKEND_DEV_PORT ?? "5000"; + const backendPort = env.DEV_PORT ?? "5000"; return { build: { From ba41e99dba8874fabd6430e02f7820f34a32b11e Mon Sep 17 00:00:00 2001 From: zurdi Date: Sat, 31 Aug 2024 20:56:44 +0000 Subject: [PATCH 02/13] fix open game in a new tab in gallery/collection --- .../src/components/common/Game/AdminMenu.vue | 18 +++++++++- .../components/common/Game/Card/ActionBar.vue | 35 +++++++++++-------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/common/Game/AdminMenu.vue b/frontend/src/components/common/Game/AdminMenu.vue index bf04f389f..634f994bd 100644 --- a/frontend/src/components/common/Game/AdminMenu.vue +++ b/frontend/src/components/common/Game/AdminMenu.vue @@ -11,6 +11,7 @@ import type { Events } from "@/types/emitter"; import type { Emitter } from "mitt"; import { storeToRefs } from "pinia"; import { inject } from "vue"; +import { useRouter } from "vue-router"; // Props const props = defineProps<{ rom: SimpleRom }>(); @@ -20,8 +21,17 @@ const auth = storeAuth(); const collectionsStore = storeCollections(); const romsStore = storeRoms(); const { favCollection } = storeToRefs(collectionsStore); +const router = useRouter(); // Functions +function openInNewTab() { + const link = router.resolve({ + name: "rom", + params: { rom: props.rom.id }, + }); + window.open(link.href, "_blank"); +} + async function switchFromFavourites() { if (!favCollection.value) { await collectionApi @@ -53,7 +63,7 @@ async function switchFromFavourites() { } else { if (favCollection.value) { favCollection.value.roms = favCollection.value.roms.filter( - (id) => id !== props.rom.id + (id) => id !== props.rom.id, ); if (romsStore.currentCollection?.name.toLowerCase() == "favourites") { romsStore.remove([props.rom]); @@ -89,6 +99,12 @@ async function switchFromFavourites() {