@8btc/office-assistant-mcp 0.0.7 → 0.0.8
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 +28 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -76998,6 +76998,18 @@ 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 (isLocalPath(match[1])) {
|
|
77007
|
+
srcs.push(match[1]);
|
|
77008
|
+
}
|
|
77009
|
+
}
|
|
77010
|
+
return srcs;
|
|
77011
|
+
};
|
|
77012
|
+
const reg = /<img[^>]+>/gi;
|
|
77001
77013
|
const createPage = async (page, item) => {
|
|
77002
77014
|
const {
|
|
77003
77015
|
tempFileName,
|
|
@@ -77014,12 +77026,10 @@ const createPage = async (page, item) => {
|
|
|
77014
77026
|
</div>
|
|
77015
77027
|
</header>
|
|
77016
77028
|
`;
|
|
77017
|
-
|
|
77018
|
-
|
|
77019
|
-
|
|
77020
|
-
|
|
77021
|
-
const fileInfoArray = await Promise.all(
|
|
77022
|
-
imgElements.filter((src) => isLocalPath(src)).map(
|
|
77029
|
+
const localSrcs = extractAllImageSrc(html2);
|
|
77030
|
+
logger.info("localSrcs:::" + localSrcs.join(","));
|
|
77031
|
+
const localFileInfoList = await Promise.all(
|
|
77032
|
+
localSrcs.map(
|
|
77023
77033
|
(src) => new Promise((resolve) => {
|
|
77024
77034
|
localImageToBase64(src).then((fileInfo) => {
|
|
77025
77035
|
resolve(fileInfo);
|
|
@@ -77029,20 +77039,19 @@ const createPage = async (page, item) => {
|
|
|
77029
77039
|
})
|
|
77030
77040
|
)
|
|
77031
77041
|
);
|
|
77032
|
-
|
|
77033
|
-
|
|
77034
|
-
|
|
77035
|
-
|
|
77042
|
+
const _html = html2.replaceAll(reg, (m) => {
|
|
77043
|
+
const item2 = localFileInfoList.find(
|
|
77044
|
+
(info) => m.indexOf(info.src) !== -1
|
|
77045
|
+
);
|
|
77046
|
+
if (item2) {
|
|
77047
|
+
return m.replace(
|
|
77048
|
+
/(<img[^>]*?)src=["'][^"']*["']([^>]*>)/gi,
|
|
77049
|
+
`$1src="${item2.base64}"$2`
|
|
77036
77050
|
);
|
|
77037
|
-
|
|
77038
|
-
|
|
77039
|
-
|
|
77040
|
-
|
|
77041
|
-
console.log("base64.length:", imgInfo.base64.length);
|
|
77042
|
-
img.src = imgInfo.base64;
|
|
77043
|
-
}),
|
|
77044
|
-
fileInfoArray
|
|
77045
|
-
);
|
|
77051
|
+
}
|
|
77052
|
+
return m;
|
|
77053
|
+
});
|
|
77054
|
+
await page.setContent(_html, { waitUntil: "networkidle" });
|
|
77046
77055
|
const pageRes = await page.pdf({
|
|
77047
77056
|
path: tempFileName,
|
|
77048
77057
|
format: "A4",
|