@dyno181cm.nexsoft/zentao_mcp 1.2.11 → 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.
- package/build/tools.js +18 -4
- package/package.json +1 -1
package/build/tools.js
CHANGED
|
@@ -53,10 +53,22 @@ function toFileUrl(filePath) {
|
|
|
53
53
|
}
|
|
54
54
|
return `file:///${normalized}`;
|
|
55
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
|
+
}
|
|
56
68
|
/**
|
|
57
69
|
* Find all <img src="..."> URLs in an HTML string, download each image
|
|
58
70
|
* to the local tmp directory using the authenticated ZenTao client,
|
|
59
|
-
* and replace the remote src with the local
|
|
71
|
+
* and replace the remote src with the local Base64 data URI.
|
|
60
72
|
* Images already cached on disk are not re-downloaded.
|
|
61
73
|
*/
|
|
62
74
|
async function localizeImages(html) {
|
|
@@ -76,7 +88,7 @@ async function localizeImages(html) {
|
|
|
76
88
|
if (!fs.existsSync(localPath)) {
|
|
77
89
|
await client.downloadImageToLocal(remoteUrl, localPath);
|
|
78
90
|
}
|
|
79
|
-
result = result.split(remoteUrl).join(
|
|
91
|
+
result = result.split(remoteUrl).join(fileToBase64(localPath));
|
|
80
92
|
}
|
|
81
93
|
catch {
|
|
82
94
|
// If download fails, keep the original remote URL
|
|
@@ -132,9 +144,11 @@ async function renderAttachments(files) {
|
|
|
132
144
|
const lines = enriched.map((f) => {
|
|
133
145
|
if (!f.localPath)
|
|
134
146
|
return `- 📎 ${f.title} — *(download failed, Size: ${formatSize(f.size)})*`;
|
|
147
|
+
if (IMAGE_EXTS.has(f.ext)) {
|
|
148
|
+
const base64 = fileToBase64(f.localPath);
|
|
149
|
+
return `- 📎  *(Size: ${formatSize(f.size)})*`;
|
|
150
|
+
}
|
|
135
151
|
const fileUrl = toFileUrl(f.localPath);
|
|
136
|
-
if (IMAGE_EXTS.has(f.ext))
|
|
137
|
-
return `- 📎  *(Size: ${formatSize(f.size)})*`;
|
|
138
152
|
return `- 📎 [${f.title}](${fileUrl}) *(Size: ${formatSize(f.size)})*`;
|
|
139
153
|
});
|
|
140
154
|
return `\n## Files 📎${headerHint}\n${lines.join('\n')}\n`;
|