Skip to content

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

fix(extension): default clips to the inbox notebook

tianma-if586501da76b6
diff --git a/apps/extension/notebook-clip.test.mjs b/apps/extension/notebook-clip.test.mjs
new file mode 100644
index 00000000..985f8860
--- /dev/null
+++ b/apps/extension/notebook-clip.test.mjs
@@ -0,0 +1,42 @@
+import { readFileSync } from "node:fs";
+import { expect, test } from "bun:test";
+import { clipNotebookId } from "./src/extension.ts";
+
+const notebooks = [
+ { id: "nb_video", slug: "video" },
+ { id: "ws_1_inbox", slug: "inbox" },
+];
+
+test("keeps a saved notebook that still exists", () => {
+ expect(clipNotebookId("nb_video", notebooks)).toBe("nb_video");
+});
+
+test("uses 等待分类 when the saved id is empty or damaged", () => {
+ expect(clipNotebookId("", notebooks)).toBe("ws_1_inbox");
+ expect(clipNotebookId(" ", notebooks)).toBe("ws_1_inbox");
+ expect(clipNotebookId("nb_deleted", notebooks)).toBe("ws_1_inbox");
+ expect(clipNotebookId("\u0001\u0005token1", notebooks)).toBe("ws_1_inbox");
+ expect(clipNotebookId("", [{ id: "nb_later" }, { id: "nb_inbox" }])).toBe("nb_inbox");
+ expect(clipNotebookId("", [{ id: "nb_later" }, { id: "ws_inbox" }])).toBe("ws_inbox");
+});
+
+test("reports no notebook when 等待分类 is missing", () => {
+ expect(clipNotebookId("nb_video", [])).toBe("");
+ expect(clipNotebookId("", [{ id: "nb_video" }])).toBe("");
+ expect(clipNotebookId("nb_video", [{ id: " " }])).toBe("");
+});
+
+test("tweet and the other direct clips resolve a notebook the account still has", () => {
+ const background = readFileSync(new URL("./src/background.ts", import.meta.url), "utf8");
+ expect(background).not.toContain("notebookId: settings.notebookId");
+ for (const marker of [
+ "await saveCapturedTweetNote",
+ "await saveCapturedImageNote",
+ "await saveCapturedXhsNote",
+ "await saveCapturedZhihuNote",
+ "await saveCapturedRedditPost",
+ ]) {
+ const call = background.slice(background.indexOf(marker), background.indexOf(marker) + 280);
+ expect(call).toContain("notebookForClip(settings)");
+ }
+});
diff --git a/apps/extension/public/_locales/en/messages.json b/apps/extension/public/_locales/en/messages.json
index 4b60d2fd..1fde76a8 100644
--- a/apps/extension/public/_locales/en/messages.json
+++ b/apps/extension/public/_locales/en/messages.json
@@ -108,7 +108,7 @@
"message": "Default notebook"
},
"autoFirstNotebook": {
- "message": "Use the first notebook automatically after connecting"
+ "message": "Inbox"
},
"testConnection": {
"message": "Test connection"
diff --git a/apps/extension/public/_locales/ja/messages.json b/apps/extension/public/_locales/ja/messages.json
index ab15a1b8..2760303b 100644
--- a/apps/extension/public/_locales/ja/messages.json
+++ b/apps/extension/public/_locales/ja/messages.json
@@ -108,7 +108,7 @@
"message": "既定のノートブック"
},
"autoFirstNotebook": {
- "message": "接続後、先頭のノートブックを自動で使う"
+ "message": "受信箱"
},
"testConnection": {
"message": "接続をテスト"
diff --git a/apps/extension/public/_locales/pl/messages.json b/apps/extension/public/_locales/pl/messages.json
index 91056233..aad18fbf 100644
--- a/apps/extension/public/_locales/pl/messages.json
+++ b/apps/extension/public/_locales/pl/messages.json
@@ -108,7 +108,7 @@
"message": "Domyślny notatnik"
},
"autoFirstNotebook": {
- "message": "Po połączeniu automatycznie użyj pierwszego notatnika"
+ "message": "Skrzynka"
},
"testConnection": {
"message": "Testuj połączenie"
diff --git a/apps/extension/public/_locales/zh_CN/messages.json b/apps/extension/public/_locales/zh_CN/messages.json
index c0477316..548b3ef3 100644
--- a/apps/extension/public/_locales/zh_CN/messages.json
+++ b/apps/extension/public/_locales/zh_CN/messages.json
@@ -108,7 +108,7 @@
"message": "默认笔记本"
},
"autoFirstNotebook": {
- "message": "连接后自动使用第一个笔记本"
+ "message": "等待分类"
},
"testConnection": {
"message": "测试连接"
diff --git a/apps/extension/src/background.ts b/apps/extension/src/background.ts
index 0e462e6b..9d4b2163 100644
--- a/apps/extension/src/background.ts
+++ b/apps/extension/src/background.ts
@@ -1,4 +1,5 @@
import {
+ clipNotebookId,
edgeEverFormRequest,
edgeEverRequest,
getInstanceOrigin,
@@ -188,7 +189,7 @@ const describeSaveError = (error: unknown) => {
const notebookForClip = async (settings: ExtensionSettings) => {
const notebooks = await listNotebooks(settings);
- const notebookId = settings.notebookId || notebooks.notebooks[0]?.id;
+ const notebookId = clipNotebookId(settings.notebookId, notebooks.notebooks);
if (!notebookId) throw new Error(t("noAvailableNotebooks"));
return notebookId;
};
@@ -354,7 +355,7 @@ const persistImage = async (
) => {
try {
await saveCapturedImageNote(imageNoteClient(settings), {
- notebookId: settings.notebookId,
+ notebookId: await notebookForClip(settings),
title: noteTitleForImage(context.pageTitle, context.alt, t("imageNoteFallbackTitle")),
alt: context.alt,
filename: filenameForImage(context.srcUrl, image.mimeType),
@@ -780,7 +781,7 @@ const saveTweetFromMenu = async (
if (stored) images.push(stored);
}
await saveCapturedTweetNote(imageNoteClient(settings), {
- notebookId: settings.notebookId,
+ notebookId: await notebookForClip(settings),
title: tweetNoteTitle({ ...tweet, fallback: t("tweetNoteFallbackTitle") }),
displayName: tweet.displayName,
handle: tweet.handle,
@@ -905,7 +906,7 @@ const saveXhsFromMenu = async (
if (stored) images.push(stored);
}
await saveCapturedXhsNote(imageNoteClient(settings), {
- notebookId: settings.notebookId,
+ notebookId: await notebookForClip(settings),
title: xhsNoteTitle({ ...note, fallback: t("xhsNoteFallbackTitle") }),
nickname: note.nickname,
noteTitle: note.title,
@@ -1011,7 +1012,7 @@ const saveLocatedZhihu = async (
}
await saveCapturedZhihuNote(imageNoteClient(settings), {
kind: note.kind,
- notebookId: settings.notebookId,
+ notebookId: await notebookForClip(settings),
title: zhihuNoteTitle({
title: note.title,
author: note.author,
@@ -1136,7 +1137,7 @@ const saveRedditFromMenu = async (
if (stored) images.push({ ...stored, url: image.url });
}
await saveCapturedRedditPost(imageNoteClient(settings), post, {
- notebookId: settings.notebookId,
+ notebookId: await notebookForClip(settings),
sourceLabel: t("sourceLabel"),
capturedAtLabel: t("capturedAtLabel"),
timeLabel: t("tweetTimeLabel"),
diff --git a/apps/extension/src/extension.ts b/apps/extension/src/extension.ts
index 27bcbb0e..50a1e0a4 100644
--- a/apps/extension/src/extension.ts
+++ b/apps/extension/src/extension.ts
@@ -9,6 +9,7 @@ export type ExtensionSettings = {
export type Notebook = {
id: string;
name: string;
+ slug?: string | null;
};
export const DEFAULT_SETTINGS: ExtensionSettings = {
@@ -17,6 +18,16 @@ export const DEFAULT_SETTINGS: ExtensionSettings = {
notebookId: "",
};
+const isInboxNotebook = (notebook: { id: string; slug?: string | null }) =>
+ notebook.slug === "inbox" || notebook.id === "nb_inbox" || notebook.id.endsWith("_inbox");
+
+// An empty or stale choice means 等待分类. A notebook the user picked still wins.
+export const clipNotebookId = (savedId: string, notebooks: { id: string; slug?: string | null }[]) => {
+ const saved = savedId.trim();
+ if (saved && notebooks.some((notebook) => notebook.id === saved)) return saved;
+ return notebooks.find((notebook) => notebook.id.trim() && isInboxNotebook(notebook))?.id ?? "";
+};
+
export const getSettings = async (): Promise<ExtensionSettings> => {
const stored = await chrome.storage.local.get(DEFAULT_SETTINGS);
return {