Skip to content

Commit

Permalink
Merge pull request #1171 from rommapp/master
Browse files Browse the repository at this point in the history
v3.5.1
  • Loading branch information
gantoine authored Sep 5, 2024
2 parents 410007b + 3094d46 commit 2de682a
Show file tree
Hide file tree
Showing 47 changed files with 273 additions and 205 deletions.
Binary file added .github/resources/romm_complete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.22.3
version: 1.22.4
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.6.1
ref: v1.6.2
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
runtimes:
Expand All @@ -19,24 +19,24 @@ runtimes:
lint:
enabled:
- [email protected]
- [email protected].0
- [email protected].1
- [email protected]
- [email protected]
- [email protected]
- [email protected].228
- [email protected].239
- git-diff-check
- [email protected]
- [email protected].1
- [email protected].3
- [email protected].2
- [email protected].4
- [email protected]
- [email protected]
- [email protected].0
- [email protected].3
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected].9
- [email protected].10
- [email protected]
ignore:
- linters: [ALL]
Expand Down
79 changes: 40 additions & 39 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
{
"tasks": [
{
"label": "Launch frontend",
"type": "npm",
"path": "frontend",
"script": "dev",
"problemMatcher": []
},
{
"label": "Launch backend",
"type": "shell",
"command": "cd backend && poetry run python3 main.py",
"problemMatcher": []
},
{
"label": "Launch worker",
"type": "shell",
"command": "cd backend && poetry run python3 worker.py",
"problemMatcher": []
},
{
"label": "Execute tests",
"type": "shell",
"command": "cd backend && poetry run pytest -vv -c ../pytest.ini",
"problemMatcher": []
},
{
"label": "Setup development environment",
"type": "shell",
"command": "docker compose up -d",
"problemMatcher": []
},
{
"label": "Setup testing environment",
"type": "shell",
"command": "export $(cat .env | grep DB_ROOT_PASSWD | xargs) && docker exec -i mariadb mariadb -u root -p$DB_ROOT_PASSWD < backend/romm_test/setup.sql",
"problemMatcher": []
}
]
"version": "2.0.0",
"tasks": [
{
"label": "Launch frontend",
"type": "npm",
"path": "frontend",
"script": "dev",
"problemMatcher": []
},
{
"label": "Launch backend",
"type": "shell",
"command": "cd backend && poetry run python3 main.py",
"problemMatcher": []
},
{
"label": "Launch worker",
"type": "shell",
"command": "cd backend && poetry run python3 worker.py",
"problemMatcher": []
},
{
"label": "Execute tests",
"type": "shell",
"command": "cd backend && poetry run pytest -vv -c ../pytest.ini",
"problemMatcher": []
},
{
"label": "Setup development environment",
"type": "shell",
"command": "docker compose up -d",
"problemMatcher": []
},
{
"label": "Setup testing environment",
"type": "shell",
"command": "export $(cat .env | grep DB_ROOT_PASSWD | xargs) && docker exec -i mariadb mariadb -u root -p$DB_ROOT_PASSWD < backend/romm_test/setup.sql",
"problemMatcher": []
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- trunk-ignore(markdownlint/MD041) -->
<div align="center">

<img src=".github/resources/romm_complete.svg" height="220px" width="auto" alt="romm logo">
<img src=".github/resources/romm_complete.png" height="220px" width="auto" alt="romm logo">

<h3 style="font-size: 25px;">
A beautiful, powerful, self-hosted rom manager.
Expand Down
5 changes: 3 additions & 2 deletions backend/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions backend/endpoints/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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={
Expand Down
6 changes: 3 additions & 3 deletions backend/handler/database/roms_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ def update_rom_user(self, id: int, data: dict, session: Session = None) -> RomUs
rom_user = self.get_rom_user_by_id(id)

if data["is_main_sibling"]:
rom = self.get_rom(rom_user.rom_id)

session.execute(
update(RomUser)
.where(
and_(
RomUser.rom_id.in_(
[rom.id for rom in rom_user.rom.get_sibling_roms()]
),
RomUser.rom_id.in_(r.id for r in rom.sibling_roms),
RomUser.user_id == rom_user.user_id,
)
)
Expand Down
14 changes: 13 additions & 1 deletion backend/handler/filesystem/roms_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@

import magic
import py7zr
import zipfile_deflate64 # trunk-ignore(ruff/F401): Patches zipfile to support deflate64 compression
from config import LIBRARY_BASE_PATH
from config.config_manager import config_manager as cm
from exceptions.fs_exceptions import RomAlreadyExistsException, RomsNotFoundException
from models.rom import RomFile
from py7zr.exceptions import (
Bad7zFile,
DecompressionError,
PasswordRequired,
UnsupportedCompressionMethodError,
)
from utils.filesystem import iter_directories, iter_files
from utils.hashing import crc32_to_hex

Expand Down Expand Up @@ -108,7 +115,12 @@ def read_7z_file(file_path: Path) -> Iterator[bytes]:
for _name, bio in f.readall().items():
while chunk := bio.read(FILE_READ_CHUNK_SIZE):
yield chunk
except py7zr.Bad7zFile:
except (
Bad7zFile,
DecompressionError,
PasswordRequired,
UnsupportedCompressionMethodError,
):
for chunk in read_basic_file(file_path):
yield chunk

Expand Down
1 change: 1 addition & 0 deletions backend/handler/metadata/igdb_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ async def wrapper(*args):

return wrapper

# trunk-ignore(ruff/ASYNC109): timeout is used for request
async def _request(self, url: str, data: str, timeout: int = 120) -> list:
httpx_client = ctx_httpx_client.get()
try:
Expand Down
8 changes: 7 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
yield


app = FastAPI(title="RomM API", version=get_version(), lifespan=lifespan)
app = FastAPI(
title="RomM API",
version=get_version(),
lifespan=lifespan,
docs_url="/api/docs",
redoc_url="/api/redoc",
)

app.add_middleware(
CORSMiddleware,
Expand Down
2 changes: 1 addition & 1 deletion env.template
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 7 additions & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/site.webmanifest" />
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#9205f2" />
<meta name="msapplication-TileColor" content="#9205f2" />
<meta name="theme-color" content="#2a0145" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RomM</title>
Expand Down
Binary file added frontend/public/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions frontend/public/browserconfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<TileColor>#9205f2</TileColor>
</tile>
</msapplication>
</browserconfig>
Binary file added frontend/public/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/favicon.ico
Binary file not shown.
Binary file added frontend/public/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/public/safari-pinned-tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions frontend/public/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "RomM",
"short_name": "RomM",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#2a0145",
"background_color": "#2a0145",
"display": "standalone"
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ function closeDialog() {
imagePreviewUrl
? imagePreviewUrl
: user.avatar_path
? `/assets/romm/assets/${user.avatar_path}?ts=${user.updated_at}`
: defaultAvatarPath
? `/assets/romm/assets/${user.avatar_path}?ts=${user.updated_at}`
: defaultAvatarPath
"
>
<v-fade-transition>
Expand Down
10 changes: 3 additions & 7 deletions frontend/src/components/Details/Notes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const romUser = ref(
note_raw_markdown: "",
note_is_public: false,
is_main_sibling: false,
}
},
);
const publicNotes =
props.rom.user_notes?.filter((note) => note.user_id !== auth.user?.id) ?? [];
Expand Down Expand Up @@ -61,7 +61,7 @@ watch(
note_is_public: false,
is_main_sibling: false,
};
}
},
);
</script>
<template>
Expand Down Expand Up @@ -131,11 +131,7 @@ watch(
</v-card-text>
</v-card>

<v-card
rounded="0"
v-if="publicNotes && publicNotes.length > 0"
class="mt-2"
>
<v-card rounded="0" v-if="publicNotes && publicNotes.length > 0" class="mt-2">
<v-card-title class="bg-terciary">
<v-list-item class="pl-2 pr-0">
<span class="text-h6">Public notes</span>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Details/Saves.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function downloasSaves() {
function updateDataTablePages() {
if (props.rom.user_saves) {
pageCount.value = Math.ceil(
props.rom.user_saves.length / itemsPerPage.value
props.rom.user_saves.length / itemsPerPage.value,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Details/States.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function downloasStates() {
function updateDataTablePages() {
if (props.rom.user_states) {
pageCount.value = Math.ceil(
props.rom.user_states.length / itemsPerPage.value
props.rom.user_states.length / itemsPerPage.value,
);
}
}
Expand Down
Loading

0 comments on commit 2de682a

Please sign in to comment.