Skip to content

Commit

Permalink
Merge pull request #1061 from rommapp/master
Browse files Browse the repository at this point in the history
v3.4.0
  • Loading branch information
zurdi15 authored Aug 7, 2024
2 parents 0a7fd2a + 51ee99e commit 348fc8d
Show file tree
Hide file tree
Showing 160 changed files with 1,638 additions and 31,897 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ name: Run Pytest

on:
pull_request:
paths-ignore:
- "docker/**"
- "examples/*"
- "frontend/**"
paths:
- "backend/**"
push:
branches:
- "master"
paths-ignore:
- "docker/**"
- "examples/*"
- "frontend/**"
paths:
- "backend/**"

permissions: read-all

Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run Typescript Typecheck

on:
pull_request:
paths:
- "frontend/**"
push:
branches:
- "master"
paths:
- "frontend/**"

permissions: read-all

jobs:
typecheck:
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18"

- name: Install dependencies
run: npm install
working-directory: frontend

- name: Run typecheck
run: npm run typecheck
working-directory: frontend
8 changes: 7 additions & 1 deletion .trunk/configs/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[lint]
# Generic, formatter-friendly config.
select = ["B", "D3", "E", "F"]
# ASYNC: flake8-async.
# B: flake8-bugbear.
# D3: flake8-docstrings (D3xx).
# E: pycodestyle errors.
# F: Pyflakes.
select = ["ASYNC", "B", "D3", "E", "F"]

# Never enforce `E501` (line length violations). This should be handled by formatters.
ignore = ["E501"]
2 changes: 1 addition & 1 deletion .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ lint:
ignore:
- linters: [ALL]
paths:
- src/__generated__/**
- frontend/src/__generated__/**
- docker/Dockerfile
definitions:
- name: eslint
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPER_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ touch romm_mock/library/roms/switch/metroid.xci
mkdir -p romm_mock/resources
mkdir -p romm_mock/assets
mkdir -p romm_mock/config
touch romm_mock/config.yml
touch romm_mock/config/config.yml
```

### Setting up the backend
Expand Down
5 changes: 3 additions & 2 deletions backend/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
ROMM_DB_DRIVER: Final = os.environ.get("ROMM_DB_DRIVER", "mariadb")

# AUTH
ROMM_AUTH_USERNAME: Final = os.environ.get("ROMM_AUTH_USERNAME", "admin")
ROMM_AUTH_PASSWORD: Final = os.environ.get("ROMM_AUTH_PASSWORD", "admin")
ROMM_AUTH_SECRET_KEY: Final = os.environ.get(
"ROMM_AUTH_SECRET_KEY", secrets.token_hex(32)
)
Expand Down Expand Up @@ -85,3 +83,6 @@
"SCHEDULED_UPDATE_SWITCH_TITLEDB_CRON",
"0 4 * * *", # At 4:00 AM every day
)

# TESTING
IS_PYTEST_RUN: Final = bool(os.environ.get("PYTEST_VERSION", False))
3 changes: 2 additions & 1 deletion backend/endpoints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from endpoints.responses import MessageResponse
from endpoints.responses.oauth import TokenResponse
from exceptions.auth_exceptions import AuthCredentialsException, DisabledException
from fastapi import APIRouter, Depends, HTTPException, Request, status
from fastapi import Depends, HTTPException, Request, status
from fastapi.security.http import HTTPBasic
from handler.auth import auth_handler, oauth_handler
from handler.database import db_user_handler
from utils.router import APIRouter

ACCESS_TOKEN_EXPIRE_MINUTES: Final = 30
REFRESH_TOKEN_EXPIRE_DAYS: Final = 7
Expand Down
40 changes: 21 additions & 19 deletions backend/endpoints/collections.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from shutil import rmtree

from anyio import open_file
from config import RESOURCES_BASE_PATH
from decorators.auth import protected_route
from endpoints.responses import MessageResponse
Expand All @@ -10,13 +11,14 @@
CollectionNotFoundInDatabaseException,
CollectionPermissionError,
)
from fastapi import APIRouter, Request, UploadFile
from fastapi import Request, UploadFile
from handler.database import db_collection_handler
from handler.filesystem import fs_resource_handler
from handler.filesystem.base_handler import CoverSize
from logger.logger import log
from models.collection import Collection
from sqlalchemy.inspection import inspect
from utils.router import APIRouter

router = APIRouter()

Expand Down Expand Up @@ -58,19 +60,19 @@ async def add_collection(
path_cover_l,
path_cover_s,
artwork_path,
) = fs_resource_handler.build_artwork_path(_added_collection, file_ext)
) = await fs_resource_handler.build_artwork_path(_added_collection, file_ext)

artwork_file = artwork.file.read()
file_location_s = f"{artwork_path}/small.{file_ext}"
with open(file_location_s, "wb+") as artwork_s:
artwork_s.write(artwork_file)
async with await open_file(file_location_s, "wb+") as artwork_s:
await artwork_s.write(artwork_file)
fs_resource_handler.resize_cover_to_small(file_location_s)

file_location_l = f"{artwork_path}/big.{file_ext}"
with open(file_location_l, "wb+") as artwork_l:
artwork_l.write(artwork_file)
async with await open_file(file_location_l, "wb+") as artwork_l:
await artwork_l.write(artwork_file)
else:
path_cover_s, path_cover_l = fs_resource_handler.get_cover(
path_cover_s, path_cover_l = await fs_resource_handler.get_cover(
overwrite=True,
entity=_added_collection,
url_cover=_added_collection.url_cover,
Expand Down Expand Up @@ -100,7 +102,8 @@ def get_collections(request: Request) -> list[CollectionSchema]:
list[CollectionSchema]: List of collections
"""

return db_collection_handler.get_collections(user_id=request.user.id)
collections = db_collection_handler.get_collections()
return CollectionSchema.for_user(request.user.id, collections)


@protected_route(router.get, "/collections/{id}", ["collections.read"])
Expand Down Expand Up @@ -128,6 +131,7 @@ async def update_collection(
request: Request,
id: int,
remove_cover: bool = False,
is_public: bool | None = None,
artwork: UploadFile | None = None,
) -> CollectionSchema:
"""Update collection endpoint
Expand Down Expand Up @@ -159,8 +163,8 @@ async def update_collection(
cleaned_data = {
"name": data.get("name", collection.name),
"description": data.get("description", collection.description),
"is_public": is_public if is_public is not None else collection.is_public,
"roms": list(set(roms)),
"is_public": data.get("is_public", collection.is_public),
"user_id": request.user.id,
}

Expand All @@ -174,31 +178,29 @@ async def update_collection(
path_cover_l,
path_cover_s,
artwork_path,
) = fs_resource_handler.build_artwork_path(collection, file_ext)
) = await fs_resource_handler.build_artwork_path(collection, file_ext)

cleaned_data["path_cover_l"] = path_cover_l
cleaned_data["path_cover_s"] = path_cover_s

artwork_file = artwork.file.read()
file_location_s = f"{artwork_path}/small.{file_ext}"
with open(file_location_s, "wb+") as artwork_s:
artwork_s.write(artwork_file)
async with await open_file(file_location_s, "wb+") as artwork_s:
await artwork_s.write(artwork_file)
fs_resource_handler.resize_cover_to_small(file_location_s)

file_location_l = f"{artwork_path}/big.{file_ext}"
with open(file_location_l, "wb+") as artwork_l:
artwork_l.write(artwork_file)
async with await open_file(file_location_l, "wb+") as artwork_l:
await artwork_l.write(artwork_file)
cleaned_data.update({"url_cover": ""})
else:
if data.get(
"url_cover", ""
) != collection.url_cover or not fs_resource_handler.cover_exists(
collection, CoverSize.BIG
if data.get("url_cover", "") != collection.url_cover or not (
await fs_resource_handler.cover_exists(collection, CoverSize.BIG)
):
cleaned_data.update(
{"url_cover": data.get("url_cover", collection.url_cover)}
)
path_cover_s, path_cover_l = fs_resource_handler.get_cover(
path_cover_s, path_cover_l = await fs_resource_handler.get_cover(
overwrite=True,
entity=collection,
url_cover=data.get("url_cover", ""),
Expand Down
3 changes: 2 additions & 1 deletion backend/endpoints/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
ConfigNotReadableException,
ConfigNotWritableException,
)
from fastapi import APIRouter, HTTPException, Request, status
from fastapi import HTTPException, Request, status
from logger.logger import log
from utils.router import APIRouter

router = APIRouter()

Expand Down
3 changes: 2 additions & 1 deletion backend/endpoints/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
TinfoilFeedSchema,
WebrcadeFeedSchema,
)
from fastapi import APIRouter, Request
from fastapi import Request
from handler.database import db_platform_handler, db_rom_handler
from models.rom import Rom
from utils.router import APIRouter

router = APIRouter()

Expand Down
3 changes: 2 additions & 1 deletion backend/endpoints/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from decorators.auth import protected_route
from endpoints.responses import MessageResponse
from endpoints.responses.firmware import AddFirmwareResponse, FirmwareSchema
from fastapi import APIRouter, File, HTTPException, Request, UploadFile, status
from fastapi import File, HTTPException, Request, UploadFile, status
from fastapi.responses import FileResponse
from handler.database import db_firmware_handler, db_platform_handler
from handler.filesystem import fs_firmware_handler
from handler.scan_handler import scan_firmware
from logger.logger import log
from utils.router import APIRouter

router = APIRouter()

Expand Down
4 changes: 2 additions & 2 deletions backend/endpoints/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
SCHEDULED_UPDATE_SWITCH_TITLEDB_CRON,
)
from endpoints.responses.heartbeat import HeartbeatResponse
from fastapi import APIRouter
from handler.database import db_user_handler
from handler.filesystem import fs_platform_handler
from handler.metadata.igdb_handler import IGDB_API_ENABLED
from handler.metadata.moby_handler import MOBY_API_ENABLED
from handler.metadata.sgdb_handler import STEAMGRIDDB_API_ENABLED
from utils import get_version
from utils.router import APIRouter

router = APIRouter()


@router.get("/heartbeat")
def heartbeat() -> HeartbeatResponse:
"""Endpoint to set the CSFR token in cache and return all the basic RomM config
"""Endpoint to set the CSRF token in cache and return all the basic RomM config
Returns:
HeartbeatReturn: TypedDict structure with all the defined values in the HeartbeatReturn class.
Expand Down
5 changes: 3 additions & 2 deletions backend/endpoints/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
from endpoints.responses.platform import PlatformSchema
from exceptions.endpoint_exceptions import PlatformNotFoundInDatabaseException
from exceptions.fs_exceptions import PlatformAlreadyExistsException
from fastapi import APIRouter, Request
from fastapi import Request
from handler.database import db_platform_handler
from handler.filesystem import fs_platform_handler
from handler.metadata.igdb_handler import IGDB_PLATFORM_LIST
from handler.scan_handler import scan_platform
from logger.logger import log
from models.platform import Platform
from utils.router import APIRouter

router = APIRouter()

Expand All @@ -33,7 +34,7 @@ async def add_platforms(request: Request) -> PlatformSchema:
fs_platform_handler.add_platforms(fs_slug=fs_slug)
except PlatformAlreadyExistsException:
log.info(f"Detected platform: {fs_slug}")
scanned_platform = scan_platform(fs_slug, [fs_slug])
scanned_platform = await scan_platform(fs_slug, [fs_slug])
return db_platform_handler.add_platform(scanned_platform)


Expand Down
3 changes: 2 additions & 1 deletion backend/endpoints/raw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from config import ASSETS_BASE_PATH
from decorators.auth import protected_route
from fastapi import APIRouter, Request
from fastapi import Request
from fastapi.responses import FileResponse
from utils.router import APIRouter

router = APIRouter()

Expand Down
11 changes: 11 additions & 0 deletions backend/endpoints/responses/collection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime

from models.collection import Collection
from pydantic import BaseModel


Expand All @@ -22,3 +23,13 @@ class CollectionSchema(BaseModel):

class Config:
from_attributes = True

@classmethod
def for_user(
cls, user_id: int, collections: list["Collection"]
) -> list["CollectionSchema"]:
return [
cls.model_validate(c)
for c in collections
if c.user_id == user_id or c.is_public
]
Loading

0 comments on commit 348fc8d

Please sign in to comment.