import type { ConnectorMeta, CrawlContext } from '@rareindex/connectors'; import type { ExtractionResult } from '@rareindex/shared'; import { parseDrouotCatalogue, parseDrouotIndex } from '../_g8-auctions-eu-apac-lib/drouot-platform.js'; import { SaleResultsConnector, type HouseConfig, type ParsedSalePage, type SaleRef } from '../_g8-auctions-eu-apac-lib/sale-results.js'; /** * Ader (Paris, Hôtel Drouot) — Drouot "site générique" platform. Past sales per year at /ventes-passees?year=YYYY, * lots at /catalogue/?offset=N&max=50 with "Résultat : 1 081 EUR" and the page note "Résultats avec frais" * (premium-inclusive) read per page. */ const BASE = 'https://www.ader-paris.fr'; const HOUSE = { base: BASE, currency: 'EUR' as const }; const PAGE = 50; export class AderConnector extends SaleResultsConnector { readonly version = '1.0.0'; readonly house: HouseConfig = { houseName: 'Ader', defaultCurrency: 'EUR', location: 'Paris, France', idKey: 'ader_lot', premiumIncluded: null, fallbackSlug: 'antiques', minIntervalMs: 2500, maxPagesPerSale: 30 }; protected override minIntervalMs = 2500; async listSales(ctx: CrawlContext): Promise { const years = (this.meta.config.years as number[] | undefined) ?? [new Date().getUTCFullYear()]; const all: SaleRef[] = []; for (const y of ctx.options.mode === 'backfill' ? backfillYears(this.meta.config.backfillFromYear) : years) { const url = `${BASE}/ventes-passees?year=${y}`; await this.throttle(url); const res = await ctx.fetch(url, { engines: ['api'], responseType: 'text', minQuality: 0, timeoutMs: 60_000 }); if (!res.success || !res.html) { ctx.anomaly('past_list_failed', `${url}: ${res.error ?? res.httpStatus}`); continue; } all.push(...parseDrouotIndex(res.html, HOUSE)); } return all; } salePageUrl(sale: SaleRef, page: number): string { return page > 1 ? `${sale.url.replace(/\/catalogue\/(\d+)[^?]*/, '/catalogue/$1')}?lang=fr&search=&offset=${(page - 1) * PAGE}&max=${PAGE}` : sale.url; } parseSalePage(res: ExtractionResult, sale: SaleRef): ParsedSalePage | null { return res.html ? parseDrouotCatalogue(res.html, sale, HOUSE, PAGE) : null; } } export function backfillYears(from: unknown): number[] { const start = Number(from ?? 2004); const now = new Date().getUTCFullYear(); const out: number[] = []; for (let y = start; y <= now; y++) out.push(y); return out; } export default function createConnector(meta: ConnectorMeta) { return new AderConnector(meta); }