fix: remove mineru built-in api key (#12455)

This commit is contained in:
槑囿脑袋 2026-01-14 16:52:55 +08:00 committed by GitHub
parent a844b5bf39
commit 262d32ac17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 33 additions and 68 deletions

View File

@ -56,8 +56,6 @@ type QuotaResponse = {
export default class MineruPreprocessProvider extends BasePreprocessProvider {
constructor(provider: PreprocessProvider, userId?: string) {
super(provider, userId)
// TODO: remove after free period ends
this.provider.apiKey = this.provider.apiKey || import.meta.env.MAIN_VITE_MINERU_API_KEY
}
public async parseFile(
@ -65,6 +63,10 @@ export default class MineruPreprocessProvider extends BasePreprocessProvider {
file: FileMetadata
): Promise<{ processedFile: FileMetadata; quota: number }> {
try {
if (!this.provider.apiKey) {
throw new Error('MinerU API key is required')
}
const filePath = fileStorage.getFilePathById(file)
logger.info(`MinerU preprocess processing started: ${filePath}`)
await this.validateFile(filePath)
@ -96,6 +98,10 @@ export default class MineruPreprocessProvider extends BasePreprocessProvider {
public async checkQuota() {
try {
if (!this.provider.apiKey) {
throw new Error('MinerU API key is required')
}
const quota = await net.fetch(`${this.provider.apiHost}/api/v4/quota`, {
method: 'GET',
headers: {

View File

@ -57,7 +57,7 @@ export const useKnowledgeBaseForm = (base?: KnowledgeBase) => {
label: t('settings.tool.preprocess.provider'),
title: t('settings.tool.preprocess.provider'),
options: preprocessProviders
.filter((p) => p.apiKey !== '' || ['mineru', 'open-mineru'].includes(p.id))
.filter((p) => p.apiKey !== '' || ['open-mineru'].includes(p.id))
.map((p) => ({ value: p.id, label: p.name }))
}
return [preprocessOptions]

View File

@ -4219,9 +4219,6 @@
"title": "Message Settings",
"use_serif_font": "Use serif font"
},
"mineru": {
"api_key": "Mineru now offers a daily free quota of 500 pages, and you do not need to enter a key."
},
"miniapps": {
"cache_change_notice": "Changes will take effect when the number of open mini apps reaches the set value",
"cache_description": "Set the maximum number of active mini apps to keep in memory",

View File

@ -4219,9 +4219,6 @@
"title": "消息设置",
"use_serif_font": "使用衬线字体"
},
"mineru": {
"api_key": "MinerU现在提供每日500页的免费额度您不需要填写密钥。"
},
"miniapps": {
"cache_change_notice": "更改将在打开的小程序增减至设定值后生效",
"cache_description": "设置同时保持活跃状态的小程序最大数量",

View File

@ -4219,9 +4219,6 @@
"title": "訊息設定",
"use_serif_font": "使用襯線字型"
},
"mineru": {
"api_key": "Mineru 現在每天提供 500 頁的免費配額,且無需輸入金鑰。"
},
"miniapps": {
"cache_change_notice": "變更會在開啟的小程式數量調整至設定值後生效",
"cache_description": "設定同時保持活躍狀態的小程式最大數量",

View File

@ -4219,9 +4219,6 @@
"title": "Nachrichteneinstellungen",
"use_serif_font": "Serifenschrift verwenden"
},
"mineru": {
"api_key": "MinerU bietet täglich 500 Seiten kostenlos an, Sie müssen keinen Schlüssel eingeben."
},
"miniapps": {
"cache_change_notice": "Änderung wird wirksam wenn Anzahl geöffneter Mini-Apps auf festgelegten Wert angepasst wird",
"cache_description": "Maximale Anzahl gleichzeitig aktiver Mini-Apps festlegen",

View File

@ -4219,9 +4219,6 @@
"title": "Ρυθμίσεις μηνυμάτων",
"use_serif_font": "Χρήση μορφής Serif"
},
"mineru": {
"api_key": "Το MinerU παρέχει δωρεάν χρήση 500 σελίδων ημερησίως, δεν χρειάζεται να συμπληρώσετε κλειδί."
},
"miniapps": {
"cache_change_notice": "Η αλλαγή θα τεθεί σε ισχύ αφού το πλήθος των ανοιχτών μικροπρογραμμάτων φτάσει τη ρυθμισμένη τιμή",
"cache_description": "Ορίστε τον μέγιστο αριθμό των μικροπρογραμμάτων που μπορούν να είναι ενεργά ταυτόχρονα",

View File

@ -4219,9 +4219,6 @@
"title": "Configuración de mensajes",
"use_serif_font": "Usar fuente serif"
},
"mineru": {
"api_key": "MinerU ahora ofrece un cupo gratuito de 500 páginas diarias, no es necesario que ingrese una clave."
},
"miniapps": {
"cache_change_notice": "Los cambios surtirán efecto cuando el número de miniaplicaciones abiertas aumente o disminuya hasta alcanzar el valor configurado",
"cache_description": "Establece el número máximo de miniaplicaciones que pueden permanecer activas simultáneamente",

View File

@ -4219,9 +4219,6 @@
"title": "Paramètres des messages",
"use_serif_font": "Utiliser une police serif"
},
"mineru": {
"api_key": "MinerU propose désormais un quota gratuit de 500 pages par jour, vous n'avez donc pas besoin de saisir de clé."
},
"miniapps": {
"cache_change_notice": "Les modifications prendront effet après l'ajout ou la suppression d'applications ouvertes jusqu'à atteindre la valeur définie",
"cache_description": "Définir le nombre maximum d'applications pouvant rester actives simultanément",

View File

@ -4219,9 +4219,6 @@
"title": "メッセージ設定",
"use_serif_font": "セリフフォントを使用"
},
"mineru": {
"api_key": "Mineruでは現在、1日500ページの無料クォータを提供しており、キーを入力する必要はありません。"
},
"miniapps": {
"cache_change_notice": "設定値に達するまでミニアプリの開閉が行われた後に変更が適用されます",
"cache_description": "メモリに保持するアクティブなミニアプリの最大数を設定します",

View File

@ -4219,9 +4219,6 @@
"title": "Configurações de mensagem",
"use_serif_font": "Usar fonte serif"
},
"mineru": {
"api_key": "O MinerU agora oferece uma cota diária gratuita de 500 páginas; você não precisa preencher uma chave."
},
"miniapps": {
"cache_change_notice": "As alterações entrarão em vigor após a abertura ou remoção dos mini aplicativos até atingir o número definido",
"cache_description": "Defina o número máximo de mini aplicativos que permanecerão ativos simultaneamente",

View File

@ -4219,9 +4219,6 @@
"title": "Setări mesaje",
"use_serif_font": "Folosește font serif"
},
"mineru": {
"api_key": "Mineru oferă acum o cotă zilnică gratuită de 500 de pagini și nu este nevoie să introduci o cheie."
},
"miniapps": {
"cache_change_notice": "Modificările vor intra în vigoare când numărul de mini-aplicații deschise atinge valoarea setată",
"cache_description": "Setează numărul maxim de mini-aplicații active de păstrat în memorie",

View File

@ -4219,9 +4219,6 @@
"title": "Настройки сообщений",
"use_serif_font": "Использовать serif шрифт"
},
"mineru": {
"api_key": "Mineru теперь предлагает ежедневную бесплатную квоту в 500 страниц, и вам не нужно вводить ключ."
},
"miniapps": {
"cache_change_notice": "Изменения вступят в силу, когда количество открытых мини-приложений достигнет установленного значения",
"cache_description": "Установить максимальное количество активных мини-приложений в памяти",

View File

@ -10,8 +10,6 @@ import { useTranslation } from 'react-i18next'
const logger = loggerService.withContext('QuotaTag')
const QUOTA_UNLIMITED = -9999
const QuotaTag: FC<{ base: KnowledgeBase; providerId: PreprocessProviderId; quota?: number }> = ({
base,
providerId,
@ -23,44 +21,40 @@ const QuotaTag: FC<{ base: KnowledgeBase; providerId: PreprocessProviderId; quot
useEffect(() => {
const checkQuota = async () => {
if (provider.id !== 'mineru') return
// 使用用户的key时quota为无限
if (provider.apiKey) {
setQuota(QUOTA_UNLIMITED)
updateProvider({ quota: QUOTA_UNLIMITED })
return
const userId = getStoreSetting('userId')
const baseParams = getKnowledgeBaseParams(base)
try {
const response = await window.api.knowledgeBase.checkQuota({
base: baseParams,
userId: userId as string
})
setQuota(response)
updateProvider({ quota: response })
} catch (error) {
logger.error('[KnowledgeContent] Error checking quota:', error as Error)
}
if (quota === undefined) {
const userId = getStoreSetting('userId')
const baseParams = getKnowledgeBaseParams(base)
try {
const response = await window.api.knowledgeBase.checkQuota({
base: baseParams,
userId: userId as string
})
setQuota(response)
} catch (error) {
logger.error('[KnowledgeContent] Error checking quota:', error as Error)
}
}
if (provider.id !== 'mineru') return
if (!provider.apiKey) {
if (quota !== undefined) {
setQuota(undefined)
updateProvider({ quota: undefined })
}
return
}
if (_quota !== undefined) {
setQuota(_quota)
updateProvider({ quota: _quota })
return
}
checkQuota()
}, [_quota, base, provider.id, provider.apiKey, provider, quota, updateProvider])
if (quota === undefined) {
checkQuota()
}
}, [_quota, base, provider.id, provider.apiKey, quota, updateProvider])
const getQuotaDisplay = () => {
if (quota === undefined) return null
if (quota === QUOTA_UNLIMITED) {
return (
<Tag color="orange" style={{ borderRadius: 20, margin: 0 }}>
{t('knowledge.quota_infinity', { name: provider.name })}
</Tag>
)
}
if (quota === 0) {
return (
<Tag color="red" style={{ borderRadius: 20, margin: 0 }}>

View File

@ -99,9 +99,7 @@ const PreprocessProviderSettings: FC<Props> = ({ provider: _provider }) => {
<Flex gap={8}>
<Input.Password
value={apiKey}
placeholder={
preprocessProvider.id === 'mineru' ? t('settings.mineru.api_key') : t('settings.provider.api_key.label')
}
placeholder={t('settings.provider.api_key.label')}
onChange={(e) => setApiKey(formatApiKeys(e.target.value))}
onBlur={onUpdateApiKey}
spellCheck={false}