diff --git a/src/components/Roms/RomsInteractive.tsx b/src/components/Roms/RomsInteractive.tsx
index e32b675..0d74d93 100644
--- a/src/components/Roms/RomsInteractive.tsx
+++ b/src/components/Roms/RomsInteractive.tsx
@@ -5,6 +5,9 @@ import { FaTriangleExclamation } from "react-icons/fa6";
import { baseRoms } from "@/data/baseRoms";
import { useBaseRoms } from "@/contexts/BaseRomContext";
import BaseRomCard from "@/components/BaseRomCard";
+import { platformAcceptAll } from "@/utils/idb";
+
+const ALLOWED_TYPES = platformAcceptAll().split(",");
export default function RomsInteractive() {
const { supported, linked, statuses, cached, totalCachedBytes, importUploadedBlob, importToCache, removeFromCache, unlinkRom, ensurePermission, countReady } = useBaseRoms();
@@ -59,6 +62,10 @@ export default function RomsInteractive() {
setDragActive(false);
const file = e.dataTransfer?.files?.[0];
if (!file) return;
+ if (!ALLOWED_TYPES.includes(`.${file.name.split(".").pop()?.toLowerCase() ?? ""}`)) {
+ setUploadMsg(`Unrecognized file. Not cached. Accepted types: ${ALLOWED_TYPES.join(", ")}`);
+ return;
+ }
const name = await importUploadedBlob(file);
if (name) setUploadMsg(`Recognized and cached: ${name}`);
else setUploadMsg("Unrecognized ROM. Not cached.");
@@ -76,7 +83,7 @@ export default function RomsInteractive() {
diff --git a/src/data/baseRoms.ts b/src/data/baseRoms.ts
index 1a9a94f..c2a4f18 100644
--- a/src/data/baseRoms.ts
+++ b/src/data/baseRoms.ts
@@ -1,7 +1,15 @@
+export const PLATFORMS = [
+ "GB",
+ "GBC",
+ "GBA",
+ "NDS",
+] as const;
+export type Platform = typeof PLATFORMS[number];
+
export type BaseRom = {
id: string;
name: string;
- platform: "GB" | "GBC" | "GBA" | "NDS";
+ platform: Platform;
region: string;
sha1?: string;
};
diff --git a/src/utils/idb.ts b/src/utils/idb.ts
index 34cbe09..0fb2b8d 100644
--- a/src/utils/idb.ts
+++ b/src/utils/idb.ts
@@ -1,4 +1,6 @@
// Minimal IndexedDB helpers for storing FileSystemFileHandle references
+import type { Platform } from "@/data/baseRoms";
+import { PLATFORMS } from "@/data/baseRoms";
const DB_NAME = "romhaven";
const DB_VERSION = 2;
@@ -113,4 +115,31 @@ export async function getAllBlobEntries(): Promise();
+ for (const plat of p) {
+ const exts = platformAccept(plat).split(",");
+ for (const ext of exts) {
+ extSet.add(ext.trim());
+ }
+ }
+ return Array.from(extSet).join(",");
+ }
+ // Exhaustive check using a mapping object for platform strings
+ const mapping: Record = {
+ GB: ".gb",
+ GBC: ".gbc,.gb",
+ GBA: ".gba",
+ NDS: ".nds",
+ };
+
+ // If `p` is not a valid Platform, TypeScript will error here.
+ return mapping[p];
+}
+
+export function platformAcceptAll(): string {
+ return platformAccept([...PLATFORMS]);
+}