@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.
Files changed (2) hide show
  1. package/dist/index.cjs +28 -19
  2. 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
- await page.setContent(html2, { waitUntil: "networkidle" });
77018
- const imgElements = await page.evaluate(async () => {
77019
- return Array.from(document.querySelectorAll("img")).map((it) => it.src);
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
- await page.evaluate(
77033
- async (fileInfoArray2) => Array.from(document.querySelectorAll("img")).forEach((img) => {
77034
- const imgInfo = fileInfoArray2.find(
77035
- (it) => it && img.src && it.src === img.src
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
- if (!imgInfo) {
77038
- return;
77039
- }
77040
- console.log("img.src:", img.src);
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",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@8btc/office-assistant-mcp",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "办公agent辅助mcp工具",
5
5
  "main": "dist/index.cjs",
6
6
  "type": "module",