smart-image-scraper-mcp 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -8,9 +8,12 @@ import httpClient from '../infrastructure/httpClient.js';
|
|
|
8
8
|
import logger from '../infrastructure/logger.js';
|
|
9
9
|
import config from '../config/index.js';
|
|
10
10
|
|
|
11
|
+
// 全局共享的并发限制器,避免多个请求同时发起导致资源竞争
|
|
12
|
+
const globalValidateLimit = pLimit(config.MAX_VALIDATE_CONCURRENCY);
|
|
13
|
+
|
|
11
14
|
export class LinkValidator {
|
|
12
15
|
constructor() {
|
|
13
|
-
this.limit =
|
|
16
|
+
this.limit = globalValidateLimit;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
/**
|
|
@@ -11,12 +11,17 @@ import { ImageProcessor } from './imageProcessor.js';
|
|
|
11
11
|
import logger from '../infrastructure/logger.js';
|
|
12
12
|
import config from '../config/index.js';
|
|
13
13
|
|
|
14
|
+
// 全局共享的并发限制器,避免多个 MCP 请求同时发起导致资源竞争
|
|
15
|
+
const globalKeywordLimit = pLimit(config.MAX_KEYWORD_CONCURRENCY);
|
|
16
|
+
const globalRequestLimit = pLimit(2); // 限制同时处理的 MCP 请求数
|
|
17
|
+
|
|
14
18
|
export class Orchestrator {
|
|
15
19
|
constructor() {
|
|
16
20
|
this.linkValidator = new LinkValidator();
|
|
17
21
|
this.fileManager = new FileManager();
|
|
18
22
|
this.imageProcessor = new ImageProcessor();
|
|
19
|
-
this.keywordLimit =
|
|
23
|
+
this.keywordLimit = globalKeywordLimit;
|
|
24
|
+
this.requestLimit = globalRequestLimit;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
/**
|
|
@@ -207,6 +212,14 @@ export class Orchestrator {
|
|
|
207
212
|
* @returns {Promise<Object>} - 执行结果
|
|
208
213
|
*/
|
|
209
214
|
async execute(params) {
|
|
215
|
+
// 使用全局请求限制器,避免多个 MCP 请求同时执行
|
|
216
|
+
return this.requestLimit(() => this._executeInternal(params));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 内部执行逻辑
|
|
221
|
+
*/
|
|
222
|
+
async _executeInternal(params) {
|
|
210
223
|
const { query, mode, count = config.DEFAULT_COUNT, source = config.DEFAULT_SOURCE, size = 'all', safeSearch = 'moderate', aspect = 'all', targetSize = null, fit = 'cover', position = 'center' } = params;
|
|
211
224
|
const options = { size, safeSearch, aspect, targetSize, fit, position };
|
|
212
225
|
|