@wenyan-md/core 3.0.4 → 3.0.5

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/core.js CHANGED
@@ -524,9 +524,9 @@ function createMathJaxParser(options = {}) {
524
524
  fontCache: options.fontCache ?? "none"
525
525
  });
526
526
  function addContainer(math, doc) {
527
+ const container = math.typesetRoot;
527
528
  const tag = math.display ? "section" : "span";
528
529
  const cls = math.display ? "block-equation" : "inline-equation";
529
- const container = math.typesetRoot;
530
530
  if (math.math) {
531
531
  doc.adaptor.setAttribute(container, "math", math.math);
532
532
  }
package/dist/publish.js CHANGED
@@ -185,12 +185,13 @@ class WechatPublisher {
185
185
  await this.tokenStore.setToken(appId, result.access_token, result.expires_in);
186
186
  return result.access_token;
187
187
  }
188
- async uploadImage(file, filename, accessToken) {
188
+ async uploadImage(file, filename, accessToken, appId) {
189
189
  let hash;
190
190
  if (this.uploadCacheStore) {
191
191
  const arrayBuffer = await file.arrayBuffer();
192
192
  hash = await this.uploadCacheStore.calcHash(arrayBuffer);
193
- const cached = await this.uploadCacheStore.get(hash);
193
+ const cacheKey = appId ? `${hash}:${appId}` : hash;
194
+ const cached = await this.uploadCacheStore.get(cacheKey);
194
195
  if (cached) {
195
196
  return {
196
197
  media_id: cached.media_id,
@@ -200,7 +201,8 @@ class WechatPublisher {
200
201
  }
201
202
  const data = await this.uploadMaterial("image", file, filename, accessToken);
202
203
  if (this.uploadCacheStore && hash) {
203
- await this.uploadCacheStore.set(hash, data.media_id, data.url);
204
+ const cacheKey = appId ? `${hash}:${appId}` : hash;
205
+ await this.uploadCacheStore.set(cacheKey, data.media_id, data.url);
204
206
  }
205
207
  return data;
206
208
  }
@@ -17,7 +17,7 @@ export declare class WechatPublisher {
17
17
  private fetchAccessToken;
18
18
  constructor(httpAdapter: HttpAdapter, tokenStoreAdapter?: TokenStorageAdapter, uploadCacheStoreAdapter?: UploadCacheStorageAdapter);
19
19
  getAccessTokenWithCache(appId: string, appSecret: string): Promise<string>;
20
- uploadImage(file: Blob, filename: string, accessToken: string): Promise<WechatUploadResponse>;
20
+ uploadImage(file: Blob, filename: string, accessToken: string, appId?: string): Promise<WechatUploadResponse>;
21
21
  publishToDraft(accessToken: string, options: WechatPublishOptions): Promise<WechatPublishResponse>;
22
22
  clearCache(): Promise<void>;
23
23
  }
package/dist/wrapper.js CHANGED
@@ -404,7 +404,7 @@ const wechatPublisher = new WechatPublisher(
404
404
  new NodeUploadCacheAdapter()
405
405
  );
406
406
  const credentialStore = new CredentialStore(new NodeCredentialStorageAdapter());
407
- async function uploadImage(imageUrl, accessToken, fileName, relativePath) {
407
+ async function uploadImage(imageUrl, accessToken, fileName, relativePath, appId) {
408
408
  let fileData;
409
409
  let finalName;
410
410
  if (imageUrl.startsWith("http")) {
@@ -433,11 +433,11 @@ async function uploadImage(imageUrl, accessToken, fileName, relativePath) {
433
433
  const fileFromPathResult = await fileFromPath(resolvedPath);
434
434
  fileData = new Blob([await fileFromPathResult.arrayBuffer()], { type: fileFromPathResult.type });
435
435
  }
436
- const data = await wechatPublisher.uploadImage(fileData, finalName, accessToken);
436
+ const data = await wechatPublisher.uploadImage(fileData, finalName, accessToken, appId);
437
437
  mediaIdMapping.set(data.url, data.media_id);
438
438
  return data;
439
439
  }
440
- async function uploadImages(content, accessToken, relativePath) {
440
+ async function uploadImages(content, accessToken, relativePath, appId) {
441
441
  if (!content.includes("<img")) {
442
442
  return { html: content, firstImageId: "" };
443
443
  }
@@ -448,7 +448,7 @@ async function uploadImages(content, accessToken, relativePath) {
448
448
  const dataSrc = element.getAttribute("src");
449
449
  if (dataSrc) {
450
450
  if (!dataSrc.startsWith("https://mmbiz.qpic.cn")) {
451
- const resp = await uploadImage(dataSrc, accessToken, void 0, relativePath);
451
+ const resp = await uploadImage(dataSrc, accessToken, void 0, relativePath, appId);
452
452
  element.setAttribute("src", resp.url);
453
453
  return resp.media_id;
454
454
  } else {
@@ -467,14 +467,14 @@ async function publishToWechatDraft(articleOptions, publishOptions = {}) {
467
467
  const { appId, appSecret, relativePath } = publishOptions;
468
468
  const { appId: appIdFinal, appSecret: appSecretFinal } = await getAppIdAndSecret(appId, appSecret);
469
469
  const accessToken = await wechatPublisher.getAccessTokenWithCache(appIdFinal, appSecretFinal);
470
- const { html, firstImageId } = await uploadImages(content, accessToken, relativePath);
470
+ const { html, firstImageId } = await uploadImages(content, accessToken, relativePath, appIdFinal);
471
471
  let thumbMediaId;
472
472
  if (cover) {
473
473
  const cachedThumbMediaId = mediaIdMapping.get(cover);
474
474
  if (cachedThumbMediaId) {
475
475
  thumbMediaId = cachedThumbMediaId;
476
476
  } else {
477
- const resp = await uploadImage(cover, accessToken, "cover.jpg", relativePath);
477
+ const resp = await uploadImage(cover, accessToken, "cover.jpg", relativePath, appIdFinal);
478
478
  thumbMediaId = resp.media_id;
479
479
  }
480
480
  } else {
@@ -483,7 +483,7 @@ async function publishToWechatDraft(articleOptions, publishOptions = {}) {
483
483
  if (cachedThumbMediaId) {
484
484
  thumbMediaId = cachedThumbMediaId;
485
485
  } else {
486
- const resp = await uploadImage(firstImageId, accessToken, "cover.jpg", relativePath);
486
+ const resp = await uploadImage(firstImageId, accessToken, "cover.jpg", relativePath, appIdFinal);
487
487
  thumbMediaId = resp.media_id;
488
488
  }
489
489
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wenyan-md/core",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "Core library for Wenyan markdown rendering & publishing",
5
5
  "author": "Lei <caol64@gmail.com> (https://github.com/caol64)",
6
6
  "license": "Apache-2.0",