smart-image-scraper-mcp 2.12.0 → 2.12.2

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-image-scraper-mcp",
3
- "version": "2.12.0",
3
+ "version": "2.12.2",
4
4
  "description": "全网智能图片抓取 MCP 服务器 - 支持 Bing/Google 图片搜索、验证和下载",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -224,13 +224,11 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
224
224
  })
225
225
  ]);
226
226
  clearTimeout(mcpTimeoutId);
227
+ orchestrator.cleanup();
227
228
  return result;
228
229
  } catch (error) {
229
230
  clearTimeout(mcpTimeoutId);
230
- // 确保中止所有操作
231
- if (orchestrator.abortController && !orchestrator.abortController.signal.aborted) {
232
- orchestrator.abortController.abort();
233
- }
231
+ orchestrator.cleanup();
234
232
  console.error(`[MCP Error] ${error.message}`);
235
233
  return {
236
234
  content: [{
@@ -13,14 +13,14 @@ import logger from './logger.js';
13
13
  // MCP 每次调用独立,keepalive 复用收益小,反而导致连接池堵塞
14
14
  const httpAgent = new http.Agent({
15
15
  keepAlive: false, // 禁用 Keep-Alive,用完立即释放
16
- maxSockets: 15, // 最大并发连接数
16
+ maxSockets: Infinity, // 不限制并发(keepAlive=false 时每个 socket 短命)
17
17
  maxFreeSockets: 0, // 不保留空闲连接
18
18
  scheduling: 'fifo', // 先进先出,公平分配
19
19
  });
20
20
 
21
21
  const httpsAgent = new https.Agent({
22
22
  keepAlive: false, // 禁用 Keep-Alive
23
- maxSockets: 15,
23
+ maxSockets: Infinity, // 不限制并发
24
24
  maxFreeSockets: 0,
25
25
  scheduling: 'fifo',
26
26
  rejectUnauthorized: false, // 允许自签名证书
@@ -11,53 +11,18 @@ import config from '../config/index.js';
11
11
  // 使用配置中的并发数,避免硬编码与配置不一致
12
12
  const globalValidateLimit = pLimit(config.MAX_VALIDATE_CONCURRENCY);
13
13
 
14
- // 已知有防盗链保护的域名列表
15
- // 这些域名的图片在浏览器直接打开会返回 403 或替换图
14
+ // 已知有严格防盗链保护的域名列表(仅包含确实无法在浏览器直接打开的)
15
+ // 这些域名的图片在浏览器地址栏直接打开会返回 403、替换图或空白
16
16
  const HOTLINK_PROTECTED_DOMAINS = [
17
- 'pic.huitu.com',
18
- 'img.shetu66.com',
19
- 'pic.nximg.cn',
20
- 'gd-hbimg.huaban.com',
21
- 'hbimg.huaban.com',
22
- 'img.zcool.cn',
23
- 'img.zcool.com',
24
- 'pic1.zhimg.com',
25
- 'pic2.zhimg.com',
26
- 'pic3.zhimg.com',
27
- 'pic4.zhimg.com',
28
- 'picx.zhimg.com',
29
- 'img.alicdn.com',
30
- 'img.taobao.com',
31
- 'gw.alicdn.com',
32
- 'cbu01.alicdn.com',
33
- 'img.pconline.com.cn',
34
- 'img.zol-img.com.cn',
35
- 'p0.meituan.net',
36
- 'p1.meituan.net',
37
- 'img.doubanio.com',
38
- 'img1.doubanio.com',
39
- 'img2.doubanio.com',
40
- 'img3.doubanio.com',
41
- 'img9.doubanio.com',
42
- 'ww1.sinaimg.cn',
43
- 'ww2.sinaimg.cn',
44
- 'ww3.sinaimg.cn',
45
- 'ww4.sinaimg.cn',
46
- 'wx1.sinaimg.cn',
47
- 'wx2.sinaimg.cn',
48
- 'wx3.sinaimg.cn',
49
- 'wx4.sinaimg.cn',
50
- 'tvax1.sinaimg.cn',
51
- 'tvax2.sinaimg.cn',
52
- 'tvax3.sinaimg.cn',
53
- 'tvax4.sinaimg.cn',
54
- 'tva1.sinaimg.cn',
55
- 'tva2.sinaimg.cn',
56
- 'tva3.sinaimg.cn',
57
- 'tva4.sinaimg.cn',
58
- 'cdn.pixabay.com',
59
- 'images.unsplash.com',
60
- 'img.freepik.com',
17
+ 'sinaimg.cn', // 新浪微博图片,严格 Referer 检查
18
+ 'doubanio.com', // 豆瓣图片,严格防盗链
19
+ 'meituan.net', // 美团图片
20
+ 'alicdn.com', // 阿里 CDN(淘宝/天猫图片)
21
+ 'taobao.com', // 淘宝图片
22
+ 'img.zcool.cn', // 站酷图片
23
+ 'img.zcool.com', // 站酷图片
24
+ 'cdn.pixabay.com', // Pixabay 防盗链
25
+ 'img.freepik.com', // Freepik 防盗链
61
26
  ];
62
27
 
63
28
  export class LinkValidator {
@@ -35,6 +35,21 @@ export class Orchestrator {
35
35
  this.abortController = null; // 用于取消正在进行的操作
36
36
  }
37
37
 
38
+ /**
39
+ * 清理资源,防止内存泄漏
40
+ */
41
+ cleanup() {
42
+ if (this.abortController) {
43
+ if (!this.abortController.signal.aborted) {
44
+ this.abortController.abort();
45
+ }
46
+ this.abortController = null;
47
+ }
48
+ this.linkValidator = null;
49
+ this.fileManager = null;
50
+ this.imageProcessor = null;
51
+ }
52
+
38
53
  /**
39
54
  * 解析关键词字符串
40
55
  * @param {string} query - 关键词字符串(逗号分隔)