@dyno181cm.nexsoft/zentao_mcp 1.2.10 → 1.2.12

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.
Files changed (2) hide show
  1. package/build/tools.js +31 -5
  2. package/package.json +1 -1
package/build/tools.js CHANGED
@@ -42,10 +42,33 @@ function formatUser(user) {
42
42
  }
43
43
  return String(user);
44
44
  }
45
+ /** Convert a local absolute path to a valid file:// URL. */
46
+ function toFileUrl(filePath) {
47
+ const normalized = filePath.replace(/\\/g, '/');
48
+ if (/^[a-zA-Z]:\//.test(normalized)) {
49
+ return `file:///${normalized}`;
50
+ }
51
+ if (normalized.startsWith('/')) {
52
+ return `file://${normalized}`;
53
+ }
54
+ return `file:///${normalized}`;
55
+ }
56
+ /** Convert a local file to a Base64 data URI for safe rendering in browser/chat UI. */
57
+ function fileToBase64(filePath) {
58
+ try {
59
+ const data = fs.readFileSync(filePath);
60
+ const ext = path.extname(filePath).toLowerCase().replace('.', '');
61
+ const mime = ext === 'svg' ? 'image/svg+xml' : `image/${ext || 'png'}`;
62
+ return `data:${mime};base64,${data.toString('base64')}`;
63
+ }
64
+ catch {
65
+ return toFileUrl(filePath); // fallback to file URL if read fails
66
+ }
67
+ }
45
68
  /**
46
69
  * Find all <img src="..."> URLs in an HTML string, download each image
47
70
  * to the local tmp directory using the authenticated ZenTao client,
48
- * and replace the remote src with the local file path.
71
+ * and replace the remote src with the local Base64 data URI.
49
72
  * Images already cached on disk are not re-downloaded.
50
73
  */
51
74
  async function localizeImages(html) {
@@ -65,7 +88,7 @@ async function localizeImages(html) {
65
88
  if (!fs.existsSync(localPath)) {
66
89
  await client.downloadImageToLocal(remoteUrl, localPath);
67
90
  }
68
- result = result.split(remoteUrl).join(localPath);
91
+ result = result.split(remoteUrl).join(fileToBase64(localPath));
69
92
  }
70
93
  catch {
71
94
  // If download fails, keep the original remote URL
@@ -121,9 +144,12 @@ async function renderAttachments(files) {
121
144
  const lines = enriched.map((f) => {
122
145
  if (!f.localPath)
123
146
  return `- 📎 ${f.title} — *(download failed, Size: ${formatSize(f.size)})*`;
124
- if (IMAGE_EXTS.has(f.ext))
125
- return `- 📎 ![${f.title}](${f.localPath}) *(Size: ${formatSize(f.size)})*`;
126
- return `- 📎 [${f.title}](${f.localPath}) *(Size: ${formatSize(f.size)})*`;
147
+ if (IMAGE_EXTS.has(f.ext)) {
148
+ const base64 = fileToBase64(f.localPath);
149
+ return `- 📎 ![${f.title}](${base64}) *(Size: ${formatSize(f.size)})*`;
150
+ }
151
+ const fileUrl = toFileUrl(f.localPath);
152
+ return `- 📎 [${f.title}](${fileUrl}) *(Size: ${formatSize(f.size)})*`;
127
153
  });
128
154
  return `\n## Files 📎${headerHint}\n${lines.join('\n')}\n`;
129
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyno181cm.nexsoft/zentao_mcp",
3
- "version": "1.2.10",
3
+ "version": "1.2.12",
4
4
  "description": "Zentao MCP Server",
5
5
  "repository": {
6
6
  "type": "git",