Merge pull request #3815 from rommapp/fix/verified-badge-hash-match

fix(frontend): base v2 verified badge on real DB hash matches
This commit is contained in:
Georges-Antoine Assi
2026-07-18 19:59:49 -04:00
committed by GitHub
23 changed files with 156 additions and 26 deletions

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Потвърждение",
"verified-rom": "Потвърден ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} версии",
"volume-mute": "Заглуши",
"volume-unmute": "Включи звука",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Ověření",
"verified-rom": "Ověřená ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} verzí",
"volume-mute": "Ztlumit",
"volume-unmute": "Zrušit ztlumení",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Verifizierung",
"verified-rom": "Verifizierte ROM",
"verified-rom-hint": "Hash mit ROM-Datenbank abgeglichen",
"versions-count": "{n} Versionen",
"volume-mute": "Stummschalten",
"volume-unmute": "Stummschaltung aufheben",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Verification",
"verified-rom": "Verified ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} versions",
"volume-mute": "Mute",
"volume-unmute": "Unmute",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Upload tracks",
"verification": "Verification",
"verified-rom": "Verified ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} versions",
"volume-mute": "Mute",
"volume-unmute": "Unmute",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Verificación",
"verified-rom": "ROM verificada",
"verified-rom-hint": "Hash verificado contra una base de datos de ROM",
"versions-count": "{n} versiones",
"volume-mute": "Silenciar",
"volume-unmute": "Quitar silencio",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Vérification",
"verified-rom": "ROM vérifiée",
"verified-rom-hint": "Empreinte vérifiée dans une base de données de ROM",
"versions-count": "{n} versions",
"volume-mute": "Couper le son",
"volume-unmute": "Activer le son",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Ellenőrzés",
"verified-rom": "Ellenőrzött ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} verzió",
"volume-mute": "Némítás",
"volume-unmute": "Némítás feloldása",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Verifica",
"verified-rom": "ROM verificata",
"verified-rom-hint": "Hash verificato su un database di ROM",
"versions-count": "{n} versioni",
"volume-mute": "Disattiva audio",
"volume-unmute": "Riattiva audio",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "検証",
"verified-rom": "確認済みROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n}件のバージョン",
"volume-mute": "ミュート",
"volume-unmute": "ミュート解除",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "검증",
"verified-rom": "검증된 ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n}개 버전",
"volume-mute": "음소거",
"volume-unmute": "음소거 해제",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Weryfikacja",
"verified-rom": "Zweryfikowany ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} wersji",
"volume-mute": "Wycisz",
"volume-unmute": "Wyłącz wyciszenie",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Verificação",
"verified-rom": "ROM verificada",
"verified-rom-hint": "Hash verificado em banco de dados de ROM",
"versions-count": "{n} versões",
"volume-mute": "Silenciar",
"volume-unmute": "Reativar som",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Verificare",
"verified-rom": "ROM verificat",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} versiuni",
"volume-mute": "Mut",
"volume-unmute": "Activează sunetul",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "Проверка",
"verified-rom": "Проверенный ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} версий",
"volume-mute": "Отключить звук",
"volume-unmute": "Включить звук",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Parça yükle",
"verification": "Doğrulama",
"verified-rom": "Doğrulanmış ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} sürüm",
"volume-mute": "Sesi kapat",
"volume-unmute": "Sesi aç",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "验证",
"verified-rom": "已验证 ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} 个版本",
"volume-mute": "静音",
"volume-unmute": "取消静音",

View File

@@ -431,6 +431,7 @@
"upload-tracks": "Add tracks",
"verification": "驗證",
"verified-rom": "已驗證 ROM",
"verified-rom-hint": "Hash verified against ROM database",
"versions-count": "{n} 個版本",
"volume-mute": "靜音",
"volume-unmute": "取消靜音",

View File

@@ -60,12 +60,18 @@ const actions = useGameActions(() => props.rom);
<span v-if="verified" class="r-v2-det-header__sep"> · </span>
<!-- Icon-only verified indicator. The check decagram is a strong
enough signal on its own; the "Verified" word was just noise
in a row that's already mostly text. RTooltip preserves the
label for keyboard / hover discovery. -->
<span v-if="verified" class="r-v2-det-header__verified">
in a row that's already mostly text. The tooltip spells out
what "verified" means (a database hash match) so the badge
isn't cryptic; the short label is the accessible name. -->
<span
v-if="verified"
class="r-v2-det-header__verified"
:aria-label="t('rom.verified-rom')"
tabindex="0"
>
<RIcon icon="mdi-check-decagram" :size="18" color="success" />
<RTooltip
:text="t('rom.verified-rom')"
:text="t('rom.verified-rom-hint')"
location="top"
activator="parent"
/>

View File

@@ -3,9 +3,8 @@
// 1. File info — name + size only.
// 2. Hashes — CRC, MD5, SHA1, all mono. RTag with eyebrow label.
// 3. Verification — RTag per database; tone="success" for match,
// neutral for miss. Independent from the "Verified" pill in the
// title header which only checks `crc_hash`. RA match comes from
// `rom.ra_id`.
// neutral for miss. Same source of truth (Hasheous match flags) as
// the "Verified" badge in the header, via `VERIFICATION_DATABASES`.
// 4. Metadata sources — ProviderGrid (linked + unlinked).
import { RTag } from "@v2/lib";
import { computed } from "vue";
@@ -14,6 +13,10 @@ import type { DetailedRom } from "@/stores/roms";
import { formatBytes } from "@/utils";
import ProviderGrid from "@/v2/components/GameDetails/ProviderGrid.vue";
import HashChip from "@/v2/components/shared/HashChip.vue";
import {
matchesDatabase,
VERIFICATION_DATABASES,
} from "@/v2/utils/romVerification";
defineOptions({ inheritAttrs: false });
@@ -55,24 +58,16 @@ const hashRows = computed<{ label: string; value: string | null }[]>(() => {
type Verification = { label: string; match: boolean };
// Per-database match badges. Hasheous covers TOSEC / No-Intro / Redump
// / FBNeo / MAME (either Arcade or MESS counts). RA is independent —
// the rom is "verified as RA" when it has an `ra_id` linked.
const verifications = computed<Verification[]>(() => {
const r = props.rom;
const h = r.hasheous_metadata ?? null;
return [
{ label: "TOSEC", match: Boolean(h?.tosec_match) },
{ label: "No-Intro", match: Boolean(h?.nointro_match) },
{ label: "Redump", match: Boolean(h?.redump_match) },
{ label: "FBNeo", match: Boolean(h?.fbneo_match) },
{
label: "MAME",
match: Boolean(h?.mame_arcade_match || h?.mame_mess_match),
},
{ label: "RA", match: Boolean(r.ra_id) },
];
});
// Per-database match badges, driven by the shared VERIFICATION_DATABASES
// so this list stays in lockstep with the header badge and the backend
// filter. A match means the ROM's hash was found in that database (via
// Hasheous), which is what "verified" communicates.
const verifications = computed<Verification[]>(() =>
VERIFICATION_DATABASES.map((db) => ({
label: db.label,
match: matchesDatabase(props.rom, db.keys),
})),
);
</script>
<template>

View File

@@ -0,0 +1,63 @@
import { describe, expect, it } from "vitest";
import type { RomHasheousMetadata } from "@/__generated__";
import type { SimpleRom } from "@/stores/roms";
import {
isRomVerified,
matchesDatabase,
VERIFICATION_DATABASES,
VERIFICATION_KEYS,
} from "./romVerification";
// Only `hasheous_metadata` is read; cast a minimal stub to SimpleRom.
const rom = (hasheous_metadata?: RomHasheousMetadata | null): SimpleRom =>
({ hasheous_metadata }) as SimpleRom;
describe("isRomVerified", () => {
it("is false when there is no hasheous metadata", () => {
expect(isRomVerified(rom())).toBe(false);
expect(isRomVerified(rom(null))).toBe(false);
});
it("is false when no signature matched (e.g. a hashed-but-unmatched archive)", () => {
expect(
isRomVerified(
rom({ tosec_match: false, nointro_match: false, ra_match: false }),
),
).toBe(false);
});
it("is true when any single database matched", () => {
for (const key of VERIFICATION_KEYS) {
expect(isRomVerified(rom({ [key]: true }))).toBe(true);
}
});
});
describe("matchesDatabase", () => {
it("matches MAME on either the arcade or the mess flag", () => {
const mame = VERIFICATION_DATABASES.find((db) => db.label === "MAME")!;
expect(matchesDatabase(rom(), mame.keys)).toBe(false);
expect(matchesDatabase(rom({ mame_arcade_match: true }), mame.keys)).toBe(
true,
);
expect(matchesDatabase(rom({ mame_mess_match: true }), mame.keys)).toBe(
true,
);
});
it("treats RetroAchievements as a database match (ra_match, not ra_id)", () => {
const ra = VERIFICATION_DATABASES.find(
(db) => db.label === "RetroAchievements",
)!;
expect(ra.keys).toEqual(["ra_match"]);
expect(matchesDatabase(rom({ ra_match: true }), ra.keys)).toBe(true);
});
});
describe("VERIFICATION_KEYS", () => {
it("is the flattened set of every database's match flags", () => {
expect(VERIFICATION_KEYS).toEqual(
VERIFICATION_DATABASES.flatMap((db) => db.keys),
);
});
});

View File

@@ -0,0 +1,45 @@
// romVerification — single source of truth for what "verified" means: a
// ROM whose file hash matched a known ROM database (via Hasheous). Mirrors
// the backend's `_filter_by_verified` (roms_handler.py) so the header
// badge, the per-database chips in the Metadata tab, and the library
// "verified" filter all agree. Merely having a computed hash
// (crc/md5/sha1) does NOT make a ROM verified.
import type { RomHasheousMetadata } from "@/__generated__";
import type { SimpleRom } from "@/stores/roms";
// Each database this ROM's hash can be checked against, with the Hasheous
// match flag(s) that count as a hit. MAME reports Arcade and MESS
// separately; either one means the ROM matched MAME. Order is the display
// order for the Metadata tab chips.
export const VERIFICATION_DATABASES: {
label: string;
keys: (keyof RomHasheousMetadata)[];
}[] = [
{ label: "TOSEC", keys: ["tosec_match"] },
{ label: "No-Intro", keys: ["nointro_match"] },
{ label: "Redump", keys: ["redump_match"] },
{ label: "MAME", keys: ["mame_arcade_match", "mame_mess_match"] },
{ label: "FBNeo", keys: ["fbneo_match"] },
{ label: "WHDLoad", keys: ["whdload_match"] },
{ label: "PureDOS", keys: ["puredos_match"] },
{ label: "RetroAchievements", keys: ["ra_match"] },
];
// Flattened match flags, i.e. the exact set the backend filters on.
export const VERIFICATION_KEYS: (keyof RomHasheousMetadata)[] =
VERIFICATION_DATABASES.flatMap((db) => db.keys);
// Whether a single database matched for this ROM.
export function matchesDatabase(
rom: SimpleRom,
keys: (keyof RomHasheousMetadata)[],
): boolean {
const h = rom.hasheous_metadata;
if (!h) return false;
return keys.some((key) => Boolean(h[key]));
}
// Whether the ROM is verified against any known database.
export function isRomVerified(rom: SimpleRom): boolean {
return matchesDatabase(rom, VERIFICATION_KEYS);
}

View File

@@ -29,6 +29,7 @@ import SaveDataTab from "@/v2/components/GameDetails/SaveDataTab.vue";
import { useBackgroundArt } from "@/v2/composables/useBackgroundArt";
import { useRightStickScroll } from "@/v2/composables/useRightStickScroll";
import { useWebpSupport } from "@/v2/composables/useWebpSupport";
import { isRomVerified } from "@/v2/utils/romVerification";
const route = useRoute();
const router = useRouter();
@@ -129,7 +130,9 @@ const regions = computed(() => currentRom.value?.regions ?? []);
const languages = computed(() => currentRom.value?.languages ?? []);
const tags = computed(() => currentRom.value?.tags ?? []);
const verified = computed(() => Boolean(currentRom.value?.crc_hash));
const verified = computed(() =>
currentRom.value ? isRomVerified(currentRom.value) : false,
);
const coverPath = computed(() => {
const r = currentRom.value;