openmaic-custom/lib/pdf/constants.ts
wyuc 91c4015732
feat(pdf): add MinerU Cloud API as PDF parsing provider (#438)
* feat(pdf): add MinerU Cloud API as PDF parsing provider

Add MinerU Cloud (v4 API) as a new PDF provider alongside unpdf (built-in)
and MinerU (self-hosted). Users can now parse PDFs via the cloud API without
deploying a self-hosted MinerU instance.

- New provider `mineru-cloud` with API key auth and optional base URL
- Cloud flow: batch create → presigned upload → poll → ZIP download → parse
- Extract shared `mineru-parser.ts` from inline code (used by both paths)
- Settings UI adapted for cloud (API key required) vs self-hosted (base URL required)
- Server-side env var support: PDF_MINERU_CLOUD_API_KEY / PDF_MINERU_CLOUD_BASE_URL
- SSRF protection on cloud verification endpoint
- i18n translations for en-US, zh-CN, ja-JP, ru-RU

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(provider-config): revert PDF activation to requiresBaseUrl

Reverts the PDF section from keylessProviders back to requiresBaseUrl: true
to fix failing test: mineru with only apiKey (no baseUrl) should not activate.
mineru-cloud API key can be configured via browser settings UI instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(pdf-settings): enable test button when API key is server-configured

The test connection button was disabled when the API key was only
configured server-side (not entered by user in browser). Now checks
isServerConfigured in addition to user-entered values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 15:15:55 +08:00

52 lines
1.2 KiB
TypeScript

/**
* PDF Provider Constants
* Separated from pdf-providers.ts to avoid importing sharp in client components
*/
import type { PDFProviderId, PDFProviderConfig } from './types';
export const MINERU_CLOUD_DEFAULT_BASE = 'https://mineru.net/api/v4';
/**
* PDF Provider Registry
*/
export const PDF_PROVIDERS: Record<PDFProviderId, PDFProviderConfig> = {
unpdf: {
id: 'unpdf',
name: 'unpdf',
requiresApiKey: false,
icon: '/logos/unpdf.svg',
features: ['text', 'images', 'metadata'],
},
mineru: {
id: 'mineru',
name: 'MinerU',
requiresApiKey: false,
icon: '/logos/mineru.png',
features: ['text', 'images', 'tables', 'formulas', 'layout-analysis'],
},
'mineru-cloud': {
id: 'mineru-cloud',
name: 'MinerU (Cloud)',
requiresApiKey: true,
icon: '/logos/mineru.png',
features: ['text', 'images', 'tables', 'formulas', 'layout-analysis'],
},
};
/**
* Get all available PDF providers
*/
export function getAllPDFProviders(): PDFProviderConfig[] {
return Object.values(PDF_PROVIDERS);
}
/**
* Get PDF provider by ID
*/
export function getPDFProvider(providerId: PDFProviderId): PDFProviderConfig | undefined {
return PDF_PROVIDERS[providerId];
}