Skip to main content

romm_cli/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents a firmware file associated with a platform.
4#[derive(Debug, Clone, Deserialize, Serialize)]
5pub struct Firmware {
6    /// Unique identifier for the firmware.
7    pub id: u64,
8    /// Original file name of the firmware.
9    pub file_name: String,
10    /// File name without RomM tags.
11    pub file_name_no_tags: String,
12    /// File name without extension.
13    pub file_name_no_ext: String,
14    /// File extension (e.g., ".bin").
15    pub file_extension: String,
16    /// Relative file path within the RomM storage.
17    pub file_path: String,
18    /// File size in bytes.
19    pub file_size_bytes: u64,
20    /// Full absolute path to the file.
21    pub full_path: String,
22    /// Whether the firmware hash has been verified against a database.
23    pub is_verified: bool,
24    /// CRC32 hash of the file.
25    pub crc_hash: String,
26    /// MD5 hash of the file.
27    pub md5_hash: String,
28    /// SHA1 hash of the file.
29    pub sha1_hash: String,
30    /// True if the file is missing from the filesystem.
31    pub missing_from_fs: bool,
32    /// ISO 8601 creation timestamp.
33    pub created_at: String,
34    /// ISO 8601 update timestamp.
35    pub updated_at: String,
36}
37
38/// A gaming platform (console or system) supported by RomM.
39#[derive(Debug, Clone, Deserialize, Serialize)]
40pub struct Platform {
41    /// Unique identifier for the platform.
42    pub id: u64,
43    /// URL-friendly slug (e.g., "nes").
44    pub slug: String,
45    /// Filesystem-friendly slug used for directory naming.
46    pub fs_slug: String,
47    /// Total number of ROMs assigned to this platform.
48    pub rom_count: u64,
49    /// Canonical name of the platform.
50    pub name: String,
51    /// IGDB slug for metadata lookup.
52    pub igdb_slug: Option<String>,
53    /// MobyGames slug for metadata lookup.
54    pub moby_slug: Option<String>,
55    /// HowLongToBeat slug for metadata lookup.
56    pub hltb_slug: Option<String>,
57    /// Custom user-defined name for the platform.
58    pub custom_name: Option<String>,
59    /// IGDB ID for metadata lookup.
60    pub igdb_id: Option<i64>,
61    /// ScreenScraper ID for metadata lookup.
62    pub sgdb_id: Option<i64>,
63    /// MobyGames ID for metadata lookup.
64    pub moby_id: Option<i64>,
65    /// LaunchBox ID for metadata lookup.
66    pub launchbox_id: Option<i64>,
67    /// ScreenScraper ID for metadata lookup.
68    pub ss_id: Option<i64>,
69    /// RetroAchievements ID for metadata lookup.
70    pub ra_id: Option<i64>,
71    /// Hasheous ID for metadata lookup.
72    pub hasheous_id: Option<i64>,
73    /// The Games DB ID for metadata lookup.
74    pub tgdb_id: Option<i64>,
75    /// Flashpoint ID for metadata lookup.
76    pub flashpoint_id: Option<i64>,
77    /// Category of the platform (e.g., "Console", "Handheld").
78    pub category: Option<String>,
79    /// Console generation (e.g., 3).
80    pub generation: Option<i64>,
81    /// Name of the platform family (e.g., "Nintendo").
82    pub family_name: Option<String>,
83    /// Slug of the platform family (e.g., "nintendo").
84    pub family_slug: Option<String>,
85    /// Official website URL.
86    pub url: Option<String>,
87    /// URL to the platform logo image.
88    pub url_logo: Option<String>,
89    /// List of firmware files required or associated with this platform.
90    pub firmware: Vec<Firmware>,
91    /// Preferred aspect ratio for the platform.
92    pub aspect_ratio: Option<String>,
93    /// ISO 8601 creation timestamp.
94    pub created_at: String,
95    /// ISO 8601 update timestamp.
96    pub updated_at: String,
97    /// Total size of all ROMs for this platform in bytes.
98    pub fs_size_bytes: u64,
99    /// True if the platform is not yet fully identified in the RomM database.
100    pub is_unidentified: bool,
101    /// True if the platform has been identified and linked to metadata.
102    pub is_identified: bool,
103    /// True if the platform directory is missing from the filesystem.
104    pub missing_from_fs: bool,
105    /// Name used for display in the UI (custom name or original name).
106    pub display_name: Option<String>,
107}
108
109/// Represents a single ROM file and its associated metadata.
110#[derive(Debug, Clone, Deserialize, Serialize)]
111pub struct Rom {
112    /// Unique identifier for the ROM.
113    pub id: u64,
114    /// ID of the parent platform.
115    pub platform_id: u64,
116    /// Slug of the parent platform.
117    pub platform_slug: Option<String>,
118    /// Filesystem slug of the parent platform.
119    pub platform_fs_slug: Option<String>,
120    /// Custom name of the parent platform.
121    pub platform_custom_name: Option<String>,
122    /// Display name of the parent platform.
123    pub platform_display_name: Option<String>,
124    /// Name of the ROM file on disk.
125    pub fs_name: String,
126    /// ROM file name without RomM tags.
127    pub fs_name_no_tags: String,
128    /// ROM file name without extension.
129    pub fs_name_no_ext: String,
130    /// File extension of the ROM (e.g., ".nes").
131    pub fs_extension: String,
132    /// Relative path to the ROM file.
133    pub fs_path: String,
134    /// Size of the ROM file in bytes.
135    pub fs_size_bytes: u64,
136    /// Canonical name of the game.
137    pub name: String,
138    /// URL-friendly slug for the game.
139    pub slug: Option<String>,
140    /// Brief description or summary of the game.
141    pub summary: Option<String>,
142    /// Path to a small thumbnail cover image.
143    pub path_cover_small: Option<String>,
144    /// Path to a large cover image.
145    pub path_cover_large: Option<String>,
146    /// Original URL of the cover image.
147    pub url_cover: Option<String>,
148    /// True if the ROM is not yet fully identified.
149    pub is_unidentified: bool,
150    /// True if the ROM has been identified and linked to metadata.
151    pub is_identified: bool,
152}
153
154/// A paginated list of ROMs returned by the API.
155#[derive(Debug, Clone, Deserialize, Serialize)]
156pub struct RomList {
157    /// The list of ROM items in this page.
158    pub items: Vec<Rom>,
159    /// Total number of ROMs matching the query across all pages.
160    pub total: u64,
161    /// Maximum number of items returned in this request.
162    pub limit: u64,
163    /// Number of items skipped from the beginning.
164    pub offset: u64,
165}
166
167/// Response row from [`GET /api/collections/virtual`](crate::endpoints::collections::ListVirtualCollections).
168#[derive(Debug, Clone, Deserialize, Serialize)]
169pub struct VirtualCollectionRow {
170    pub id: String,
171    pub name: String,
172    #[serde(rename = "type")]
173    pub collection_type: String,
174    #[serde(default)]
175    pub rom_count: u64,
176    #[serde(default)]
177    pub is_virtual: bool,
178}
179
180impl From<VirtualCollectionRow> for Collection {
181    fn from(v: VirtualCollectionRow) -> Self {
182        Self {
183            id: 0,
184            name: v.name,
185            collection_type: Some(v.collection_type),
186            rom_count: Some(v.rom_count),
187            is_smart: false,
188            is_virtual: true,
189            virtual_id: Some(v.id),
190        }
191    }
192}
193
194/// Manual / smart / virtual row for the library collections pane.
195///
196/// Virtual (autogenerated) collections use string IDs from RomM; see [`virtual_id`](Self::virtual_id)
197/// and [`is_virtual`](Self::is_virtual). Numeric [`id`](Self::id) is unused (0) for virtual rows.
198#[derive(Debug, Clone, Deserialize, Serialize)]
199pub struct Collection {
200    pub id: u64,
201    pub name: String,
202    #[serde(rename = "type")]
203    pub collection_type: Option<String>,
204    pub rom_count: Option<u64>,
205    /// Smart collections are listed separately by RomM; used for ROM filter/cache keys.
206    #[serde(default)]
207    pub is_smart: bool,
208    /// Autogenerated / virtual collections from `GET /api/collections/virtual`.
209    #[serde(default)]
210    pub is_virtual: bool,
211    #[serde(default)]
212    pub virtual_id: Option<String>,
213}