refactor: remove mineru_api_base_url from ParserEngineConfig and related components

- Eliminated the `mineru_api_base_url` field from the `ParserEngineConfig` interface and its usage across the application, simplifying the configuration structure.
- Updated the `ParserEngineSettings` view to remove the corresponding input field, enhancing the user interface.
- Adjusted the `PingMinerUCloud` function to no longer require the base URL parameter, defaulting to a predefined value instead.
- Modified database migration comments to reflect the removal of the base URL from the configuration.

These changes streamline the configuration process for the MinerU Cloud integration, improving clarity and reducing potential misconfigurations.
This commit is contained in:
wizardchen
2026-03-03 11:14:33 +08:00
committed by lyingbug
parent 931bd38138
commit 894d2c060a
6 changed files with 18 additions and 49 deletions
@@ -41,8 +41,10 @@ const SimpleEngineName = "simple"
type simpleEngine struct{}
func (e *simpleEngine) Name() string { return SimpleEngineName }
func (e *simpleEngine) Description() string { return "简单格式 & 图片解析(无需外部服务)" }
func (e *simpleEngine) Name() string { return SimpleEngineName }
func (e *simpleEngine) Description() string {
return "简单格式 & 图片解析(无需外部服务)"
}
func (e *simpleEngine) FileTypes(_ bool) []string {
return []string{"md", "markdown", "txt", "csv", "jpg", "jpeg", "png", "gif", "bmp", "tiff", "webp"}
}
@@ -85,7 +87,7 @@ func (e *mineruCloudEngine) CheckAvailable(_ bool, overrides map[string]string)
if apiKey == "" {
return false, "未配置 MinerU API Key"
}
return PingMinerUCloud(apiKey, overrides["mineru_api_base_url"])
return PingMinerUCloud(apiKey)
}
// ---------------------------------------------------------------------------
@@ -29,9 +29,9 @@ const (
// MinerUCloudReader calls the MinerU Cloud API (mineru.net) to read/convert documents.
// Flow: POST /file-urls/batch → PUT file → poll GET /extract-results/batch/{batch_id}.
type MinerUCloudReader struct {
apiKey string
baseURL string
model string
apiKey string
baseURL string
model string
formulaEnable bool
tableEnable bool
ocrEnable bool
@@ -40,14 +40,9 @@ type MinerUCloudReader struct {
// NewMinerUCloudReader creates a reader from ParserEngineOverrides.
func NewMinerUCloudReader(overrides map[string]string) *MinerUCloudReader {
baseURL := strings.TrimRight(stringOr(overrides["mineru_api_base_url"], defaultBaseURL), "/")
if safe, reason := utils.IsSSRFSafeURL(baseURL); !safe {
logger.Printf("WARN: [MinerUCloud] baseURL rejected by SSRF check (%s), falling back to default", reason)
baseURL = defaultBaseURL
}
return &MinerUCloudReader{
apiKey: strings.TrimSpace(overrides["mineru_api_key"]),
baseURL: baseURL,
baseURL: defaultBaseURL,
model: stringOr(overrides["mineru_cloud_model"], "pipeline"),
formulaEnable: parseBoolOr(overrides["mineru_cloud_enable_formula"], true),
tableEnable: parseBoolOr(overrides["mineru_cloud_enable_table"], true),
@@ -481,24 +476,14 @@ func readZipEntryBytes(f *zip.File) ([]byte, error) {
return io.ReadAll(rc)
}
// logCloudResponseStructure is now unified in helpers.go as logResponseStructure("MinerUCloud", ...)
// PingMinerUCloud checks if the MinerU Cloud API is reachable with the given API key.
func PingMinerUCloud(apiKey, baseURL string) (bool, string) {
func PingMinerUCloud(apiKey string) (bool, string) {
apiKey = strings.TrimSpace(apiKey)
baseURL = strings.TrimRight(strings.TrimSpace(baseURL), "/")
if apiKey == "" {
return false, "未配置 MinerU Cloud API Key"
}
if baseURL == "" {
baseURL = defaultBaseURL
}
targetURL := baseURL + "/file-urls/batch"
if safe, reason := utils.IsSSRFSafeURL(targetURL); !safe {
return false, fmt.Sprintf("baseURL 不安全: %s", reason)
}
targetURL := defaultBaseURL + "/file-urls/batch"
payload := []byte(`{"files":[],"model_version":"pipeline"}`)
req, err := http.NewRequest(http.MethodPost, targetURL, bytes.NewReader(payload))
if err != nil {
@@ -522,5 +507,3 @@ func PingMinerUCloud(apiKey, baseURL string) (bool, string) {
}
return true, ""
}
// firstNonEmpty, sleepCtx are defined in helpers.go