/** * Copyright 2026 aphrody-code * SPDX-License-Identifier: Apache-2.0 */ import { AssetSearch, type AssetKind } from "../assets/index.ts"; import { EXIT, type CommonOptions, logger } from "./shared.ts"; function usage(): void { Bun.stdout.write(`bxc assets — attributed image and GIF provider search Usage: bxc assets search [--type image|gif] [--provider ] [--limit ] bxc assets providers [--type image|gif] Providers: wikimedia-commons Attributed images from the public Commons API google-images Images and GIF discovery through the stored Google session giphy GIF search (GIPHY_API_KEY) Tenor was retired by Google on 2026-06-30 and is not advertised at runtime. Results are references with provenance; BXC does not download or republish them. `); } export async function main( argv: readonly string[], common: CommonOptions, ): Promise { const action = argv[0]; if (!action || action === "--help" || action === "-h") { usage(); return; } let kind: AssetKind = "image"; let limit = 10; let offset = 0; const providers: string[] = []; const query: string[] = []; for (let index = 1; index < argv.length; index++) { const arg = argv[index]; if (arg === "--type") kind = argv[++index] as AssetKind; else if (arg === "--provider") providers.push(argv[++index] ?? ""); else if (arg === "--limit") limit = Number(argv[++index]); else if (arg === "--offset") offset = Number(argv[++index]); else if (!arg.startsWith("-")) query.push(arg); } if (kind !== "image" && kind !== "gif") { logger.error("--type must be image or gif"); process.exit(EXIT.MISUSE); } const engine = new AssetSearch(); if (action === "providers") { const available = engine.available(kind); Bun.stdout.write( common.json ? `${JSON.stringify({ kind, providers: available })}\n` : `${available.join("\n")}\n`, ); return; } if (action !== "search" || query.length === 0) { usage(); process.exit(EXIT.MISUSE); } const response = await engine.search(query.join(" "), { kind, limit, offset, providers: providers.filter(Boolean), }); if (common.json) { Bun.stdout.write(`${JSON.stringify(response, null, 2)}\n`); return; } logger.log( `cache=${response.cache} nextOffset=${response.nextOffset ?? "none"}`, common, ); for (const result of response.results) { logger.log( `[${result.provider}] ${result.title}\n${result.url}\n${result.attribution}`, common, ); } }