Add Vitest, jsdom and importer tests

Set up testing with Vitest and jsdom and add unit tests for importers (jellyfin, playnite, stashapp, xbvr). Add typedoc configuration and update vite.config.ts and importer source files to support the tests. Ignore generated docs by adding /docs to .gitignore and add test-related devDependencies (vitest, @vitest/ui, jsdom, typedoc) in package.json.
This commit is contained in:
Lars Behrends
2026-04-16 15:09:06 +02:00
parent 432416cfc5
commit 63c5d0a7c0
13 changed files with 3336 additions and 13 deletions
+91
View File
@@ -1,48 +1,96 @@
/**
* XBVR Importer Module
*
* This module provides functionality to import VR adult video content from an XBVR instance into the Kyoo media database.
* It fetches scene data from the DeoVR API endpoint, extracts actors and video details, and handles both new imports
* and updates to existing entries. The module specifically filters for content in the 'Recent' scene group.
*
* @module xbvrImporter
*/
const BASE_URL = import.meta.env.VITE_API_URL;
// Import the source mapping and types
import { SOURCE_CATEGORY_MAPPING, Media, Staff } from '@/types';
/**
* Configuration for connecting to an XBVR instance
*/
export interface XBVRConfig {
/** URL of the XBVR server */
url: string;
/** API key for authentication (optional) */
apiKey?: string;
/** If true, update existing media entries; if false, only import new entries */
updateExisting?: boolean;
}
/**
* Progress tracking for the import operation
*/
export interface ImportProgress {
/** Current number of items processed */
current: number;
/** Total number of items to process */
total: number;
/** Current stage of the import process */
stage: 'idle' | 'fetching' | 'importing' | 'complete' | 'error';
/** Human-readable status message */
message: string;
/** Number of videos successfully imported */
videosImported: number;
/** Number of actors successfully imported */
actorsImported: number;
/** Array of error messages encountered during import */
errors: string[];
}
/**
* Basic video information from the DeoVR scene list
*/
export interface XBVRVideo {
/** Video title */
title: string;
/** Video length in seconds */
videoLength: number;
/** URL to the video thumbnail */
thumbnailUrl: string;
/** URL to fetch detailed video information */
video_url: string;
}
/**
* Detailed video information as returned by the XBVR API
*/
export interface XBVRVideoDetail {
/** Unique video identifier */
id: number;
/** Video title */
title: string;
/** Video description */
description: string;
/** Release date as Unix timestamp */
date: number;
/** URL to the video thumbnail */
thumbnailUrl: string;
/** Average rating */
rating_avg: number;
/** Screen type (e.g., '180', '360', 'dome') */
screenType: string;
/** Stereo mode (e.g., 'sbs', 'tb') */
stereoMode: string;
/** Video length in seconds */
videoLength: number;
/** Pay site information */
paysite?: {
name: string;
};
/** Array of actors in the video */
actors: Array<{
id: number;
name: string;
}>;
/** Array of category tags */
categories: Array<{
tag: {
name: string;
@@ -50,16 +98,59 @@ export interface XBVRVideoDetail {
}>;
}
/**
* Scene list structure as returned by the DeoVR API
*/
export interface XBVRSceneList {
/** Array of scene groups */
scenes: Array<{
/** Name of the scene group (e.g., 'Recent', 'Favorites') */
name: string;
/** List of videos in this group */
list: XBVRVideo[];
}>;
}
/**
* Callback function for logging import progress messages
* @param message - The log message to display
*/
export type LogCallback = (message: string) => void;
/**
* Callback function for updating import progress
* @param progress - Partial progress object with updated fields
*/
export type ProgressCallback = (progress: Partial<ImportProgress>) => void;
/**
* Imports VR adult videos and actors from an XBVR instance into the Kyoo media database
*
* This function performs the following steps:
* 1. Fetches existing media and cast from Kyoo to check for duplicates
* 2. Fetches the scene list from the DeoVR API endpoint
* 3. Extracts videos from the 'Recent' scene group
* 4. Fetches detailed information for each video
* 5. Imports or updates actors first
* 6. Imports or updates videos with their associated actors
*
* Videos and actors containing 'aka:' in their name are automatically skipped.
*
* @param config - Configuration for connecting to XBVR
* @param logCallback - Callback function for logging progress messages
* @param progressCallback - Callback function for updating import progress
* @returns Promise resolving to the final import progress state
*
* @example
* ```typescript
* const progress = await importFromXBVR(
* { url: 'http://localhost:9999', apiKey: 'your-api-key' },
* (msg) => console.log(msg),
* (prog) => updateUI(prog)
* );
* console.log(`Imported ${progress.videosImported} videos and ${progress.actorsImported} actors`);
* ```
*/
export async function importFromXBVR(
config: XBVRConfig,
logCallback: LogCallback,