feat: scraper registry + adapter interface

This commit is contained in:
2026-05-25 13:55:07 +00:00
parent 91dea772aa
commit 890fdecf24
3 changed files with 58 additions and 0 deletions

19
src/lib/scrapers/index.ts Normal file
View File

@@ -0,0 +1,19 @@
import { detectShop, type Shop } from '@/lib/shops'
import type { PriceScraper, ScrapeResult } from './types'
const registry = new Map<Shop, PriceScraper>()
export function registerScraper(scraper: PriceScraper) {
registry.set(scraper.shop, scraper)
}
export async function scrapeUrl(url: string): Promise<ScrapeResult> {
const shop = detectShop(url)
if (!shop) throw new Error(`Unsupported URL: ${url}`)
const scraper = registry.get(shop)
if (!scraper) throw new Error(`No scraper registered for shop: ${shop}`)
return scraper.scrape(url)
}
export function registerScraperForTest(s: PriceScraper) { registry.set(s.shop, s) }
export function resetScrapersForTest() { registry.clear() }