Merge pull request #883 from rommapp/rom-fetch-perf

Improved performance of Rom DB fetch
This commit is contained in:
Georges-Antoine Assi
2024-05-25 21:42:45 -04:00
committed by GitHub
92 changed files with 255 additions and 172 deletions

View File

@@ -31,7 +31,6 @@ class ScreenshotSchema(BaseAsset):
class UploadedScreenshotsResponse(TypedDict):
uploaded: int
screenshots: list[ScreenshotSchema]
url_screenshots: list[str]
merged_screenshots: list[str]

View File

@@ -93,16 +93,8 @@ class RomSchema(BaseModel):
multi: bool
files: list[str]
url_screenshots: list[str]
merged_screenshots: list[str]
full_path: str
sibling_roms: list["RomSchema"] = Field(default_factory=list)
user_saves: list[SaveSchema] = Field(default_factory=list)
user_states: list[StateSchema] = Field(default_factory=list)
user_screenshots: list[ScreenshotSchema] = Field(default_factory=list)
user_notes: list[RomNoteSchema] = Field(default_factory=list)
class Config:
from_attributes = True
@@ -119,8 +111,17 @@ class RomSchema(BaseModel):
.lower()
)
class DetailedRomSchema(RomSchema):
merged_screenshots: list[str]
sibling_roms: list["RomSchema"] = Field(default_factory=list)
user_saves: list[SaveSchema] = Field(default_factory=list)
user_states: list[StateSchema] = Field(default_factory=list)
user_screenshots: list[ScreenshotSchema] = Field(default_factory=list)
user_notes: list[RomNoteSchema] = Field(default_factory=list)
@classmethod
def from_orm_with_request(cls, db_rom: Rom, request: Request) -> "RomSchema":
def from_orm_with_request(cls, db_rom: Rom, request: Request) -> "DetailedRomSchema":
rom = cls.model_validate(db_rom)
user_id = request.user.id

View File

@@ -9,4 +9,3 @@ class SearchRomSchema(BaseModel):
summary: str
igdb_url_cover: str = ""
moby_url_cover: str = ""
url_screenshots: list[str]

View File

@@ -10,6 +10,7 @@ from endpoints.responses.rom import (
AddRomsResponse,
CustomStreamingResponse,
RomSchema,
DetailedRomSchema,
RomNoteSchema,
)
from exceptions.fs_exceptions import RomAlreadyExistsException
@@ -119,7 +120,7 @@ def get_roms(
"/roms/{id}",
[] if DISABLE_DOWNLOAD_ENDPOINT_AUTH else ["roms.read"],
)
def get_rom(request: Request, id: int) -> RomSchema:
def get_rom(request: Request, id: int) -> DetailedRomSchema:
"""Get rom endpoint
Args:
@@ -127,9 +128,9 @@ def get_rom(request: Request, id: int) -> RomSchema:
id (int): Rom internal id
Returns:
RomSchema: Rom stored in the database
DetailedRomSchema: Rom stored in the database
"""
return RomSchema.from_orm_with_request(db_rom_handler.get_roms(id), request)
return DetailedRomSchema.from_orm_with_request(db_rom_handler.get_roms(id), request)
@protected_route(
@@ -248,7 +249,7 @@ async def update_rom(
rename_as_igdb: bool = False,
remove_cover: bool = False,
artwork: Optional[UploadFile] = File(None),
) -> RomSchema:
) -> DetailedRomSchema:
"""Update rom endpoint
Args:
@@ -261,7 +262,7 @@ async def update_rom(
HTTPException: If a rom already have that name when enabling the rename_as_igdb flag
Returns:
RomSchema: Rom stored in the database
DetailedRomSchema: Rom stored in the database
"""
data = await request.form()
@@ -375,7 +376,7 @@ async def update_rom(
db_rom_handler.update_rom(id, cleaned_data)
return db_rom_handler.get_roms(id)
return DetailedRomSchema.from_orm_with_request(db_rom_handler.get_roms(id), request)
@protected_route(router.post, "/roms/delete", ["roms.write"])

View File

@@ -55,6 +55,5 @@ def add_screenshots(
return {
"uploaded": len(screenshots),
"screenshots": [s for s in rom.screenshots if s.user_id == current_user.id],
"url_screenshots": rom.url_screenshots,
"merged_screenshots": rom.merged_screenshots,
}

View File

@@ -97,7 +97,6 @@ async def search_rom(
"summary": "",
"igdb_url_cover": "",
"moby_url_cover": "",
"url_screenshots": [],
},
**item,
}

View File

@@ -1,4 +1,3 @@
import json
from fastapi.testclient import TestClient
from unittest.mock import patch
@@ -45,12 +44,6 @@ def test_update_rom(rename_file_mock, get_rom_by_id_mock, access_token, rom):
"file_name": "Metroid Prime Remastered.zip",
"summary": "summary test",
"url_cover": "https://images.igdb.com/igdb/image/upload/t_cover_big/co2l7z.jpg",
"url_screenshots": json.dumps(
[
"https://images.igdb.com/igdb/image/upload/t_original/qhiqlmwvvuaqxxn4cxlr.jpg",
"https://images.igdb.com/igdb/image/upload/t_original/kqkixazzsokqgoxmuish.jpg",
]
),
"genres": '[{"id": 5, "name": "Shooter"}, {"id": 8, "name": "Platform"}, {"id": 31, "name": "Adventure"}]',
"franchises": '[{"id": 756, "name": "Metroid"}]',
"collections": '[{"id": 243, "name": "Metroid"}, {"id": 6240, "name": "Metroid Prime"}]',

View File

@@ -17,6 +17,9 @@ from sqlalchemy import (
DateTime,
func,
UniqueConstraint,
select,
and_,
or_,
)
from sqlalchemy.orm import Mapped, relationship
@@ -108,14 +111,17 @@ class Rom(BaseModel):
def get_sibling_roms(self) -> list["Rom"]:
from handler.database import db_rom_handler
if not self.igdb_id:
return []
with db_rom_handler.session.begin() as session:
return session.scalars(
db_rom_handler.get_roms(platform_id=self.platform_id).filter(
Rom.id != self.id,
Rom.igdb_id == self.igdb_id,
select(Rom).where(
and_(
Rom.platform_id == self.platform_id,
Rom.id != self.id,
or_(
and_(Rom.igdb_id == self.igdb_id, Rom.igdb_id != None), # noqa
and_(Rom.moby_id == self.moby_id, Rom.moby_id != None), # noqa
),
)
)
).all()

View File

@@ -7,7 +7,7 @@ import socket from "@/services/socket";
import storeConfig from "@/stores/config";
import storeGalleryFilter from "@/stores/galleryFilter";
import storeHeartbeat from "@/stores/heartbeat";
import storeRoms, { type Rom } from "@/stores/roms";
import storeRoms, { type SimpleRom } from "@/stores/roms";
import storePlatforms from "@/stores/platforms";
import storeAuth from "@/stores/auth";
import storeScanning from "@/stores/scanning";
@@ -42,7 +42,7 @@ socket.on(
}
);
socket.on("scan:scanning_rom", (rom: Rom) => {
socket.on("scan:scanning_rom", (rom: SimpleRom) => {
scanningStore.set(true);
if (romsStore.platformID === rom.platform_id) {
romsStore.add([rom]);

View File

@@ -15,6 +15,7 @@ export type { Body_update_rom_roms__id__put } from './models/Body_update_rom_rom
export type { Body_update_user_users__id__put } from './models/Body_update_user_users__id__put';
export type { ConfigResponse } from './models/ConfigResponse';
export type { CursorPage_RomSchema_ } from './models/CursorPage_RomSchema_';
export type { DetailedRomSchema } from './models/DetailedRomSchema';
export type { FirmwareSchema } from './models/FirmwareSchema';
export type { HeartbeatResponse } from './models/HeartbeatResponse';
export type { HTTPValidationError } from './models/HTTPValidationError';

View File

@@ -9,3 +9,4 @@ export type AddFirmwareResponse = {
uploaded: number;
firmware: Array<FirmwareSchema>;
};

View File

@@ -7,3 +7,4 @@ export type AddRomsResponse = {
uploaded_roms: Array<string>;
skipped_roms: Array<string>;
};

View File

@@ -6,3 +6,4 @@
export type Body_add_firmware_firmware_post = {
files: Array<Blob>;
};

View File

@@ -6,3 +6,4 @@
export type Body_add_roms_roms_post = {
roms: Array<Blob>;
};

View File

@@ -6,3 +6,4 @@
export type Body_add_saves_saves_post = {
saves: Array<Blob>;
};

View File

@@ -6,3 +6,4 @@
export type Body_add_screenshots_screenshots_post = {
screenshots: Array<Blob>;
};

View File

@@ -6,3 +6,4 @@
export type Body_add_states_states_post = {
states: Array<Blob>;
};

View File

@@ -12,3 +12,4 @@ export type Body_token_token_post = {
client_secret?: (string | null);
refresh_token?: (string | null);
};

View File

@@ -6,3 +6,4 @@
export type Body_update_rom_roms__id__put = {
artwork?: (Blob | null);
};

View File

@@ -6,3 +6,4 @@
export type Body_update_user_users__id__put = {
avatar?: (Blob | null);
};

View File

@@ -16,3 +16,4 @@ export type ConfigResponse = {
FIRMWARE_FOLDER_NAME: string;
HIGH_PRIO_STRUCTURE_PATH: string;
};

View File

@@ -28,3 +28,4 @@ export type CursorPage_RomSchema_ = {
*/
next_page?: (string | null);
};

View File

@@ -0,0 +1,59 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { RomIGDBMetadata } from './RomIGDBMetadata';
import type { RomMobyMetadata } from './RomMobyMetadata';
import type { RomNoteSchema } from './RomNoteSchema';
import type { RomSchema } from './RomSchema';
import type { SaveSchema } from './SaveSchema';
import type { ScreenshotSchema } from './ScreenshotSchema';
import type { StateSchema } from './StateSchema';
export type DetailedRomSchema = {
id: number;
igdb_id: (number | null);
sgdb_id: (number | null);
moby_id: (number | null);
platform_id: number;
platform_slug: string;
platform_name: string;
file_name: string;
file_name_no_tags: string;
file_name_no_ext: string;
file_extension: string;
file_path: string;
file_size_bytes: number;
name: (string | null);
slug: (string | null);
summary: (string | null);
first_release_date: (number | null);
alternative_names: Array<string>;
genres: Array<string>;
franchises: Array<string>;
collections: Array<string>;
companies: Array<string>;
game_modes: Array<string>;
igdb_metadata: (RomIGDBMetadata | null);
moby_metadata: (RomMobyMetadata | null);
path_cover_s: (string | null);
path_cover_l: (string | null);
has_cover: boolean;
url_cover: (string | null);
revision: (string | null);
regions: Array<string>;
languages: Array<string>;
tags: Array<string>;
multi: boolean;
files: Array<string>;
full_path: string;
merged_screenshots: Array<string>;
sibling_roms?: Array<RomSchema>;
user_saves?: Array<SaveSchema>;
user_states?: Array<StateSchema>;
user_screenshots?: Array<ScreenshotSchema>;
user_notes?: Array<RomNoteSchema>;
readonly sort_comparator: string;
};

View File

@@ -17,3 +17,4 @@ export type FirmwareSchema = {
md5_hash: string;
sha1_hash: string;
};

View File

@@ -8,3 +8,4 @@ import type { ValidationError } from './ValidationError';
export type HTTPValidationError = {
detail?: Array<ValidationError>;
};

View File

@@ -14,3 +14,4 @@ export type HeartbeatResponse = {
ANY_SOURCE_ENABLED: boolean;
METADATA_SOURCES: MetadataSourcesDict;
};

View File

@@ -7,3 +7,4 @@ export type IGDBPlatform = {
igdb_id: number;
name?: string;
};

View File

@@ -10,3 +10,4 @@ export type IGDBRelatedGame = {
type: string;
cover_url: string;
};

View File

@@ -6,3 +6,4 @@
export type MessageResponse = {
msg: string;
};

View File

@@ -7,3 +7,4 @@ export type MetadataSourcesDict = {
IGDB_API_ENABLED: boolean;
MOBY_API_ENABLED: boolean;
};

View File

@@ -7,3 +7,4 @@ export type MobyGamesPlatform = {
moby_id: number;
name?: string;
};

View File

@@ -9,11 +9,12 @@ export type PlatformSchema = {
id: number;
slug: string;
fs_slug: string;
name: string;
rom_count: number;
igdb_id?: (number | null);
sgdb_id?: (number | null);
moby_id?: (number | null);
name: string;
logo_path?: (string | null);
rom_count: number;
firmware?: Array<FirmwareSchema>;
};

View File

@@ -25,3 +25,4 @@ export type RomIGDBMetadata = {
ports?: Array<IGDBRelatedGame>;
similar_games?: Array<IGDBRelatedGame>;
};

View File

@@ -11,3 +11,4 @@ export type RomMobyMetadata = {
alternate_titles?: Array<string>;
platforms?: Array<MobyGamesPlatform>;
};

View File

@@ -10,5 +10,6 @@ export type RomNoteSchema = {
last_edited_at: string;
raw_markdown: string;
is_public: boolean;
readonly user__username: string;
user__username: string;
};

View File

@@ -5,10 +5,6 @@
import type { RomIGDBMetadata } from './RomIGDBMetadata';
import type { RomMobyMetadata } from './RomMobyMetadata';
import type { RomNoteSchema } from './RomNoteSchema';
import type { SaveSchema } from './SaveSchema';
import type { ScreenshotSchema } from './ScreenshotSchema';
import type { StateSchema } from './StateSchema';
export type RomSchema = {
id: number;
@@ -46,13 +42,7 @@ export type RomSchema = {
tags: Array<string>;
multi: boolean;
files: Array<string>;
url_screenshots: Array<string>;
merged_screenshots: Array<string>;
full_path: string;
sibling_roms?: Array<RomSchema>;
user_saves?: Array<SaveSchema>;
user_states?: Array<StateSchema>;
user_screenshots?: Array<ScreenshotSchema>;
user_notes?: Array<RomNoteSchema>;
readonly sort_comparator: string;
};

View File

@@ -22,3 +22,4 @@ export type SaveSchema = {
emulator: (string | null);
screenshot: (ScreenshotSchema | null);
};

View File

@@ -9,3 +9,4 @@ export type SchedulerDict = {
RESCAN: TaskDict;
SWITCH_TITLEDB: TaskDict;
};

View File

@@ -18,3 +18,4 @@ export type ScreenshotSchema = {
created_at: string;
updated_at: string;
};

View File

@@ -11,5 +11,5 @@ export type SearchRomSchema = {
summary: string;
igdb_url_cover?: string;
moby_url_cover?: string;
url_screenshots: Array<string>;
};

View File

@@ -22,3 +22,4 @@ export type StateSchema = {
emulator: (string | null);
screenshot: (ScreenshotSchema | null);
};

View File

@@ -11,3 +11,4 @@ export type StatsReturn = {
SCREENSHOTS: number;
FILESIZE: number;
};

View File

@@ -9,3 +9,4 @@ export type TaskDict = {
MESSAGE: string;
CRON: string;
};

View File

@@ -8,3 +8,4 @@ export type TinfoilFeedSchema = {
directories: Array<string>;
success: string;
};

View File

@@ -9,3 +9,4 @@ export type TokenResponse = {
token_type: string;
expires: number;
};

View File

@@ -9,3 +9,4 @@ export type UploadedSavesResponse = {
uploaded: number;
saves: Array<SaveSchema>;
};

View File

@@ -8,6 +8,6 @@ import type { ScreenshotSchema } from './ScreenshotSchema';
export type UploadedScreenshotsResponse = {
uploaded: number;
screenshots: Array<ScreenshotSchema>;
url_screenshots: Array<string>;
merged_screenshots: Array<string>;
};

View File

@@ -9,3 +9,4 @@ export type UploadedStatesResponse = {
uploaded: number;
states: Array<StateSchema>;
};

View File

@@ -15,3 +15,4 @@ export type UserSchema = {
last_login: (string | null);
last_active: (string | null);
};

View File

@@ -8,3 +8,4 @@ export type ValidationError = {
msg: string;
type: string;
};

View File

@@ -8,3 +8,4 @@ export type WatcherDict = {
TITLE: string;
MESSAGE: string;
};

View File

@@ -11,3 +11,4 @@ export type WebrcadeFeedSchema = {
background: string;
categories: Array<Record<string, any>>;
};

View File

@@ -3,13 +3,13 @@ import AdminMenu from "@/components/Game/AdminMenu/Base.vue";
import romApi from "@/services/api/rom";
import storeAuth from "@/stores/auth";
import storeDownload from "@/stores/download";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
import type { Events } from "@/types/emitter";
import { getDownloadLink, platformSlugEJSCoreMap } from "@/utils";
import type { Emitter } from "mitt";
import { inject, ref } from "vue";
const props = defineProps<{ rom: Rom }>();
const props = defineProps<{ rom: DetailedRom }>();
const downloadStore = storeDownload();
const emitter = inject<Emitter<Events>>("emitter");
const auth = storeAuth();
@@ -24,7 +24,7 @@ function toggleEmulation() {
emitter?.emit("showEmulation", null);
}
async function copyDownloadLink(rom: Rom) {
async function copyDownloadLink(rom: DetailedRom) {
const downloadLink =
location.protocol +
"//" +

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
const props = defineProps<{ rom: Rom }>();
const props = defineProps<{ rom: DetailedRom }>();
import { useTheme } from "vuetify";
const theme = useTheme();
</script>

View File

@@ -1,9 +1,9 @@
<script setup lang="ts">
import type { RomSchema } from "@/__generated__";
import type { DetailedRom } from "@/stores/roms";
import { useTheme } from "vuetify";
const theme = useTheme();
const props = defineProps<{ rom: RomSchema }>();
const props = defineProps<{ rom: DetailedRom }>();
const imgSrc =
!props.rom.igdb_id && !props.rom.moby_id && !props.rom.has_cover
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
defineProps<{ rom: Rom }>();
defineProps<{ rom: DetailedRom }>();
</script>
<template>
<v-row no-gutters>

View File

@@ -2,13 +2,13 @@
import { isNull } from "lodash";
import type { FirmwareSchema, SaveSchema, StateSchema } from "@/__generated__";
import rom from "@/services/api/rom";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
import { formatBytes } from "@/utils";
import Player from "@/views/Play/Player.vue";
import { ref } from "vue";
import type { Platform } from "@/stores/platforms";
const props = defineProps<{ rom: Rom; platform: Platform }>();
const props = defineProps<{ rom: DetailedRom; platform: Platform }>();
const biosRef = ref<FirmwareSchema | null>(null);
const saveRef = ref<SaveSchema | null>(null);
const stateRef = ref<StateSchema | null>(null);

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
defineProps<{ rom: Rom }>();
defineProps<{ rom: DetailedRom }>();
</script>
<template>
<v-col class="pa-0" cols="4" sm="2" md="3" lg="3" v-for="game in rom.igdb_metadata?.expanded_games">

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
defineProps<{ rom: Rom }>();
defineProps<{ rom: DetailedRom }>();
</script>
<template>
<v-row no-gutters>

View File

@@ -1,10 +1,10 @@
<script setup lang="ts">
import type { PlatformSchema } from "@/__generated__";
import type { Platform } from "@/stores/platforms";
import FileInfo from "@/components/Details/Info/FileInfo.vue";
import GameInfo from "@/components/Details/Info/GameInfo.vue";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
defineProps<{ rom: Rom; platform: PlatformSchema }>();
defineProps<{ rom: DetailedRom; platform: Platform }>();
</script>
<template>
<file-info :rom="rom" :platform="platform" />

View File

@@ -1,11 +1,11 @@
<script setup lang="ts">
import type { PlatformSchema } from "@/__generated__";
import type { Platform } from "@/stores/platforms";
import VersionSwitcher from "@/components/Details/VersionSwitcher.vue";
import storeDownload from "@/stores/download";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
import { formatBytes } from "@/utils";
defineProps<{ rom: Rom; platform: PlatformSchema }>();
defineProps<{ rom: DetailedRom; platform: Platform }>();
const downloadStore = storeDownload();
</script>
<template>

View File

@@ -1,9 +1,9 @@
<script setup lang="ts">
import storeGalleryFilter from "@/stores/galleryFilter";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
import { useDisplay } from "vuetify";
defineProps<{ rom: Rom }>();
defineProps<{ rom: DetailedRom }>();
const { xs } = useDisplay();
const galleryFilter = storeGalleryFilter();
</script>

View File

@@ -2,13 +2,13 @@
import { ref } from "vue";
import { useTheme } from "vuetify";
import { type Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
import storeAuth from "@/stores/auth";
import romApi from "@/services/api/rom";
import { MdEditor, MdPreview } from "md-editor-v3";
import "md-editor-v3/lib/style.css";
const props = defineProps<{ rom: Rom }>();
const props = defineProps<{ rom: DetailedRom }>();
const auth = storeAuth();
const theme = useTheme();

View File

@@ -1,8 +1,8 @@
<script setup lang="ts">
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
import { ref } from "vue";
const props = defineProps<{ rom: Rom }>();
const props = defineProps<{ rom: DetailedRom }>();
const combined = ref([
...(props.rom.igdb_metadata?.remakes ?? []),
...(props.rom.igdb_metadata?.remasters ?? []),

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
defineProps<{ rom: Rom }>();
defineProps<{ rom: DetailedRom }>();
</script>
<template>
<v-row no-gutters>

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
defineProps<{ rom: Rom }>();
defineProps<{ rom: DetailedRom }>();
</script>
<template>
<v-row class="mb-3" no-gutters>

View File

@@ -1,13 +1,13 @@
<script setup lang="ts">
import type { SaveSchema } from "@/__generated__";
import saveApi from "@/services/api/save";
import storeRoms, { type Rom } from "@/stores/roms";
import storeRoms, { type DetailedRom } from "@/stores/roms";
import type { Events } from "@/types/emitter";
import { formatBytes } from "@/utils";
import type { Emitter } from "mitt";
import { inject, ref } from "vue";
const props = defineProps<{ rom: Rom }>();
const props = defineProps<{ rom: DetailedRom }>();
const savesToUpload = ref<File[]>([]);
const selectedSaves = ref<SaveSchema[]>([]);
const emitter = inject<Emitter<Events>>("emitter");

View File

@@ -1,8 +1,8 @@
<script setup lang="ts">
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
import { useDisplay } from "vuetify";
defineProps<{ rom: Rom }>();
defineProps<{ rom: DetailedRom }>();
const { xs } = useDisplay();
</script>
<template>

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
defineProps<{ rom: Rom }>();
defineProps<{ rom: DetailedRom }>();
</script>
<template>

View File

@@ -5,11 +5,11 @@ import type { Emitter } from "mitt";
import type { Events } from "@/types/emitter";
import { formatBytes } from "@/utils";
import stateApi from "@/services/api/state";
import storeRoms, { type Rom } from "@/stores/roms";
import storeRoms, { type DetailedRom } from "@/stores/roms";
import type { StateSchema } from "@/__generated__";
const props = defineProps<{ rom: Rom }>();
const props = defineProps<{ rom: DetailedRom }>();
const statesToUpload = ref<File[]>([]);
const selectedStates = ref<StateSchema[]>([]);
const emitter = inject<Emitter<Events>>("emitter");

View File

@@ -2,10 +2,11 @@
import { identity } from "lodash";
import PlatformIcon from "@/components/Platform/PlatformIcon.vue";
import { regionToEmoji, languageToEmoji } from "@/utils";
import type { RomSchema, PlatformSchema } from "@/__generated__/";
import type { DetailedRom } from "@/stores/roms";
import type { Platform } from "@/stores/platforms";
import { useDisplay } from "vuetify";
defineProps<{ rom: RomSchema; platform: PlatformSchema }>();
defineProps<{ rom: DetailedRom; platform: Platform }>();
const { smAndDown } = useDisplay();
</script>
<template>

View File

@@ -1,15 +1,15 @@
<script setup lang="ts">
import type { PlatformSchema } from "@/__generated__";
import type { Rom } from "@/stores/roms";
import type { Platform } from "@/stores/platforms";
import type { DetailedRom } from "@/stores/roms";
import { languageToEmoji, regionToEmoji } from "@/utils";
import { ref } from "vue";
import { useRouter } from "vue-router";
const props = defineProps<{ rom: Rom; platform: PlatformSchema }>();
const props = defineProps<{ rom: DetailedRom; platform: Platform }>();
const router = useRouter();
const version = ref(props.rom.id);
function formatItem(rom: Rom) {
function formatItem(rom: DetailedRom) {
const langs = rom.languages.map((l) => languageToEmoji(l)).join(" ");
const regions = rom.regions.map((r) => regionToEmoji(r)).join(" ");
const tags = rom.tags.map((t) => `(${t})`).join(" ");

View File

@@ -4,7 +4,7 @@ import { useDisplay } from "vuetify";
import type { Emitter } from "mitt";
import type { Events } from "@/types/emitter";
import storeRoms, { type Rom } from "@/stores/roms";
import storeRoms, { type DetailedRom } from "@/stores/roms";
import saveApi from "@/services/api/save";
import stateApi from "@/services/api/state";
import type { SaveSchema, StateSchema } from "@/__generated__";
@@ -13,7 +13,7 @@ const { xs, mdAndDown, lgAndUp } = useDisplay();
const romsStore = storeRoms();
const show = ref(false);
const assetType = ref<"user_saves" | "user_states">("user_saves");
const romRef = ref<Rom | null>(null);
const romRef = ref<DetailedRom | null>(null);
const assets = ref<(SaveSchema | StateSchema)[]>([]);
const deleteFromFs = ref(false);

View File

@@ -3,7 +3,7 @@ import type { SearchRomSchema } from "@/__generated__";
import SelectSourceDialog from "@/components/Dialog/Rom/MatchRom/SelectSource.vue";
import romApi from "@/services/api/rom";
import storeHeartbeat from "@/stores/heartbeat";
import storeRoms, { type Rom } from "@/stores/roms";
import storeRoms, { type SimpleRom } from "@/stores/roms";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
import { inject, onBeforeUnmount, ref } from "vue";
@@ -11,7 +11,7 @@ import { useDisplay, useTheme } from "vuetify";
const { xs, mdAndDown, lgAndUp } = useDisplay();
const show = ref(false);
const rom = ref<Rom | null>(null);
const rom = ref<SimpleRom | null>(null);
const romsStore = storeRoms();
const renameAsIGDB = ref(false);
const searching = ref(false);

View File

@@ -1,5 +1,4 @@
<script setup lang="ts">
import type { RomSchema } from "@/__generated__";
import PlatformIcon from "@/components/Platform/PlatformIcon.vue";
import romApi from "@/services/api/rom";
import storeGalleryView from "@/stores/galleryView";
@@ -10,6 +9,7 @@ import type { Emitter } from "mitt";
import { inject, onBeforeUnmount, ref } from "vue";
import { useRouter } from "vue-router";
import { useDisplay, useTheme } from "vuetify";
import { type SimpleRom } from "@/stores/roms";
const theme = useTheme();
const { xs, mdAndDown, lgAndUp } = useDisplay();
@@ -73,7 +73,7 @@ async function filterRoms() {
}
}
function romDetails(rom: RomSchema) {
function romDetails(rom: SimpleRom) {
router.push({
name: "rom",
params: { rom: rom.id },

View File

@@ -3,7 +3,6 @@ import socket from "@/services/socket";
import storeHeartbeat from "@/stores/heartbeat";
import storeRoms from "@/stores/roms";
import storeScanning from "@/stores/scanning";
import { computed, ref } from "vue";
// Props
const scanningStore = storeScanning();

View File

@@ -2,10 +2,10 @@
import { inject } from "vue";
import type { Emitter } from "mitt";
import type { Events } from "@/types/emitter";
import type { Rom } from "@/stores/roms";
import type { SimpleRom } from "@/stores/roms";
import storeHeartbeat from "@/stores/heartbeat";
defineProps<{ rom: Rom }>();
defineProps<{ rom: SimpleRom }>();
const emitter = inject<Emitter<Events>>("emitter");
const heartbeat = storeHeartbeat();
</script>

View File

@@ -3,11 +3,11 @@ import romApi from "@/services/api/rom";
import storeDownload from "@/stores/download";
import storeAuth from "@/stores/auth";
import AdminMenu from "@/components/Game/AdminMenu/Base.vue";
import type { Rom } from "@/stores/roms";
import type { SimpleRom } from "@/stores/roms";
import { platformSlugEJSCoreMap } from "@/utils";
// Props
defineProps<{ rom: Rom }>();
defineProps<{ rom: SimpleRom }>();
const auth = storeAuth();
const downloadStore = storeDownload();
</script>

View File

@@ -1,11 +1,11 @@
<script setup lang="ts">
import storeRoms, { type Rom } from "@/stores/roms.js";
import storeRoms, { type SimpleRom } from "@/stores/roms.js";
import ActionBar from "@/components/Game/Card/ActionBar.vue";
import Cover from "@/components/Game/Card/Cover.vue";
// Props
const props = defineProps<{
rom: Rom;
rom: SimpleRom;
index: number;
selected: boolean;
showSelector: boolean;

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import storeDownload from "@/stores/download";
import storeGalleryView from "@/stores/galleryView";
import storeRoms, { type Rom } from "@/stores/roms";
import storeRoms, { type SimpleRom } from "@/stores/roms";
import { languageToEmoji, regionToEmoji } from "@/utils";
import { identity, isNull } from "lodash";
import { ref } from "vue";
@@ -9,7 +9,7 @@ import { useTheme } from "vuetify";
// Props
defineProps<{
rom: Rom;
rom: SimpleRom;
isHoveringTop: boolean;
showSelector: boolean;
selected: boolean;

View File

@@ -1,5 +1,6 @@
import type { MessageResponse, PlatformSchema } from "@/__generated__";
import type { MessageResponse } from "@/__generated__";
import api from "@/services/api/index";
import type { Platform } from "@/stores/platforms";
export const platformApi = api;
@@ -7,28 +8,28 @@ async function uploadPlatform({
fsSlug,
}: {
fsSlug: string;
}): Promise<{ data: PlatformSchema }> {
}): Promise<{ data: Platform }> {
return api.post("/platforms", { fs_slug: fsSlug });
}
async function getPlatforms(): Promise<{ data: PlatformSchema[] }> {
async function getPlatforms(): Promise<{ data: Platform[] }> {
return api.get("/platforms");
}
async function getPlatform(
id: number | undefined
): Promise<{ data: PlatformSchema }> {
): Promise<{ data: Platform }> {
return api.get(`/platforms/${id}`);
}
async function getSupportedPlatforms(): Promise<{ data: PlatformSchema[] }> {
async function getSupportedPlatforms(): Promise<{ data: Platform[] }> {
return api.get("/platforms/supported");
}
async function updatePlatform({
platform,
}: {
platform: PlatformSchema;
platform: Platform;
}): Promise<{ data: MessageResponse }> {
return api.delete(`/platforms/${platform.id}`);
}
@@ -36,7 +37,7 @@ async function updatePlatform({
async function deletePlatform({
platform,
}: {
platform: PlatformSchema;
platform: Platform;
}): Promise<{ data: MessageResponse }> {
return api.delete(`/platforms/${platform.id}`);
}

View File

@@ -2,13 +2,12 @@ import type {
AddRomsResponse,
CursorPage_RomSchema_,
MessageResponse,
RomSchema,
SearchRomSchema,
} from "@/__generated__";
import api from "@/services/api/index";
import socket from "@/services/socket";
import storeDownload from "@/stores/download";
import type { Rom } from "@/stores/roms";
import type { SimpleRom, DetailedRom } from "@/stores/roms";
import { getDownloadLink } from "@/utils";
export const romApi = api;
@@ -64,7 +63,7 @@ async function getRecentRoms(): Promise<{ data: CursorPage_RomSchema_ }> {
});
}
async function getRom({ romId }: { romId: number }): Promise<{ data: Rom }> {
async function getRom({ romId }: { romId: number }): Promise<{ data: DetailedRom }> {
return api.get(`/roms/${romId}`);
}
@@ -105,7 +104,7 @@ async function downloadRom({
rom,
files = [],
}: {
rom: Rom;
rom: SimpleRom;
files?: string[];
}) {
const a = document.createElement("a");
@@ -124,7 +123,7 @@ async function downloadRom({
}
}
export type UpdateRom = Rom & {
export type UpdateRom = SimpleRom & {
artwork?: File;
};
@@ -136,7 +135,7 @@ async function updateRom({
rom: UpdateRom;
renameAsIGDB?: boolean;
removeCover?: boolean;
}): Promise<{ data: RomSchema }> {
}): Promise<{ data: DetailedRom }> {
var formData = new FormData();
if (rom.igdb_id) formData.append("igdb_id", rom.igdb_id.toString());
if (rom.moby_id) formData.append("moby_id", rom.moby_id.toString());
@@ -155,7 +154,7 @@ async function deleteRoms({
roms,
deleteFromFs = false,
}: {
roms: Rom[];
roms: SimpleRom[];
deleteFromFs: boolean;
}): Promise<{ data: MessageResponse }> {
return api.post("/roms/delete", {
@@ -172,7 +171,7 @@ async function updateRomNote({
romId: number;
rawMarkdown: string;
isPublic: boolean;
}): Promise<{ data: RomSchema }> {
}): Promise<{ data: DetailedRom }> {
return api.put(`/roms/${romId}/note`, {
raw_markdown: rawMarkdown,
is_public: isPublic,

View File

@@ -1,6 +1,6 @@
import type { SaveSchema, UploadedSavesResponse } from "@/__generated__";
import api from "@/services/api/index";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
export const saveApi = api;
@@ -9,7 +9,7 @@ async function uploadSaves({
saves,
emulator,
}: {
rom: Rom;
rom: DetailedRom;
saves: File[];
emulator?: string;
}): Promise<{ data: UploadedSavesResponse }> {

View File

@@ -1,6 +1,6 @@
import type { ScreenshotSchema, UploadedScreenshotsResponse } from "@/__generated__";
import api from "@/services/api/index";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
export const screenshotApi = api;
@@ -8,7 +8,7 @@ async function uploadScreenshots({
rom,
screenshots,
}: {
rom: Rom;
rom: DetailedRom;
screenshots: File[];
}): Promise<{ data: UploadedScreenshotsResponse }> {
let formData = new FormData();

View File

@@ -1,6 +1,6 @@
import type { StateSchema, UploadedStatesResponse } from "@/__generated__";
import api from "@/services/api/index";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
export const stateApi = api;
@@ -9,7 +9,7 @@ async function uploadStates({
states,
emulator,
}: {
rom: Rom;
rom: DetailedRom;
states: File[];
emulator?: string;
}): Promise<{ data: UploadedStatesResponse }> {

View File

@@ -1,25 +1,27 @@
import type { PlatformSchema, RomSchema } from "@/__generated__/";
import { groupBy, isNull, uniqBy } from "lodash";
import type { RomSchema, DetailedRomSchema } from "@/__generated__/";
import { groupBy, uniqBy } from "lodash";
import { nanoid } from "nanoid";
import { defineStore, type Store } from "pinia";
import { defineStore } from "pinia";
import storeGalleryFilter from "./galleryFilter";
import type { ExtractPiniaStoreType } from "@/types";
type GalleryFilterStore = ExtractPiniaStoreType<typeof storeGalleryFilter>;
export type Rom = RomSchema & {
export type SimpleRom = RomSchema & {
siblings?: RomSchema[]; // Added by the frontend
};
export type DetailedRom = DetailedRomSchema;
export default defineStore("roms", {
state: () => ({
_platformID: 0,
_all: [] as Rom[],
_grouped: [] as Rom[],
_all: [] as SimpleRom[],
_grouped: [] as SimpleRom[],
_filteredIDs: [] as number[],
_searchIDs: [] as number[],
_selectedIDs: [] as number[],
recentRoms: [] as Rom[],
recentRoms: [] as SimpleRom[],
lastSelectedIndex: -1,
cursor: "" as string | null,
searchCursor: "" as string | null,
@@ -62,7 +64,7 @@ export default defineStore("roms", {
)
)
.map((games) => ({
...(games.shift() as Rom),
...(games.shift() as SimpleRom),
siblings: games,
}))
.sort((a, b) => {
@@ -72,23 +74,23 @@ export default defineStore("roms", {
setPlatformID(platformID: number) {
this._platformID = platformID;
},
setRecentRoms(roms: Rom[]) {
setRecentRoms(roms: SimpleRom[]) {
this.recentRoms = roms;
},
// All roms
set(roms: Rom[]) {
set(roms: SimpleRom[]) {
this._all = roms;
this._reorder();
},
add(roms: Rom[]) {
add(roms: SimpleRom[]) {
this._all = this._all.concat(roms);
this._reorder();
},
update(rom: Rom) {
update(rom: SimpleRom) {
this._all = this._all.map((value) => (value.id === rom.id ? rom : value));
this._reorder();
},
remove(roms: Rom[]) {
remove(roms: SimpleRom[]) {
this._all = this._all.filter((value) => {
return !roms.find((rom) => {
return rom.id === value.id;
@@ -114,7 +116,7 @@ export default defineStore("roms", {
this.lastSelectedIndex = -1;
},
// Filter roms by gallery filter store state
setFiltered(roms: Rom[], galleryFilter: GalleryFilterStore) {
setFiltered(roms: SimpleRom[], galleryFilter: GalleryFilterStore) {
this._filteredIDs = roms.map((rom) => rom.id);
if (galleryFilter.filterUnmatched) this.filterUnmatched();
if (galleryFilter.selectedGenre) {
@@ -164,17 +166,17 @@ export default defineStore("roms", {
.map((rom) => rom.id);
},
// Search roms
setSearch(roms: Rom[]) {
setSearch(roms: SimpleRom[]) {
this._searchIDs = roms.map((rom) => rom.id);
},
// Selected roms
setSelection(roms: Rom[]) {
setSelection(roms: SimpleRom[]) {
this._selectedIDs = roms.map((rom) => rom.id);
},
addToSelection(rom: Rom) {
addToSelection(rom: SimpleRom) {
this._selectedIDs.push(rom.id);
},
removeFromSelection(rom: Rom) {
removeFromSelection(rom: SimpleRom) {
this._selectedIDs = this._selectedIDs.filter((id) => {
return id !== rom.id;
});

View File

@@ -1,5 +1,5 @@
import { defineStore } from "pinia";
import type { Rom } from "@/stores/roms";
import type { SimpleRom } from "@/stores/roms";
export default defineStore("scanning", {
state: () => ({
@@ -8,7 +8,7 @@ export default defineStore("scanning", {
name: string;
slug: string;
id: number;
roms: Rom[];
roms: SimpleRom[];
}[],
scanStats: {
scanned_platforms: 0,

View File

@@ -1,6 +1,6 @@
import type { SaveSchema, SearchRomSchema, StateSchema } from "@/__generated__";
import type { Platform } from "@/stores/platforms";
import type { Rom } from "@/stores/roms";
import type { SimpleRom } from "@/stores/roms";
import type { User } from "@/stores/users";
export type UserItem = User & {
@@ -17,12 +17,12 @@ export type SnackbarStatus = {
export type Events = {
showDeletePlatformDialog: Platform;
showMatchRomDialog: Rom;
showMatchRomDialog: SimpleRom;
showSelectSourceDialog: SearchRomSchema;
showSearchRomDialog: null;
showEditRomDialog: Rom;
showEditRomDialog: SimpleRom;
showCopyDownloadLinkDialog: string;
showDeleteRomDialog: Rom[];
showDeleteRomDialog: SimpleRom[];
showUploadRomDialog: Platform | null;
showFirmwareDialog: Platform;
showAddPlatformDialog: null;
@@ -47,11 +47,11 @@ export type Events = {
showEditUserDialog: User;
showDeleteUserDialog: User;
showDeleteSavesDialog: {
rom: Rom;
rom: DetailedRom;
saves: SaveSchema[];
};
showDeleteStatesDialog: {
rom: Rom;
rom: DetailedRom;
states: StateSchema[];
};
showEmulation: null;
@@ -69,5 +69,5 @@ export type Events = {
filterBarShow: null;
filterBarReset: null;
sortBarShow: null;
romUpdated: Rom;
romUpdated: DetailedRom;
};

View File

@@ -1,5 +1,5 @@
import cronstrue from "cronstrue";
import type { Rom } from "@/stores/roms";
import type { SimpleRom } from "@/stores/roms";
export const views: Record<
number,
@@ -75,7 +75,7 @@ export function getDownloadLink({
rom,
files = [],
}: {
rom: Rom;
rom: SimpleRom;
files?: string[];
}) {
// Force download of all multirom-parts when no part is selected

View File

@@ -1,5 +1,4 @@
<script setup lang="ts">
import type { PlatformSchema } from "@/__generated__";
import ActionBar from "@/components/Details/ActionBar.vue";
import AdditionalContent from "@/components/Details/AdditionalContent.vue";
import BackgroundHeader from "@/components/Details/BackgroundHeader.vue";
@@ -14,7 +13,8 @@ import TitleInfo from "@/components/Details/Title.vue";
import platformApi from "@/services/api/platform";
import romApi from "@/services/api/rom";
import storeDownload from "@/stores/download";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
import type { Platform } from "@/stores/platforms";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
import { inject, onBeforeMount, ref, watch } from "vue";
@@ -22,8 +22,8 @@ import { useRoute } from "vue-router";
import { useDisplay, useTheme } from "vuetify";
const route = useRoute();
const rom = ref<Rom>();
const platform = ref<PlatformSchema>();
const rom = ref<DetailedRom>();
const platform = ref<Platform>();
const tab = ref<
| "details"
| "saves"

View File

@@ -7,10 +7,10 @@ import romApi from "@/services/api/rom";
import firmwareApi from "@/services/api/firmware";
import { useRoute } from "vue-router";
import Player from "@/views/Play/Player.vue";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
const route = useRoute();
const rom = ref<Rom | null>(null);
const rom = ref<DetailedRom | null>(null);
const firmwareOptions = ref<FirmwareSchema[]>([]);
const biosRef = ref<FirmwareSchema | null>(null);

View File

@@ -5,11 +5,11 @@ import saveApi, { saveApi as api } from "@/services/api/save";
import screenshotApi from "@/services/api/screenshot";
import { platformSlugEJSCoreMap } from "@/utils";
import type { FirmwareSchema, SaveSchema, StateSchema } from "@/__generated__";
import type { Rom } from "@/stores/roms";
import type { DetailedRom } from "@/stores/roms";
import type { ValueOf } from "@/types";
const props = defineProps<{
rom: Rom;
rom: DetailedRom;
save: SaveSchema | null;
state: StateSchema | null;
bios: FirmwareSchema | null;
@@ -200,7 +200,6 @@ window.EJS_onSaveState = function ({
if (stateRef.value)
stateRef.value.screenshot = data.screenshots[0];
props.rom.user_screenshots = data.screenshots;
props.rom.url_screenshots = data.url_screenshots;
props.rom.merged_screenshots = data.merged_screenshots;
})
.catch((e) => console.log(e));
@@ -243,7 +242,6 @@ window.EJS_onSaveState = function ({
})
.then(({ data }) => {
props.rom.user_screenshots = data.screenshots;
props.rom.url_screenshots = data.url_screenshots;
props.rom.merged_screenshots = data.merged_screenshots;
})
.catch((e) => console.log(e));
@@ -330,7 +328,6 @@ window.EJS_onSaveSave = function ({
.then(({ data }) => {
if (saveRef.value) saveRef.value.screenshot = data.screenshots[0];
props.rom.user_screenshots = data.screenshots;
props.rom.url_screenshots = data.url_screenshots;
props.rom.merged_screenshots = data.merged_screenshots;
})
.catch((e) => console.log(e));
@@ -368,7 +365,6 @@ window.EJS_onSaveSave = function ({
})
.then(({ data }) => {
props.rom.user_screenshots = data.screenshots;
props.rom.url_screenshots = data.url_screenshots;
props.rom.merged_screenshots = data.merged_screenshots;
})
.catch((e) => console.log(e));