mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
feat: expose the parsed ROM version in the API and game overview (#5255)
* feat(api): include the parsed version tag in ROM responses The filename parser stores a version tag such as `(v2.00)` or `(version CN-07)` in `Rom.version` and keeps it out of `tags`, but the ROM response schemas never exposed it, so a client had no way to read it. Add `version` next to `revision` and regenerate the frontend types. Closes #5243 * fix(frontend): give hand-built ROM objects the new version field romFixture(), the list row fixture and RelatedGameCard build SimpleRom objects by hand, so vue-tsc rejected them once version became a required schema field. * test(roms): fix mock parameter order in version tag test (code-review) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(api): return null for a missing revision or version and clear version on unmatch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(frontend): show the parsed ROM version on the game overview Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -450,6 +450,7 @@ class RomSchema(BaseModel):
|
||||
is_identified: bool
|
||||
|
||||
revision: str | None
|
||||
version: str | None
|
||||
regions: list[str]
|
||||
languages: list[str]
|
||||
tags: list[str]
|
||||
@@ -484,6 +485,11 @@ class RomSchema(BaseModel):
|
||||
validation_alias="included_sibling_roms"
|
||||
)
|
||||
|
||||
# The filename parser stores "" when a name has no such tag.
|
||||
@field_validator("revision", "version")
|
||||
def empty_tag_to_none(cls, v: str | None) -> str | None:
|
||||
return v or None
|
||||
|
||||
@field_validator(*_METADATA_NAME_LIST_KEYS, mode="before")
|
||||
def clean_name_lists(cls, v: object, info: ValidationInfo) -> object:
|
||||
# A stored blob can hold {id, name} objects where a list of names belongs.
|
||||
|
||||
@@ -2083,7 +2083,8 @@ async def update_rom(
|
||||
),
|
||||
"slug": "",
|
||||
**{c: {} for c in PROVIDER_METADATA_COLUMNS},
|
||||
"revision": "",
|
||||
"revision": None,
|
||||
"version": None,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -995,6 +995,77 @@ def test_update_rom_reparses_tags_on_fs_name_change(
|
||||
assert body["tags"] == []
|
||||
|
||||
|
||||
@patch.object(FSRomsHandler, "rename_fs_rom")
|
||||
@patch.object(IGDBHandler, "get_rom_by_id", return_value=IGDBRom(igdb_id=None))
|
||||
def test_rom_responses_include_the_parsed_version_tag(
|
||||
get_rom_by_id_mock: AsyncMock,
|
||||
rename_fs_rom_mock: AsyncMock,
|
||||
client: TestClient,
|
||||
access_token: str,
|
||||
rom: Rom,
|
||||
):
|
||||
# The version tag is taken out of `tags`, so this field is the only
|
||||
# parsed copy a client gets.
|
||||
response = client.put(
|
||||
f"/api/roms/{rom.id}",
|
||||
headers={"Authorization": f"Bearer {access_token}"},
|
||||
data={"fs_name": "Helmet (version CN-07).nes"},
|
||||
)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["version"] == "CN-07"
|
||||
assert response.json()["tags"] == []
|
||||
|
||||
for path in (f"/api/roms/{rom.id}", f"/api/roms/{rom.id}/simple"):
|
||||
response = client.get(path, headers={"Authorization": f"Bearer {access_token}"})
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["version"] == "CN-07"
|
||||
|
||||
|
||||
@patch.object(FSRomsHandler, "rename_fs_rom")
|
||||
@patch.object(IGDBHandler, "get_rom_by_id", return_value=IGDBRom(igdb_id=None))
|
||||
def test_rom_responses_return_null_for_missing_revision_and_version(
|
||||
get_rom_by_id_mock: AsyncMock,
|
||||
rename_fs_rom_mock: AsyncMock,
|
||||
client: TestClient,
|
||||
access_token: str,
|
||||
rom: Rom,
|
||||
):
|
||||
response = client.put(
|
||||
f"/api/roms/{rom.id}",
|
||||
headers={"Authorization": f"Bearer {access_token}"},
|
||||
data={"fs_name": "Helmet (USA).nes"},
|
||||
)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["revision"] is None
|
||||
assert response.json()["version"] is None
|
||||
|
||||
|
||||
@patch.object(FSRomsHandler, "rename_fs_rom")
|
||||
@patch.object(IGDBHandler, "get_rom_by_id", return_value=IGDBRom(igdb_id=None))
|
||||
def test_update_rom_unmatch_metadata_clears_revision_and_version(
|
||||
get_rom_by_id_mock: AsyncMock,
|
||||
rename_fs_rom_mock: AsyncMock,
|
||||
client: TestClient,
|
||||
access_token: str,
|
||||
rom: Rom,
|
||||
):
|
||||
headers = {"Authorization": f"Bearer {access_token}"}
|
||||
response = client.put(
|
||||
f"/api/roms/{rom.id}",
|
||||
headers=headers,
|
||||
data={"fs_name": "Helmet (Rev 1) (v1.1).nes"},
|
||||
)
|
||||
assert response.json()["revision"] == "1"
|
||||
assert response.json()["version"] == "1.1"
|
||||
|
||||
response = client.put(
|
||||
f"/api/roms/{rom.id}", headers=headers, params={"unmatch_metadata": True}
|
||||
)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["revision"] is None
|
||||
assert response.json()["version"] is None
|
||||
|
||||
|
||||
@patch.object(FSRomsHandler, "rename_fs_rom")
|
||||
@patch.object(IGDBHandler, "get_rom_by_id", return_value=IGDBRom(igdb_id=None))
|
||||
def test_update_rom_manual_alternative_names_are_searchable(
|
||||
|
||||
@@ -90,6 +90,7 @@ export type DetailedRomSchema = {
|
||||
is_unidentified: boolean;
|
||||
is_identified: boolean;
|
||||
revision: (string | null);
|
||||
version: (string | null);
|
||||
regions: Array<string>;
|
||||
languages: Array<string>;
|
||||
tags: Array<string>;
|
||||
|
||||
@@ -82,6 +82,7 @@ export type SimpleRomSchema = {
|
||||
is_unidentified: boolean;
|
||||
is_identified: boolean;
|
||||
revision: (string | null);
|
||||
version: (string | null);
|
||||
regions: Array<string>;
|
||||
languages: Array<string>;
|
||||
tags: Array<string>;
|
||||
|
||||
@@ -97,6 +97,7 @@ export const ROM_DEFAULTS: SimpleRom = {
|
||||
is_unidentified: false,
|
||||
is_identified: true,
|
||||
revision: null,
|
||||
version: null,
|
||||
regions: ["USA"],
|
||||
languages: ["en"],
|
||||
tags: [],
|
||||
|
||||
@@ -76,6 +76,7 @@ function mount(props: Record<string, unknown> = {}) {
|
||||
hltb: null,
|
||||
lastPlayed: null,
|
||||
revision: null,
|
||||
version: null,
|
||||
expansions: [],
|
||||
dlcs: [],
|
||||
remakes: [],
|
||||
@@ -98,6 +99,18 @@ function gridItems(wrapper: ReturnType<typeof mount>) {
|
||||
.map((c) => c.props("items") as IGDBRelatedGame[]);
|
||||
}
|
||||
|
||||
describe("OverviewTab fact rows", () => {
|
||||
it("shows the parsed version", () => {
|
||||
const text = mount({ version: "CN-07" }).text();
|
||||
expect(text).toContain("rom.version");
|
||||
expect(text).toContain("CN-07");
|
||||
});
|
||||
|
||||
it("hides the version row when there is none", () => {
|
||||
expect(mount().text()).not.toContain("rom.version");
|
||||
});
|
||||
});
|
||||
|
||||
describe("OverviewTab related games", () => {
|
||||
// IGDB has always sent `ports`; the overview dropped them on the floor.
|
||||
it("renders a grid for ports", () => {
|
||||
|
||||
@@ -58,6 +58,7 @@ const props = defineProps<{
|
||||
hltb: RomHLTBMetadata | null | undefined;
|
||||
lastPlayed: string | null;
|
||||
revision: string | null;
|
||||
version: string | null;
|
||||
expansions: IGDBRelatedGame[];
|
||||
dlcs: IGDBRelatedGame[];
|
||||
remakes: IGDBRelatedGame[];
|
||||
@@ -213,13 +214,17 @@ const coverSource = computed(() => {
|
||||
<!-- 1. Summary -->
|
||||
<p v-if="summary" class="overview-tab__summary">{{ summary }}</p>
|
||||
|
||||
<!-- 2. Per-ROM fact rows (left-labelled). Revision, Last played +
|
||||
the per-game characteristics (Players, Age rating, RomM
|
||||
<!-- 2. Per-ROM fact rows (left-labelled). Revision, Version, Last
|
||||
played + the per-game characteristics (Players, Age rating, RomM
|
||||
collections) get a row each so each fact can render its own
|
||||
semantic widget instead of being flattened to a chip list. -->
|
||||
<div
|
||||
v-if="
|
||||
revision || lastPlayed || hasQuickFacts || userCollectionTiles.length
|
||||
revision ||
|
||||
version ||
|
||||
lastPlayed ||
|
||||
hasQuickFacts ||
|
||||
userCollectionTiles.length
|
||||
"
|
||||
class="overview-tab__facts"
|
||||
>
|
||||
@@ -228,6 +233,11 @@ const coverSource = computed(() => {
|
||||
<div class="overview-tab__field">{{ revision }}</div>
|
||||
</div>
|
||||
|
||||
<div v-if="version" class="overview-tab__row">
|
||||
<div class="overview-tab__label">{{ t("rom.version") }}</div>
|
||||
<div class="overview-tab__field">{{ version }}</div>
|
||||
</div>
|
||||
|
||||
<div v-if="lastPlayed" class="overview-tab__row">
|
||||
<div class="overview-tab__label">{{ t("rom.last-played") }}</div>
|
||||
<div class="overview-tab__field">{{ lastPlayed }}</div>
|
||||
|
||||
@@ -146,6 +146,7 @@ const syntheticRom = computed<SimpleRom>(() => ({
|
||||
is_unidentified: false,
|
||||
is_identified: false,
|
||||
revision: null,
|
||||
version: null,
|
||||
regions: [],
|
||||
languages: [],
|
||||
tags: [],
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Потвърждение",
|
||||
"verified-rom": "Потвърден ROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "Версия",
|
||||
"versions-count": "{n} версии",
|
||||
"volume-mute": "Заглуши",
|
||||
"volume-unmute": "Включи звука",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Ověření",
|
||||
"verified-rom": "Ověřená ROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "Verze",
|
||||
"versions-count": "{n} verzí",
|
||||
"volume-mute": "Ztlumit",
|
||||
"volume-unmute": "Zrušit ztlumení",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Verifizierung",
|
||||
"verified-rom": "Verifizierte ROM",
|
||||
"verified-rom-hint": "Hash mit ROM-Datenbank abgeglichen",
|
||||
"version": "Version",
|
||||
"versions-count": "{n} Versionen",
|
||||
"volume-mute": "Stummschalten",
|
||||
"volume-unmute": "Stummschaltung aufheben",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Verification",
|
||||
"verified-rom": "Verified ROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "Version",
|
||||
"versions-count": "{n} versions",
|
||||
"volume-mute": "Mute",
|
||||
"volume-unmute": "Unmute",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Verification",
|
||||
"verified-rom": "Verified ROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "Version",
|
||||
"versions-count": "{n} versions",
|
||||
"volume-mute": "Mute",
|
||||
"volume-unmute": "Unmute",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Verificación",
|
||||
"verified-rom": "ROM verificada",
|
||||
"verified-rom-hint": "Hash verificado contra una base de datos de ROM",
|
||||
"version": "Versión",
|
||||
"versions-count": "{n} versiones",
|
||||
"volume-mute": "Silenciar",
|
||||
"volume-unmute": "Quitar silencio",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Vérification",
|
||||
"verified-rom": "ROM vérifiée",
|
||||
"verified-rom-hint": "Empreinte vérifiée dans une base de données de ROM",
|
||||
"version": "Version",
|
||||
"versions-count": "{n} versions",
|
||||
"volume-mute": "Couper le son",
|
||||
"volume-unmute": "Activer le son",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Ellenőrzés",
|
||||
"verified-rom": "Ellenőrzött ROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "Verzió",
|
||||
"versions-count": "{n} verzió",
|
||||
"volume-mute": "Némítás",
|
||||
"volume-unmute": "Némítás feloldása",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Verifica",
|
||||
"verified-rom": "ROM verificata",
|
||||
"verified-rom-hint": "Hash verificato su un database di ROM",
|
||||
"version": "Versione",
|
||||
"versions-count": "{n} versioni",
|
||||
"volume-mute": "Disattiva audio",
|
||||
"volume-unmute": "Riattiva audio",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "検証",
|
||||
"verified-rom": "確認済みROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "バージョン",
|
||||
"versions-count": "{n}件のバージョン",
|
||||
"volume-mute": "ミュート",
|
||||
"volume-unmute": "ミュート解除",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "검증",
|
||||
"verified-rom": "검증된 ROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "버전",
|
||||
"versions-count": "{n}개 버전",
|
||||
"volume-mute": "음소거",
|
||||
"volume-unmute": "음소거 해제",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Weryfikacja",
|
||||
"verified-rom": "Zweryfikowany ROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "Wersja",
|
||||
"versions-count": "{n} wersji",
|
||||
"volume-mute": "Wycisz",
|
||||
"volume-unmute": "Wyłącz wyciszenie",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Verificação",
|
||||
"verified-rom": "ROM verificada",
|
||||
"verified-rom-hint": "Hash verificado em banco de dados de ROM",
|
||||
"version": "Versão",
|
||||
"versions-count": "{n} versões",
|
||||
"volume-mute": "Silenciar",
|
||||
"volume-unmute": "Reativar som",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Verificare",
|
||||
"verified-rom": "ROM verificat",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "Versiune",
|
||||
"versions-count": "{n} versiuni",
|
||||
"volume-mute": "Mut",
|
||||
"volume-unmute": "Activează sunetul",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Проверка",
|
||||
"verified-rom": "Проверенный ROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "Версия",
|
||||
"versions-count": "{n} версий",
|
||||
"volume-mute": "Отключить звук",
|
||||
"volume-unmute": "Включить звук",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Verifiering",
|
||||
"verified-rom": "Verifierad ROM-fil",
|
||||
"verified-rom-hint": "Hashvärdet har verifierats mot ROM-databasen",
|
||||
"version": "Version",
|
||||
"versions-count": "{n} versioner",
|
||||
"volume-mute": "Stäng av ljudet",
|
||||
"volume-unmute": "Sätt på ljudet",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "Doğrulama",
|
||||
"verified-rom": "Doğrulanmış ROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "Sürüm",
|
||||
"versions-count": "{n} sürüm",
|
||||
"volume-mute": "Sesi kapat",
|
||||
"volume-unmute": "Sesi aç",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "验证",
|
||||
"verified-rom": "已验证 ROM",
|
||||
"verified-rom-hint": "校验值与 ROM 数据库一致",
|
||||
"version": "版本",
|
||||
"versions-count": "{n} 个版本",
|
||||
"volume-mute": "静音",
|
||||
"volume-unmute": "取消静音",
|
||||
|
||||
@@ -484,6 +484,7 @@
|
||||
"verification": "驗證",
|
||||
"verified-rom": "已驗證 ROM",
|
||||
"verified-rom-hint": "Hash verified against ROM database",
|
||||
"version": "版本",
|
||||
"versions-count": "{n} 個版本",
|
||||
"volume-mute": "靜音",
|
||||
"volume-unmute": "取消靜音",
|
||||
|
||||
@@ -137,6 +137,7 @@ export function romFixture(overrides: Partial<SimpleRom> = {}): SimpleRom {
|
||||
is_unidentified: false,
|
||||
is_identified: false,
|
||||
revision: null,
|
||||
version: null,
|
||||
regions: [],
|
||||
languages: [],
|
||||
tags: [],
|
||||
|
||||
@@ -381,6 +381,7 @@ const activeTab = computed({
|
||||
:hltb="currentRom.hltb_metadata"
|
||||
:last-played="lastPlayed"
|
||||
:revision="currentRom.revision ?? null"
|
||||
:version="currentRom.version ?? null"
|
||||
:expansions="expansions"
|
||||
:dlcs="dlcs"
|
||||
:remakes="remakes"
|
||||
|
||||
Reference in New Issue
Block a user