mirror of
https://github.com/rommapp/romm.git
synced 2026-06-27 22:35:57 +00:00
cleanup for simplicity
This commit is contained in:
@@ -301,21 +301,23 @@ class RomSchema(BaseModel):
|
||||
merged_screenshots: list[str]
|
||||
merged_ra_metadata: RomRAMetadata | None
|
||||
|
||||
files: list[RomFileSchema]
|
||||
siblings: list[SiblingRomSchema]
|
||||
files: list[RomFileSchema] = Field(validation_alias="included_files")
|
||||
sibling_roms: list[SiblingRomSchema] = Field(
|
||||
validation_alias="included_sibling_roms"
|
||||
)
|
||||
|
||||
@field_validator("files")
|
||||
def sort_files(cls, v: list[RomFileSchema]) -> list[RomFileSchema]:
|
||||
return sorted(v, key=lambda x: x.file_name)
|
||||
|
||||
@field_validator("siblings")
|
||||
def sort_siblings(cls, v: list[SiblingRomSchema]) -> list[SiblingRomSchema]:
|
||||
@field_validator("sibling_roms")
|
||||
def sort_sibling_roms(cls, v: list[SiblingRomSchema]) -> list[SiblingRomSchema]:
|
||||
return sorted(v, key=lambda x: x.sort_comparator)
|
||||
|
||||
@classmethod
|
||||
def populate_properties(cls, db_rom: Rom, request: Request) -> Rom:
|
||||
db_rom.rom_user = RomUserSchema.for_user(request.user.id, db_rom) # type: ignore
|
||||
db_rom.has_notes = any( # type: ignore
|
||||
db_rom.rom_user = RomUserSchema.for_user(request.user.id, db_rom) # type: ignore[assignment]
|
||||
db_rom.has_notes = any( # type: ignore[assignment]
|
||||
note.is_public or note.user_id == request.user.id for note in db_rom.notes
|
||||
)
|
||||
return db_rom
|
||||
@@ -367,18 +369,18 @@ class SimpleRomSchema(RomSchema):
|
||||
siblings: Sequence[Rom] | None = None,
|
||||
) -> SimpleRomSchema:
|
||||
db_rom = cls.populate_properties(db_rom, request)
|
||||
db_rom.files = files or [] # type: ignore
|
||||
db_rom.siblings = ( # type: ignore
|
||||
db_rom.included_files = files or [] # type: ignore[assignment]
|
||||
db_rom.included_sibling_roms = ( # type: ignore[assignment]
|
||||
[SiblingRomSchema.from_rom(s) for s in siblings] if siblings else []
|
||||
)
|
||||
return cls.model_validate(db_rom)
|
||||
|
||||
@classmethod
|
||||
def from_orm_with_factory(cls, db_rom: Rom) -> SimpleRomSchema:
|
||||
db_rom.rom_user = rom_user_schema_factory() # type: ignore
|
||||
db_rom.files = [] # type: ignore
|
||||
db_rom.siblings = [] # type: ignore
|
||||
db_rom.has_notes = False # type: ignore
|
||||
db_rom.rom_user = rom_user_schema_factory() # type: ignore[assignment]
|
||||
db_rom.included_files = [] # type: ignore[assignment]
|
||||
db_rom.included_sibling_roms = [] # type: ignore[assignment]
|
||||
db_rom.has_notes = False # type: ignore[assignment]
|
||||
return cls.model_validate(db_rom)
|
||||
|
||||
|
||||
@@ -416,20 +418,21 @@ class DetailedRomSchema(RomSchema):
|
||||
(SiblingRomSchema.from_rom(s) for s in db_rom.sibling_roms),
|
||||
key=lambda x: x.sort_comparator,
|
||||
)
|
||||
db_rom.siblings = sorted_siblings # type: ignore
|
||||
db_rom.included_sibling_roms = sorted_siblings # type: ignore[assignment]
|
||||
db_rom.included_files = sorted(db_rom.files, key=lambda x: x.file_name) # type: ignore[assignment]
|
||||
|
||||
db_rom.user_saves = [ # type: ignore
|
||||
db_rom.user_saves = [ # type: ignore[assignment]
|
||||
SaveSchema.model_validate(s) for s in db_rom.saves if s.user_id == user_id
|
||||
]
|
||||
db_rom.user_states = [ # type: ignore
|
||||
db_rom.user_states = [ # type: ignore[assignment]
|
||||
StateSchema.model_validate(s) for s in db_rom.states if s.user_id == user_id
|
||||
]
|
||||
db_rom.user_screenshots = [ # type: ignore
|
||||
db_rom.user_screenshots = [ # type: ignore[assignment]
|
||||
ScreenshotSchema.model_validate(s)
|
||||
for s in db_rom.screenshots
|
||||
if s.user_id == user_id
|
||||
]
|
||||
db_rom.user_collections = UserCollectionSchema.for_user( # type: ignore
|
||||
db_rom.user_collections = UserCollectionSchema.for_user( # type: ignore[assignment]
|
||||
user_id, db_rom.collections
|
||||
)
|
||||
|
||||
@@ -456,7 +459,7 @@ class DetailedRomSchema(RomSchema):
|
||||
|
||||
# Sort notes by updated_at (most recent first)
|
||||
all_notes.sort(key=lambda x: x.updated_at, reverse=True)
|
||||
db_rom.all_user_notes = all_notes # type: ignore
|
||||
db_rom.all_user_notes = all_notes # type: ignore[assignment]
|
||||
|
||||
return cls.model_validate(db_rom)
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ from handler.metadata.ra_handler import RAGameRom, RAHandler
|
||||
from handler.metadata.ss_handler import SSHandler, SSRom
|
||||
from models.platform import Platform
|
||||
from models.rom import Rom, RomFile
|
||||
from models.user import User
|
||||
|
||||
MOCK_IGDB_ID = 11111
|
||||
MOCK_MOBY_ID = 22222
|
||||
|
||||
@@ -91,7 +91,7 @@ export type DetailedRomSchema = {
|
||||
merged_screenshots: Array<string>;
|
||||
merged_ra_metadata: (RomRAMetadata | null);
|
||||
files: Array<RomFileSchema>;
|
||||
siblings: Array<SiblingRomSchema>;
|
||||
sibling_roms: Array<SiblingRomSchema>;
|
||||
user_saves: Array<SaveSchema>;
|
||||
user_states: Array<StateSchema>;
|
||||
user_screenshots: Array<ScreenshotSchema>;
|
||||
|
||||
@@ -86,6 +86,6 @@ export type SimpleRomSchema = {
|
||||
merged_screenshots: Array<string>;
|
||||
merged_ra_metadata: (RomRAMetadata | null);
|
||||
files: Array<RomFileSchema>;
|
||||
siblings: Array<SiblingRomSchema>;
|
||||
sibling_roms: Array<SiblingRomSchema>;
|
||||
};
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ watch(
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row
|
||||
v-if="rom.siblings.length > 0"
|
||||
v-if="rom.sibling_roms.length > 0"
|
||||
class="align-center my-3"
|
||||
no-gutters
|
||||
>
|
||||
|
||||
@@ -25,7 +25,7 @@ function updateVersion() {
|
||||
max-width="fit-content"
|
||||
hide-details
|
||||
:items="
|
||||
[rom, ...rom.siblings].map((i) => ({
|
||||
[rom, ...rom.sibling_roms].map((i) => ({
|
||||
title: i.fs_name_no_ext,
|
||||
value: i.id,
|
||||
}))
|
||||
|
||||
@@ -374,10 +374,10 @@ onBeforeUnmount(() => {
|
||||
<v-icon>mdi-check-decagram-outline</v-icon>
|
||||
</v-chip>
|
||||
<v-chip
|
||||
v-if="rom.siblings.length > 0 && showSiblings"
|
||||
v-if="rom.sibling_roms.length > 0 && showSiblings"
|
||||
class="translucent mr-1 mb-1 px-1"
|
||||
density="compact"
|
||||
:title="`${rom.siblings.length} sibling(s)`"
|
||||
:title="`${rom.sibling_roms.length} sibling(s)`"
|
||||
>
|
||||
<v-icon>mdi-card-multiple-outline</v-icon>
|
||||
</v-chip>
|
||||
|
||||
@@ -310,10 +310,10 @@ function updateOptions({ sortBy }: { sortBy: SortBy }) {
|
||||
</v-avatar>
|
||||
</v-chip>
|
||||
<v-chip
|
||||
v-if="item.siblings.length > 0 && showSiblings"
|
||||
v-if="item.sibling_roms.length > 0 && showSiblings"
|
||||
class="translucent mr-1 px-1 item-chip"
|
||||
size="x-small"
|
||||
:title="`${item.siblings.length} sibling(s)`"
|
||||
:title="`${item.sibling_roms.length} sibling(s)`"
|
||||
>
|
||||
<v-icon>mdi-card-multiple-outline</v-icon>
|
||||
</v-chip>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type {
|
||||
AddFirmwareResponse,
|
||||
Body_add_firmware_api_firmware_post as AddFirmwareInput,
|
||||
BulkOperationResponse,
|
||||
FirmwareSchema,
|
||||
} from "@/__generated__";
|
||||
@@ -28,8 +27,7 @@ async function uploadFirmware({
|
||||
files: File[];
|
||||
}) {
|
||||
const formData = new FormData();
|
||||
const typedFiles: AddFirmwareInput["files"] = files;
|
||||
typedFiles.forEach((file) => formData.append("files", file));
|
||||
files.forEach((file) => formData.append("files", file));
|
||||
|
||||
const { data } = await firmwareApi.post<AddFirmwareResponse>(
|
||||
`/firmware`,
|
||||
|
||||
@@ -9,12 +9,15 @@ import { buildFormInput } from "@/utils/formData";
|
||||
|
||||
export const saveApi = api;
|
||||
|
||||
type SaveUploadInput = AddSaveInput & {
|
||||
type SaveUploadInput = Omit<AddSaveInput, "saveFile" | "screenshotFile"> & {
|
||||
saveFile: File;
|
||||
screenshotFile?: File;
|
||||
};
|
||||
|
||||
type UpdateSaveUploadInput = UpdateSaveInput & {
|
||||
type UpdateSaveUploadInput = Omit<
|
||||
UpdateSaveInput,
|
||||
"saveFile" | "screenshotFile"
|
||||
> & {
|
||||
saveFile: File;
|
||||
screenshotFile?: File;
|
||||
};
|
||||
|
||||
@@ -9,12 +9,15 @@ import { buildFormInput } from "@/utils/formData";
|
||||
|
||||
export const stateApi = api;
|
||||
|
||||
type StateUploadInput = AddStateInput & {
|
||||
type StateUploadInput = Omit<AddStateInput, "stateFile" | "screenshotFile"> & {
|
||||
stateFile: File;
|
||||
screenshotFile?: File;
|
||||
};
|
||||
|
||||
type UpdateStateUploadInput = UpdateStateInput & {
|
||||
type UpdateStateUploadInput = Omit<
|
||||
UpdateStateInput,
|
||||
"stateFile" | "screenshotFile"
|
||||
> & {
|
||||
stateFile: File;
|
||||
screenshotFile?: File;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export type FormInputField<
|
||||
T extends Record<string, unknown>,
|
||||
K extends keyof T = keyof T,
|
||||
> = readonly [key: K, value: T[K], filename?: string];
|
||||
> = readonly [key: K, value: T[K] | Blob, filename?: string];
|
||||
|
||||
export function buildFormInput<T extends Record<string, unknown>>(
|
||||
fields: ReadonlyArray<FormInputField<T>>,
|
||||
|
||||
Reference in New Issue
Block a user