mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
added all supported platforms to upload rom dialog
This commit is contained in:
@@ -3,7 +3,8 @@ from endpoints.responses import MessageResponse
|
||||
from endpoints.responses.platform import PlatformSchema
|
||||
from exceptions.fs_exceptions import PlatformAlreadyExistsException
|
||||
from fastapi import APIRouter, HTTPException, Request, status
|
||||
from handler import db_platform_handler, igdb_handler, fs_platform_handler
|
||||
from handler import db_platform_handler, fs_platform_handler
|
||||
from handler.metadata_handler.igdb_handler import IGDB_PLATFORM_LIST
|
||||
from logger.logger import log
|
||||
|
||||
router = APIRouter()
|
||||
@@ -47,6 +48,33 @@ def get_platforms(request: Request) -> list[PlatformSchema]:
|
||||
return db_platform_handler.get_platforms()
|
||||
|
||||
|
||||
@protected_route(router.get, "/platforms/supported", ["platforms.read"])
|
||||
def get_supported_platforms(request: Request) -> list[PlatformSchema]:
|
||||
"""Get list of supported platforms endpoint
|
||||
|
||||
Args:
|
||||
request (Request): Fastapi Request object
|
||||
|
||||
Returns:
|
||||
list[PlatformSchema]: List of supported platforms
|
||||
"""
|
||||
|
||||
supported_platforms = []
|
||||
db_platforms: list = db_platform_handler.get_platforms()
|
||||
# This double loop probably can be done better
|
||||
for platform in IGDB_PLATFORM_LIST:
|
||||
platform["id"] = -1
|
||||
for p in db_platforms:
|
||||
if p.name == platform["name"]:
|
||||
platform["id"] = p.id
|
||||
platform["fs_slug"] = platform["slug"]
|
||||
platform["logo_path"] = ""
|
||||
platform["roms"] = []
|
||||
platform["rom_count"] = 0
|
||||
supported_platforms.append(PlatformSchema.model_validate(platform).model_dump())
|
||||
return supported_platforms
|
||||
|
||||
|
||||
@protected_route(router.get, "/platforms/{id}", ["platforms.read"])
|
||||
def get_platform(request: Request, id: int) -> PlatformSchema:
|
||||
"""Get platforms endpoint
|
||||
|
||||
@@ -10,8 +10,8 @@ class PlatformSchema(BaseModel):
|
||||
igdb_id: Optional[int] = None
|
||||
sgdb_id: Optional[int] = None
|
||||
moby_id: Optional[int] = None
|
||||
name: Optional[str]
|
||||
logo_path: str
|
||||
name: str
|
||||
logo_path: Optional[str] = ""
|
||||
rom_count: int
|
||||
|
||||
class Config:
|
||||
|
||||
@@ -10,7 +10,7 @@ export type PlatformSchema = {
|
||||
igdb_id?: (number | null);
|
||||
sgdb_id?: (number | null);
|
||||
moby_id?: (number | null);
|
||||
name: (string | null);
|
||||
name: string;
|
||||
logo_path: string;
|
||||
rom_count: number;
|
||||
};
|
||||
|
||||
@@ -2,38 +2,39 @@
|
||||
import PlatformIcon from "@/components/Platform/PlatformIcon.vue";
|
||||
import romApi from "@/services/api/rom";
|
||||
import socket from "@/services/socket";
|
||||
import storePlatforms, { type Platform } from "@/stores/platforms";
|
||||
import { type Platform } from "@/stores/platforms";
|
||||
import storeScanning from "@/stores/scanning";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import { formatBytes } from "@/utils";
|
||||
import type { Emitter } from "mitt";
|
||||
import { inject, ref } from "vue";
|
||||
import { inject, ref, onMounted } from "vue";
|
||||
import { useDisplay } from "vuetify";
|
||||
import platformApi from "@/services/api/platform";
|
||||
|
||||
// Props
|
||||
const { xs, mdAndDown, lgAndUp } = useDisplay();
|
||||
const show = ref(false);
|
||||
const romsToUpload = ref<File[]>([]);
|
||||
const scanningStore = storeScanning();
|
||||
const platform = ref<Platform | null>(null);
|
||||
const platforms = storePlatforms();
|
||||
const selectedPlatform = ref<Platform | null>(null);
|
||||
const supportedPlatforms = ref<Platform[]>();
|
||||
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
emitter?.on("showUploadRomDialog", (platformWhereUpload) => {
|
||||
if (platformWhereUpload) {
|
||||
platform.value = platformWhereUpload;
|
||||
selectedPlatform.value = platformWhereUpload;
|
||||
}
|
||||
show.value = true;
|
||||
});
|
||||
|
||||
// Functions
|
||||
async function uploadRoms() {
|
||||
if (!platform.value) return;
|
||||
if (!selectedPlatform.value) return;
|
||||
show.value = false;
|
||||
scanningStore.set(true);
|
||||
const platformId = platform.value.id;
|
||||
const platformId = selectedPlatform.value.id;
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: `Uploading ${romsToUpload.value.length} roms to ${platform.value.name}...`,
|
||||
msg: `Uploading ${romsToUpload.value.length} roms to ${selectedPlatform.value.name}...`,
|
||||
icon: "mdi-loading mdi-spin",
|
||||
color: "romm-accent-1",
|
||||
});
|
||||
@@ -81,7 +82,7 @@ async function uploadRoms() {
|
||||
});
|
||||
});
|
||||
romsToUpload.value = [];
|
||||
platform.value = null;
|
||||
selectedPlatform.value = null;
|
||||
}
|
||||
|
||||
function triggerFileInput() {
|
||||
@@ -96,8 +97,28 @@ function removeRomFromList(romName: string) {
|
||||
function closeDialog() {
|
||||
show.value = false;
|
||||
romsToUpload.value = [];
|
||||
platform.value = null;
|
||||
selectedPlatform.value = null;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
platformApi
|
||||
.getSupportedPlatforms()
|
||||
.then(({ data }) => {
|
||||
supportedPlatforms.value = data.sort((a, b) => {
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
})
|
||||
.catch(({ response, message }) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: `Unable to upload roms: ${
|
||||
response?.data?.detail || response?.statusText || message
|
||||
}`,
|
||||
icon: "mdi-close-circle",
|
||||
color: "red",
|
||||
timeout: 4000,
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -142,11 +163,11 @@ function closeDialog() {
|
||||
<v-toolbar density="compact" class="bg-primary">
|
||||
<v-row class="align-center" no-gutters>
|
||||
<v-col cols="10" sm="8" lg="9">
|
||||
<v-select
|
||||
<v-autocomplete
|
||||
label="Platform"
|
||||
item-title="name"
|
||||
v-model="platform"
|
||||
:items="platforms.value"
|
||||
v-model="selectedPlatform"
|
||||
:items="supportedPlatforms"
|
||||
prepend-inner-icon="mdi-controller"
|
||||
prepend-icon=""
|
||||
return-object
|
||||
@@ -169,7 +190,7 @@ function closeDialog() {
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
</v-select>
|
||||
</v-autocomplete>
|
||||
</v-col>
|
||||
<v-col>
|
||||
<v-btn
|
||||
@@ -229,7 +250,7 @@ function closeDialog() {
|
||||
<v-btn
|
||||
@click="uploadRoms()"
|
||||
class="text-romm-green ml-5 bg-terciary"
|
||||
:disabled="romsToUpload.length == 0 || platform == null"
|
||||
:disabled="romsToUpload.length == 0 || selectedPlatform == null"
|
||||
>
|
||||
Upload
|
||||
</v-btn>
|
||||
|
||||
@@ -21,6 +21,10 @@ async function getPlatform(
|
||||
return api.get(`/platforms/${id}`);
|
||||
}
|
||||
|
||||
async function getSupportedPlatforms(): Promise<{ data: PlatformSchema[] }> {
|
||||
return api.get("/platforms/supported");
|
||||
}
|
||||
|
||||
async function updatePlatform({
|
||||
platform,
|
||||
}: {
|
||||
@@ -41,5 +45,6 @@ export default {
|
||||
uploadPlatform,
|
||||
getPlatforms,
|
||||
getPlatform,
|
||||
getSupportedPlatforms,
|
||||
deletePlatform,
|
||||
};
|
||||
|
||||
@@ -93,7 +93,7 @@ watch(metadataOptions, (newOptions) => {
|
||||
<!-- Platform selector -->
|
||||
<v-row class="px-4 pt-4 align-center" no-gutters>
|
||||
<v-col cols="12" xs="12" sm="12" md="6" xl="6" class="pr-1">
|
||||
<v-select
|
||||
<v-autocomplete
|
||||
label="Platforms"
|
||||
item-title="name"
|
||||
v-model="platformsToScan"
|
||||
@@ -116,7 +116,7 @@ watch(metadataOptions, (newOptions) => {
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
</v-select>
|
||||
</v-autocomplete>
|
||||
</v-col>
|
||||
<v-col
|
||||
cols="12"
|
||||
|
||||
Reference in New Issue
Block a user