Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(desktop): default imported WeChat images to small

tianma-if5fdf7f5935c7
diff --git a/apps/web/src/lib/wechat-chat-import.test.mjs b/apps/web/src/lib/wechat-chat-import.test.mjs
index a6905888..452382cf 100644
--- a/apps/web/src/lib/wechat-chat-import.test.mjs
+++ b/apps/web/src/lib/wechat-chat-import.test.mjs
@@ -1,5 +1,6 @@
import { describe, expect, test } from "bun:test";
-import { FILE_ATTACHMENT_NODE_TYPE } from "@edgeever/shared";
+import { FILE_ATTACHMENT_NODE_TYPE, resolveMemoContentDoc } from "@edgeever/shared";
+import { IMAGE_WIDTH_PRESETS } from "@edgeever/shared/image-display";
import { createWeChatChatMemo } from "./wechat-chat-import.ts";
const memo = {
@@ -44,6 +45,12 @@ describe("WeChat chat note", () => {
const saved = JSON.stringify(updated.contentJson);
expect(saved).toContain("edgeever-staged://微信图片_1.jpg");
expect(saved).toContain(FILE_ATTACHMENT_NODE_TYPE);
+ expect(updated.contentJson.content.find((node) => node.type === "image")?.attrs?.width).toBe(
+ IMAGE_WIDTH_PRESETS.find((preset) => preset.id === "small").width,
+ );
+ expect(resolveMemoContentDoc(updated.contentJson, updated.contentMarkdown).content.find(
+ (node) => node.type === "image",
+ )?.attrs?.width).toBe(IMAGE_WIDTH_PRESETS.find((preset) => preset.id === "small").width);
});
test("removes the empty note when an attachment cannot be saved", async () => {
diff --git a/apps/web/src/lib/wechat-chat-import.ts b/apps/web/src/lib/wechat-chat-import.ts
index cef15a24..ca4b4a24 100644
--- a/apps/web/src/lib/wechat-chat-import.ts
+++ b/apps/web/src/lib/wechat-chat-import.ts
@@ -1,6 +1,8 @@
import { docToMarkdown, markdownToDoc, type TiptapDoc } from "@edgeever/shared";
+import { IMAGE_WIDTH_PRESETS } from "@edgeever/shared/image-display";
export const WECHAT_MEDIA_URL_PREFIX = "edgeever-wechat-media://";
+const WECHAT_IMAGE_WIDTH = IMAGE_WIDTH_PRESETS.find((preset) => preset.id === "small")!.width;
type WeChatMedia = {
id: string;
@@ -20,7 +22,9 @@ type WeChatMemo = {
const noteContent = (markdown: string) => {
const parsed = markdownToDoc(markdown);
- const nodes = parsed.content ?? [];
+ const nodes = (parsed.content ?? []).map((node) => node.type === "image"
+ ? { ...node, attrs: { ...node.attrs, width: WECHAT_IMAGE_WIDTH } }
+ : node);
const contentJson: TiptapDoc = {
type: "doc",
content: nodes.at(-1)?.type === "paragraph" ? nodes : [...nodes, { type: "paragraph" }],