mirror of
https://github.com/rommapp/romm.git
synced 2026-02-18 00:27:41 +01:00
fixup running scans and loading
This commit is contained in:
@@ -183,15 +183,13 @@ class SimpleRomSchema(RomSchema):
|
||||
@classmethod
|
||||
def from_orm_with_request(cls, db_rom: Rom, request: Request) -> SimpleRomSchema:
|
||||
user_id = request.user.id
|
||||
rom = cls.model_validate(db_rom)
|
||||
rom.rom_user = RomUserSchema.for_user(user_id, db_rom)
|
||||
return rom
|
||||
db_rom.rom_user = RomUserSchema.for_user(user_id, db_rom) # type: ignore
|
||||
return cls.model_validate(db_rom)
|
||||
|
||||
@classmethod
|
||||
def from_orm_with_factory(cls, db_rom: Rom) -> SimpleRomSchema:
|
||||
rom = cls.model_validate(db_rom)
|
||||
rom.rom_user = rom_user_schema_factory()
|
||||
return rom
|
||||
db_rom.rom_user = rom_user_schema_factory() # type: ignore
|
||||
return cls.model_validate(db_rom)
|
||||
|
||||
|
||||
class DetailedRomSchema(RomSchema):
|
||||
@@ -208,26 +206,24 @@ class DetailedRomSchema(RomSchema):
|
||||
def from_orm_with_request(cls, db_rom: Rom, request: Request) -> DetailedRomSchema:
|
||||
user_id = request.user.id
|
||||
|
||||
rom = cls.model_validate(db_rom)
|
||||
|
||||
rom.rom_user = RomUserSchema.for_user(user_id, db_rom)
|
||||
rom.user_notes = RomUserSchema.notes_for_user(user_id, db_rom)
|
||||
rom.user_saves = [
|
||||
db_rom.rom_user = RomUserSchema.for_user(user_id, db_rom) # type: ignore
|
||||
db_rom.user_notes = RomUserSchema.notes_for_user(user_id, db_rom) # type: ignore
|
||||
db_rom.user_saves = [ # type: ignore
|
||||
SaveSchema.model_validate(s) for s in db_rom.saves if s.user_id == user_id
|
||||
]
|
||||
rom.user_states = [
|
||||
db_rom.user_states = [ # type: ignore
|
||||
StateSchema.model_validate(s) for s in db_rom.states if s.user_id == user_id
|
||||
]
|
||||
rom.user_screenshots = [
|
||||
db_rom.user_screenshots = [ # type: ignore
|
||||
ScreenshotSchema.model_validate(s)
|
||||
for s in db_rom.screenshots
|
||||
if s.user_id == user_id
|
||||
]
|
||||
rom.user_collections = CollectionSchema.for_user(
|
||||
db_rom.user_collections = CollectionSchema.for_user( # type: ignore
|
||||
user_id, [c for c in db_rom.get_collections()]
|
||||
)
|
||||
|
||||
return rom
|
||||
return cls.model_validate(db_rom)
|
||||
|
||||
|
||||
class UserNotesSchema(TypedDict):
|
||||
|
||||
@@ -428,8 +428,8 @@ async def _identify_rom(
|
||||
RomFile(
|
||||
id=db_rom_file.id if db_rom_file else None,
|
||||
rom_id=_added_rom.id,
|
||||
fs_name=file.file_name,
|
||||
fs_path=file.file_path,
|
||||
file_name=file.file_name,
|
||||
file_path=file.file_path,
|
||||
file_size_bytes=file.file_size_bytes,
|
||||
last_modified=file.last_modified,
|
||||
)
|
||||
@@ -503,22 +503,22 @@ async def scan_handler(_sid: str, options: dict):
|
||||
metadata_sources = options.get("apis", [])
|
||||
|
||||
# Uncomment this to run scan in the current process
|
||||
# await scan_platforms(
|
||||
# platform_ids=platform_ids,
|
||||
# scan_type=scan_type,
|
||||
# roms_ids=roms_ids,
|
||||
# metadata_sources=metadata_sources,
|
||||
# )
|
||||
|
||||
return high_prio_queue.enqueue(
|
||||
scan_platforms,
|
||||
platform_ids,
|
||||
scan_type,
|
||||
roms_ids,
|
||||
metadata_sources,
|
||||
job_timeout=SCAN_TIMEOUT, # Timeout (default of 4 hours)
|
||||
await scan_platforms(
|
||||
platform_ids=platform_ids,
|
||||
scan_type=scan_type,
|
||||
roms_ids=roms_ids,
|
||||
metadata_sources=metadata_sources,
|
||||
)
|
||||
|
||||
# return high_prio_queue.enqueue(
|
||||
# scan_platforms,
|
||||
# platform_ids,
|
||||
# scan_type,
|
||||
# roms_ids,
|
||||
# metadata_sources,
|
||||
# job_timeout=SCAN_TIMEOUT, # Timeout (default of 4 hours)
|
||||
# )
|
||||
|
||||
|
||||
@socket_handler.socket_server.on("scan:stop")
|
||||
async def stop_scan_handler(_sid: str):
|
||||
|
||||
@@ -16,13 +16,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
collection = session.merge(collection)
|
||||
session.flush()
|
||||
|
||||
new_collection = session.scalar(
|
||||
select(Collection).filter_by(id=collection.id).limit(1)
|
||||
)
|
||||
if not new_collection:
|
||||
raise ValueError("Could not find newly created collection")
|
||||
|
||||
return new_collection
|
||||
return session.query(Collection).filter_by(id=collection.id).one()
|
||||
|
||||
@begin_session
|
||||
def get_collection(self, id: int, session: Session = None) -> Collection | None:
|
||||
|
||||
@@ -47,12 +47,13 @@ class DBFirmwareHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def update_firmware(self, id: int, data: dict, session: Session = None) -> Firmware:
|
||||
return session.scalar(
|
||||
session.execute(
|
||||
update(Firmware)
|
||||
.where(Firmware.id == id)
|
||||
.values(**data)
|
||||
.execution_options(synchronize_session="evaluate")
|
||||
)
|
||||
return session.query(Firmware).filter_by(id=id).one()
|
||||
|
||||
@begin_session
|
||||
def delete_firmware(self, id: int, session: Session = None) -> None:
|
||||
|
||||
@@ -19,13 +19,7 @@ class DBPlatformsHandler(DBBaseHandler):
|
||||
platform = session.merge(platform)
|
||||
session.flush()
|
||||
|
||||
new_platform = session.scalar(
|
||||
select(Platform).filter_by(id=platform.id).limit(1)
|
||||
)
|
||||
if not new_platform:
|
||||
raise ValueError("Could not find newly created platform")
|
||||
|
||||
return new_platform
|
||||
return session.query(Platform).filter_by(id=platform.id).one()
|
||||
|
||||
@begin_session
|
||||
def get_platform(self, id: int, *, session: Session = None) -> Platform | None:
|
||||
|
||||
@@ -193,12 +193,13 @@ class DBRomsHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def update_rom(self, id: int, data: dict, session: Session = None) -> Rom:
|
||||
return session.scalar(
|
||||
session.execute(
|
||||
update(Rom)
|
||||
.where(Rom.id == id)
|
||||
.values(**data)
|
||||
.execution_options(synchronize_session="evaluate")
|
||||
)
|
||||
return session.query(Rom).filter_by(id=id).one()
|
||||
|
||||
@begin_session
|
||||
def delete_rom(self, id: int, session: Session = None) -> None:
|
||||
@@ -257,15 +258,9 @@ class DBRomsHandler(DBBaseHandler):
|
||||
.execution_options(synchronize_session="evaluate")
|
||||
)
|
||||
|
||||
rom_user = self.get_rom_user_by_id(id)
|
||||
if not rom_user:
|
||||
raise ValueError(f"RomUser with id {id} not found")
|
||||
|
||||
rom_user = session.query(RomUser).filter_by(id=id).one()
|
||||
if data.get("is_main_sibling", False):
|
||||
rom = self.get_rom(rom_user.rom_id)
|
||||
if not rom:
|
||||
raise ValueError(f"Rom with id {rom_user.rom_id} not found")
|
||||
|
||||
rom = session.query(Rom).filter_by(id=rom_user.rom_id).one()
|
||||
session.execute(
|
||||
update(RomUser)
|
||||
.where(
|
||||
@@ -277,11 +272,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
.values(is_main_sibling=False)
|
||||
)
|
||||
|
||||
rom_user = self.get_rom_user_by_id(id)
|
||||
if not rom_user:
|
||||
raise ValueError(f"RomUser with id {id} not found")
|
||||
|
||||
return rom_user
|
||||
return session.query(RomUser).filter_by(id=id).one()
|
||||
|
||||
@begin_session
|
||||
def add_rom_file(self, rom_file: RomFile, session: Session = None) -> RomFile:
|
||||
@@ -312,8 +303,4 @@ class DBRomsHandler(DBBaseHandler):
|
||||
.execution_options(synchronize_session="evaluate")
|
||||
)
|
||||
|
||||
rom_file = self.get_rom_file_by_id(id)
|
||||
if not rom_file:
|
||||
raise ValueError(f"RomFile with id {id} not found")
|
||||
|
||||
return rom_file
|
||||
return session.query(RomFile).filter_by(id=id).one()
|
||||
|
||||
@@ -29,12 +29,13 @@ class DBSavesHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def update_save(self, id: int, data: dict, session: Session = None) -> Save:
|
||||
return session.scalar(
|
||||
session.execute(
|
||||
update(Save)
|
||||
.where(Save.id == id)
|
||||
.values(**data)
|
||||
.execution_options(synchronize_session="evaluate")
|
||||
)
|
||||
return session.query(Save).filter_by(id=id).one()
|
||||
|
||||
@begin_session
|
||||
def delete_save(self, id: int, session: Session = None) -> None:
|
||||
|
||||
@@ -33,12 +33,13 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
def update_screenshot(
|
||||
self, id: int, data: dict, session: Session = None
|
||||
) -> Screenshot:
|
||||
return session.scalar(
|
||||
session.execute(
|
||||
update(Screenshot)
|
||||
.where(Screenshot.id == id)
|
||||
.values(**data)
|
||||
.execution_options(synchronize_session="evaluate")
|
||||
)
|
||||
return session.query(Screenshot).filter_by(id=id).one()
|
||||
|
||||
@begin_session
|
||||
def delete_screenshot(self, id: int, session: Session = None) -> None:
|
||||
|
||||
@@ -29,12 +29,13 @@ class DBStatesHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def update_state(self, id: int, data: dict, session: Session = None) -> State:
|
||||
return session.scalar(
|
||||
session.execute(
|
||||
update(State)
|
||||
.where(State.id == id)
|
||||
.values(**data)
|
||||
.execution_options(synchronize_session="evaluate")
|
||||
)
|
||||
return session.query(State).filter_by(id=id).one()
|
||||
|
||||
@begin_session
|
||||
def delete_state(self, id: int, session: Session = None) -> None:
|
||||
|
||||
@@ -29,12 +29,13 @@ class DBUsersHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def update_user(self, id: int, data: dict, session: Session = None) -> User:
|
||||
return session.scalar(
|
||||
session.execute(
|
||||
update(User)
|
||||
.where(User.id == id)
|
||||
.values(**data)
|
||||
.execution_options(synchronize_session="evaluate")
|
||||
)
|
||||
return session.query(User).filter_by(id=id).one()
|
||||
|
||||
@begin_session
|
||||
def get_users(self, session: Session = None) -> Sequence[User]:
|
||||
|
||||
@@ -7,9 +7,8 @@ import shutil
|
||||
import tarfile
|
||||
import zipfile
|
||||
from collections.abc import Callable, Iterator
|
||||
from hashlib import _Hash
|
||||
from pathlib import Path
|
||||
from typing import Final, Literal, TypedDict
|
||||
from typing import Any, Final, Literal, TypedDict
|
||||
|
||||
import magic
|
||||
import py7zr
|
||||
@@ -264,9 +263,9 @@ class FSRomsHandler(FSHandler):
|
||||
self,
|
||||
file_path: Path,
|
||||
rom_crc_c: int,
|
||||
rom_md5_h: _Hash,
|
||||
rom_sha1_h: _Hash,
|
||||
) -> tuple[int, int, _Hash, _Hash, _Hash, _Hash]:
|
||||
rom_md5_h: Any,
|
||||
rom_sha1_h: Any,
|
||||
) -> tuple[int, int, Any, Any, Any, Any]:
|
||||
mime = magic.Magic(mime=True)
|
||||
file_type = mime.from_file(file_path)
|
||||
extension = Path(file_path).suffix.lower()
|
||||
|
||||
@@ -183,8 +183,9 @@ async def scan_rom(
|
||||
|
||||
# Set default properties
|
||||
rom_attrs = {
|
||||
**fs_rom,
|
||||
"id": rom.id if rom else None,
|
||||
"multi": fs_rom["multi"],
|
||||
"fs_name": fs_rom["fs_name"],
|
||||
"platform_id": platform.id,
|
||||
"name": fs_rom["fs_name"],
|
||||
"url_cover": "",
|
||||
@@ -212,7 +213,7 @@ async def scan_rom(
|
||||
)
|
||||
|
||||
# Update properties that don't require metadata
|
||||
filesize = sum([file["size"] for file in rom_attrs["files"]])
|
||||
filesize = sum([file.file_size_bytes for file in fs_rom["files"]])
|
||||
regs, rev, langs, other_tags = fs_rom_handler.parse_tags(rom_attrs["fs_name"])
|
||||
rom_attrs.update(
|
||||
{
|
||||
|
||||
@@ -32,8 +32,9 @@ async def test_scan_rom():
|
||||
async with initialize_context():
|
||||
files = [
|
||||
RomFile(
|
||||
filename="Paper Mario (USA).z64",
|
||||
size=1024,
|
||||
file_name="Paper Mario (USA).z64",
|
||||
file_path="Paper Mario (USA)",
|
||||
file_size_bytes=1024,
|
||||
last_modified=1620000000,
|
||||
)
|
||||
]
|
||||
|
||||
@@ -105,8 +105,7 @@ class Rom(BaseModel):
|
||||
primaryjoin="Rom.id == SiblingRom.rom_id",
|
||||
secondaryjoin="Rom.id == SiblingRom.sibling_rom_id",
|
||||
)
|
||||
|
||||
files: Mapped[list[RomFile]] = relationship(back_populates="rom")
|
||||
files: Mapped[list[RomFile]] = relationship(back_populates="rom", lazy="immediate")
|
||||
saves: Mapped[list[Save]] = relationship(back_populates="rom")
|
||||
states: Mapped[list[State]] = relationship(back_populates="rom")
|
||||
screenshots: Mapped[list[Screenshot]] = relationship(back_populates="rom")
|
||||
|
||||
@@ -143,7 +143,7 @@ function closeDialog() {
|
||||
hide-default-header
|
||||
>
|
||||
<template #item.name="{ item }">
|
||||
<rom-list-item :rom="item" with-filename />
|
||||
<rom-list-item :rom="item" with-filename with-size />
|
||||
</template>
|
||||
<template #bottom>
|
||||
<v-divider />
|
||||
|
||||
@@ -116,7 +116,7 @@ function closeDialog() {
|
||||
hide-default-header
|
||||
>
|
||||
<template #item.name="{ item }">
|
||||
<rom-list-item :rom="item" with-filename />
|
||||
<rom-list-item :rom="item" with-filename with-size />
|
||||
</template>
|
||||
<template #bottom>
|
||||
<v-divider />
|
||||
|
||||
@@ -122,7 +122,7 @@ function closeDialog() {
|
||||
show-select
|
||||
>
|
||||
<template #item.name="{ item }">
|
||||
<rom-list-item :rom="item" with-filename>
|
||||
<rom-list-item :rom="item" with-filename with-size>
|
||||
<template #append-body>
|
||||
<v-row v-if="romsToDeleteFromFs.includes(item.id)" no-gutters>
|
||||
<v-col>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import RAvatarRom from "@/components/common/Game/RAvatar.vue";
|
||||
import { formatBytes } from "@/utils";
|
||||
import { useDisplay } from "vuetify";
|
||||
|
||||
// Props
|
||||
withDefaults(
|
||||
@@ -18,7 +17,7 @@ withDefaults(
|
||||
withAvatar: true,
|
||||
withName: true,
|
||||
withFilename: false,
|
||||
withSize: true,
|
||||
withSize: false,
|
||||
withLink: false,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -134,7 +134,7 @@ onMounted(async () => {
|
||||
src="/assets/emulatorjs/powered_by_emulatorjs.png"
|
||||
/>
|
||||
<v-divider class="my-4" />
|
||||
<rom-list-item :rom="rom" with-filename />
|
||||
<rom-list-item :rom="rom" with-filename with-size />
|
||||
<v-divider class="my-4" />
|
||||
<v-select
|
||||
v-if="supportedCores.length > 1"
|
||||
|
||||
@@ -98,7 +98,7 @@ onMounted(async () => {
|
||||
src="/assets/ruffle/powered_by_ruffle.png"
|
||||
/>
|
||||
<v-divider class="my-4" />
|
||||
<rom-list-item :rom="rom" with-filename />
|
||||
<rom-list-item :rom="rom" with-filename with-size />
|
||||
<v-divider class="my-4" />
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
Reference in New Issue
Block a user