imports are cool xD

This commit is contained in:
Lars Behrends
2026-04-10 12:24:54 +02:00
parent 73c578f1ec
commit d6ad4c80b3
4 changed files with 92 additions and 9 deletions

View File

@@ -60,6 +60,29 @@ export interface PlayniteGamesResponse {
export type LogCallback = (message: string) => void;
export type ProgressCallback = (progress: Partial<ImportProgress>) => void;
async function fetchGameCover(baseUrl: string, headers: Record<string, string>, gameId: string): Promise<string | null> {
try {
const coverResponse = await fetch(`${baseUrl}/api/games/${gameId}/cover`, {
method: 'GET',
headers
});
if (!coverResponse.ok) {
return null;
}
const blob = await coverResponse.blob();
const arrayBuffer = await blob.arrayBuffer();
const base64 = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
// Determine MIME type from blob
const mimeType = blob.type || 'image/jpeg';
return `data:${mimeType};base64,${base64}`;
} catch (error) {
return null;
}
}
export async function importFromPlaynite(
config: PlayniteConfig,
logCallback: LogCallback,
@@ -194,7 +217,6 @@ export async function importFromPlaynite(
// Staff is for actors/performers only - leave empty for games
const staff: any[] = [];
// Determine type based on genres/features
let type = 'Game';
//if (game.genres?.includes('Visual Novel') || game.genres?.includes('Adventure')) {
@@ -242,7 +264,7 @@ export async function importFromPlaynite(
links: game.links || [],
achievements: [],
year: year.toString(),
poster: null,
poster: game.coverBase64 || null,
banner: null,
rating: rating,
category: 'Game',