← back to Ventura Claw

server/connectors/met.js

45 lines

// Metropolitan Museum of Art — open access collection.
// No API key. https://metmuseum.github.io/
const BASE = "https://collectionapi.metmuseum.org/public/collection/v1";
async function call(path) {
  const r = await fetch(`${BASE}${path}`, {
    headers: { "User-Agent": "VenturaClaw/1.0 (steve@venturaclaw.com)", Accept: "application/json" },
    signal: AbortSignal.timeout(15_000),
  });
  if (!r.ok) throw new Error(`met ${r.status}`);
  return r.json();
}
module.exports = {
  meta: { id: "met", name: "MET Museum", category: "data", docsUrl: "https://metmuseum.github.io/", auth: "none", realImpl: true },
  fields: [],
  configured() { return true; },
  async health() {
    try {
      const d = await call("/objects?metadataDate=2026-01-01");
      return { ok: true, label: `${(d.total ?? 0).toLocaleString()} objects · public domain catalog` };
    } catch (e) { return { ok: false, reason: e.message }; }
  },
  actions: {
    async "search"({ q, hasImages, isPublicDomain, departmentId }) {
      if (!q) throw new Error("q required");
      const qs = new URLSearchParams({ q });
      if (hasImages) qs.set("hasImages", "true");
      if (isPublicDomain) qs.set("isPublicDomain", "true");
      if (departmentId) qs.set("departmentId", String(departmentId));
      const d = await call(`/search?${qs}`);
      return { total: d.total, objectIDs: (d.objectIDs || []).slice(0, 100) };
    },
    async "object"({ objectID }) {
      if (!objectID) throw new Error("objectID required");
      const d = await call(`/objects/${objectID}`);
      return {
        objectID: d.objectID, title: d.title, artist: d.artistDisplayName, date: d.objectDate,
        medium: d.medium, classification: d.classification, department: d.department,
        isPublicDomain: d.isPublicDomain, primaryImage: d.primaryImage, primaryImageSmall: d.primaryImageSmall,
        objectURL: d.objectURL, creditLine: d.creditLine, dimensions: d.dimensions,
      };
    },
    async "departments"() { return await call("/departments"); },
  },
};