more game page stuff
This commit is contained in:
@@ -32,6 +32,7 @@ export interface DetailedGame extends Game {
|
||||
collections?: string[];
|
||||
favorite?: boolean;
|
||||
manualUrl?: string;
|
||||
platformId?: number;
|
||||
}
|
||||
|
||||
export interface RommCollection {
|
||||
@@ -311,7 +312,22 @@ export const rommApiClient = {
|
||||
screenshots: (json.screenshots || []).map((s: any) => s.url ? getFullImageUrl(s.url) || '' : ''),
|
||||
fsName: json.fs_name,
|
||||
regions: regions.length > 0 ? regions : ['Global'],
|
||||
players: json.players || getFirst('total_players') || getFirst('players'),
|
||||
players: (() => {
|
||||
let val = json.metadatum?.player_count || json.players || getFirst('player_count') || getFirst('total_players') || getFirst('players') || getFirst('max_players');
|
||||
if (val && (String(val) === '1' || String(val).toLowerCase() === 'single player')) {
|
||||
const modes = getAll('game_modes').map(sanitize).map(m => m.toLowerCase());
|
||||
if (modes.includes('multiplayer') || modes.includes('co-operative') || modes.includes('split screen')) {
|
||||
val = 'Multiplayer';
|
||||
}
|
||||
}
|
||||
if (val) {
|
||||
val = String(val);
|
||||
if (!val.toLowerCase().includes('player')) {
|
||||
val = `${val} ${val === '1' ? 'Player' : 'Players'}`;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
})(),
|
||||
rating: ratingVal ? Math.round(Number(ratingVal)) : undefined,
|
||||
esrbRating: ageRatingStr,
|
||||
sha1: json.hashes?.sha1,
|
||||
@@ -321,6 +337,7 @@ export const rommApiClient = {
|
||||
])).filter(Boolean),
|
||||
favorite: (json.user_collections || json.rom_collections || []).some((c: any) => c.is_favorite || c.name === 'Favorites'),
|
||||
manualUrl: getFullImageUrl(json.url_manual),
|
||||
platformId: json.platform_id,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -422,6 +439,19 @@ export const rommApiClient = {
|
||||
return res.json();
|
||||
},
|
||||
|
||||
getPlayUrl(gameId: string): string {
|
||||
return `${this.apiBase}/roms/${gameId}/play`;
|
||||
},
|
||||
|
||||
getManualUrl(gameId: string, platformId?: number): string {
|
||||
// Constructed manual URL: /assets/romm/resources/roms/[platform_id]/[rom_id]/manual/[rom_id].pdf
|
||||
// We return a relative path to ensure the request goes through our local origin (bypassing CORS via Vite proxy).
|
||||
if (platformId) {
|
||||
return `/assets/romm/resources/roms/${platformId}/${gameId}/manual/${gameId}.pdf`;
|
||||
}
|
||||
return `${this.apiBase}/roms/${gameId}/manual`;
|
||||
},
|
||||
|
||||
async fetchCurrentUser(): Promise<UserProfile> {
|
||||
const res = await fetch(`${this.apiBase}/users/me`, { headers: this.headers });
|
||||
if (!res.ok) throw new Error('Failed to fetch user profile.');
|
||||
|
||||
Reference in New Issue
Block a user