@8btc/office-assistant-mcp 0.0.7 → 0.0.9
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/dist/index.cjs +36 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -76998,6 +76998,22 @@ const localImageToBase64 = async (imagePath) => {
|
|
|
76998
76998
|
}
|
|
76999
76999
|
return null;
|
|
77000
77000
|
};
|
|
77001
|
+
const extractAllImageSrc = (html2) => {
|
|
77002
|
+
const regex = /<img[^>]*?src=["']([^"']+)["'][^>]*>/gi;
|
|
77003
|
+
const srcs = [];
|
|
77004
|
+
let match;
|
|
77005
|
+
while ((match = regex.exec(html2)) !== null) {
|
|
77006
|
+
if (!match[1].startsWith("data:image/")) {
|
|
77007
|
+
logger.info("extractAllImageSrc match[0]:" + match[0], match[1]);
|
|
77008
|
+
logger.info("extractAllImageSrc match[1]:" + match[1]);
|
|
77009
|
+
}
|
|
77010
|
+
if (isLocalPath(match[1])) {
|
|
77011
|
+
srcs.push(match[1]);
|
|
77012
|
+
}
|
|
77013
|
+
}
|
|
77014
|
+
return srcs;
|
|
77015
|
+
};
|
|
77016
|
+
const reg = /<img[^>]+>/gi;
|
|
77001
77017
|
const createPage = async (page, item) => {
|
|
77002
77018
|
const {
|
|
77003
77019
|
tempFileName,
|
|
@@ -77014,12 +77030,10 @@ const createPage = async (page, item) => {
|
|
|
77014
77030
|
</div>
|
|
77015
77031
|
</header>
|
|
77016
77032
|
`;
|
|
77017
|
-
|
|
77018
|
-
|
|
77019
|
-
|
|
77020
|
-
|
|
77021
|
-
const fileInfoArray = await Promise.all(
|
|
77022
|
-
imgElements.filter((src) => isLocalPath(src)).map(
|
|
77033
|
+
const localSrcs = extractAllImageSrc(html2);
|
|
77034
|
+
logger.info("localSrcs:::" + localSrcs.join(","));
|
|
77035
|
+
const localFileInfoList = await Promise.all(
|
|
77036
|
+
localSrcs.map(
|
|
77023
77037
|
(src) => new Promise((resolve) => {
|
|
77024
77038
|
localImageToBase64(src).then((fileInfo) => {
|
|
77025
77039
|
resolve(fileInfo);
|
|
@@ -77029,20 +77043,19 @@ const createPage = async (page, item) => {
|
|
|
77029
77043
|
})
|
|
77030
77044
|
)
|
|
77031
77045
|
);
|
|
77032
|
-
|
|
77033
|
-
|
|
77034
|
-
|
|
77035
|
-
|
|
77046
|
+
const _html = html2.replaceAll(reg, (m) => {
|
|
77047
|
+
const item2 = localFileInfoList.find(
|
|
77048
|
+
(info) => m.indexOf(info.src) !== -1
|
|
77049
|
+
);
|
|
77050
|
+
if (item2) {
|
|
77051
|
+
return m.replace(
|
|
77052
|
+
/(<img[^>]*?)src=["'][^"']*["']([^>]*>)/gi,
|
|
77053
|
+
`$1src="${item2.base64}"$2`
|
|
77036
77054
|
);
|
|
77037
|
-
|
|
77038
|
-
|
|
77039
|
-
|
|
77040
|
-
|
|
77041
|
-
console.log("base64.length:", imgInfo.base64.length);
|
|
77042
|
-
img.src = imgInfo.base64;
|
|
77043
|
-
}),
|
|
77044
|
-
fileInfoArray
|
|
77045
|
-
);
|
|
77055
|
+
}
|
|
77056
|
+
return m;
|
|
77057
|
+
});
|
|
77058
|
+
await page.setContent(_html, { waitUntil: "networkidle" });
|
|
77046
77059
|
const pageRes = await page.pdf({
|
|
77047
77060
|
path: tempFileName,
|
|
77048
77061
|
format: "A4",
|
|
@@ -77223,6 +77236,10 @@ const tool = {
|
|
|
77223
77236
|
const toolHandler = async (args) => {
|
|
77224
77237
|
try {
|
|
77225
77238
|
logger.info(`start: ${(/* @__PURE__ */ new Date()).getTime()}`);
|
|
77239
|
+
try {
|
|
77240
|
+
logger.info(JSON.stringify(args));
|
|
77241
|
+
} catch (e) {
|
|
77242
|
+
}
|
|
77226
77243
|
const generatedTemplates = await generateBasePdf(args);
|
|
77227
77244
|
const pdfUrl = await generatePDF({
|
|
77228
77245
|
list: generatedTemplates,
|