src / image_search / providers / BaseImageProvider.ts
import { HTTPClient } from "../../http/HTTPClient";
import { ISyncableProviderInstance } from "../../providers/ISyncableProviderInstance";
import { defaultProviderInstanceRegistry } from "../../providers/ProviderInstanceRegistry";
import { SearchOptions } from "../../types/search";
import { ImageSearchResult } from "../models";
export interface BaseImageProviderOptions {
providerName: string;
httpClient?: HTTPClient;
httpTimeoutSeconds?: number;
}
/**
* Abstract base class for image search providers.
* Manages provider name identification, HTTP operations via HTTPClient,
* and standardized response normalization into generic ImageSearchResult objects.
* Mapped from Python `image_search/providers/base_image_provider.py` BaseImageProvider.
*/
export abstract class BaseImageProvider implements ISyncableProviderInstance {
public readonly category: string = "image";
protected readonly _providerName: string;
protected readonly _httpClient: HTTPClient;
constructor(options: BaseImageProviderOptions) {
if (!options.providerName || !options.providerName.trim()) {
throw new Error("Image provider name cannot be empty.");
}
this._providerName = options.providerName.toLowerCase().trim();
this._httpClient =
options.httpClient ??
new HTTPClient({
timeoutSeconds: options.httpTimeoutSeconds ?? 30.0,
});
// Auto-register this image provider instance with global ProviderInstanceRegistry
defaultProviderInstanceRegistry.register(this);
}
public get configIdentity(): string {
return `${this.category}.${this._providerName}`;
}
public get providerName(): string {
return this._providerName;
}
public setKeys(_keys: string[]): void {
// Default no-op for providers that do not use API keys (e.g. DuckDuckGo).
// Overridden by subclasses with KeyManager.
}
public abstract searchImages(
query: string,
options?: SearchOptions
): Promise<ImageSearchResult[]>;
}
src / image_search / providers / BaseImageProvider.ts
import { HTTPClient } from "../../http/HTTPClient";
import { ISyncableProviderInstance } from "../../providers/ISyncableProviderInstance";
import { defaultProviderInstanceRegistry } from "../../providers/ProviderInstanceRegistry";
import { SearchOptions } from "../../types/search";
import { ImageSearchResult } from "../models";
export interface BaseImageProviderOptions {
providerName: string;
httpClient?: HTTPClient;
httpTimeoutSeconds?: number;
}
/**
* Abstract base class for image search providers.
* Manages provider name identification, HTTP operations via HTTPClient,
* and standardized response normalization into generic ImageSearchResult objects.
* Mapped from Python `image_search/providers/base_image_provider.py` BaseImageProvider.
*/
export abstract class BaseImageProvider implements ISyncableProviderInstance {
public readonly category: string = "image";
protected readonly _providerName: string;
protected readonly _httpClient: HTTPClient;
constructor(options: BaseImageProviderOptions) {
if (!options.providerName || !options.providerName.trim()) {
throw new Error("Image provider name cannot be empty.");
}
this._providerName = options.providerName.toLowerCase().trim();
this._httpClient =
options.httpClient ??
new HTTPClient({
timeoutSeconds: options.httpTimeoutSeconds ?? 30.0,
});
// Auto-register this image provider instance with global ProviderInstanceRegistry
defaultProviderInstanceRegistry.register(this);
}
public get configIdentity(): string {
return `${this.category}.${this._providerName}`;
}
public get providerName(): string {
return this._providerName;
}
public setKeys(_keys: string[]): void {
// Default no-op for providers that do not use API keys (e.g. DuckDuckGo).
// Overridden by subclasses with KeyManager.
}
public abstract searchImages(
query: string,
options?: SearchOptions
): Promise<ImageSearchResult[]>;
}