5390bbf615
Build and Push Docker Image / build (push) Successful in 2m6s
Docs Check / Markdown lint (push) Successful in 1m58s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 2m4s
Docs Check / Mermaid diagram parse check (push) Successful in 1m58s
CI / Security audit (push) Successful in 1m48s
CI / Tests & coverage (push) Successful in 1m59s
CI / Swagger Validation & Coverage (push) Successful in 1m47s
145 lines
4.0 KiB
JavaScript
145 lines
4.0 KiB
JavaScript
// Copyright (c) 2026 Gordon Bolton. MIT License.
|
|
const axios = require('axios');
|
|
const { logToFile } = require('../utils/logger');
|
|
|
|
/**
|
|
* Ombi API client for fetching requests and searching media.
|
|
* Provides integration with Ombi request management system.
|
|
*/
|
|
class OmbiClient {
|
|
constructor(url, apiKey) {
|
|
this.url = url.replace(/\/$/, ''); // Remove trailing slash
|
|
this.apiKey = apiKey;
|
|
this.axios = axios.create({
|
|
headers: { 'ApiKey': this.apiKey },
|
|
timeout: 10000
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get all movie requests from Ombi
|
|
* @returns {Promise<Array>} Array of movie request objects
|
|
*/
|
|
async getMovieRequests() {
|
|
try {
|
|
const response = await this.axios.get(`${this.url}/api/v1/Request/movie`);
|
|
return response.data || [];
|
|
} catch (error) {
|
|
logToFile(`[OmbiClient] Movie requests error: ${error.message}`);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get all TV requests from Ombi
|
|
* @returns {Promise<Array>} Array of TV request objects
|
|
*/
|
|
async getTvRequests() {
|
|
try {
|
|
const response = await this.axios.get(`${this.url}/api/v1/Request/tv`);
|
|
return response.data || [];
|
|
} catch (error) {
|
|
logToFile(`[OmbiClient] TV requests error: ${error.message}`);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Search for movies by TMDB ID
|
|
* @param {string} tmdbId - TheMovieDB ID
|
|
* @returns {Promise<Object|null>} Search result object or null if not found
|
|
*/
|
|
async searchMovieByTmdbId(tmdbId) {
|
|
if (!tmdbId) return null;
|
|
|
|
try {
|
|
const response = await this.axios.get(`${this.url}/api/v1/Search/movie/${tmdbId}`);
|
|
return response.data || null;
|
|
} catch (error) {
|
|
logToFile(`[OmbiClient] Movie search error for TMDB ID ${tmdbId}: ${error.message}`);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Search for movies by IMDB ID
|
|
* @param {string} imdbId - IMDB ID
|
|
* @returns {Promise<Object|null>} Search result object or null if not found
|
|
*/
|
|
async searchMovieByImdbId(imdbId) {
|
|
if (!imdbId) return null;
|
|
|
|
try {
|
|
const response = await this.axios.get(`${this.url}/api/v1/Search/movie/imdb/${imdbId}`);
|
|
return response.data || null;
|
|
} catch (error) {
|
|
logToFile(`[OmbiClient] Movie search error for IMDB ID ${imdbId}: ${error.message}`);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Search for TV shows by TVDB ID
|
|
* @param {string} tvdbId - TheTVDB ID
|
|
* @returns {Promise<Object|null>} Search result object or null if not found
|
|
*/
|
|
async searchTvByTvdbId(tvdbId) {
|
|
if (!tvdbId) return null;
|
|
|
|
try {
|
|
const response = await this.axios.get(`${this.url}/api/v1/Search/tv/${tvdbId}`);
|
|
return response.data || null;
|
|
} catch (error) {
|
|
logToFile(`[OmbiClient] TV search error for TVDB ID ${tvdbId}: ${error.message}`);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Search for TV shows by TMDB ID
|
|
* @param {string} tmdbId - TheMovieDB ID
|
|
* @returns {Promise<Object|null>} Search result object or null if not found
|
|
*/
|
|
async searchTvByTmdbId(tmdbId) {
|
|
if (!tmdbId) return null;
|
|
|
|
try {
|
|
const response = await this.axios.get(`${this.url}/api/v1/Search/tv/tmdb/${tmdbId}`);
|
|
return response.data || null;
|
|
} catch (error) {
|
|
logToFile(`[OmbiClient] TV search error for TMDB ID ${tmdbId}: ${error.message}`);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test connection to Ombi API
|
|
* @returns {Promise<boolean>} True if connection is successful
|
|
*/
|
|
async testConnection() {
|
|
try {
|
|
const response = await this.axios.get(`${this.url}/api/v1/Request/movie`);
|
|
return response.status === 200;
|
|
} catch (error) {
|
|
logToFile(`[OmbiClient] Connection test failed: ${error.message}`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get all users from Ombi
|
|
* @returns {Promise<Array>} Array of user objects
|
|
*/
|
|
async getUsers() {
|
|
try {
|
|
const response = await this.axios.get(`${this.url}/api/v1/Identity/Users`);
|
|
return response.data || [];
|
|
} catch (error) {
|
|
logToFile(`[OmbiClient] Get users error: ${error.message}`);
|
|
return [];
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = OmbiClient;
|