🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(desktop): recognize app.lobehub.com file links in cloud mode (#20992)
YuTengjinge76d208a62b5
diff --git a/src/features/Conversation/Markdown/plugins/FileLink/rehypePlugin.test.ts b/src/features/Conversation/Markdown/plugins/FileLink/rehypePlugin.test.tsindex de5f7140efc..0223a359c99 100644--- a/src/features/Conversation/Markdown/plugins/FileLink/rehypePlugin.test.ts+++ b/src/features/Conversation/Markdown/plugins/FileLink/rehypePlugin.test.ts@@ -159,6 +159,46 @@ describe('rehypeFileLink', () => {expect((tree as any).children[0].tagName).toBe(LOBE_FILE_LINK_TAG);});+ it('also classifies links on the official cloud gateway apex', () => {+ useElectronStore.setState({ dataSyncConfig: { storageMode: 'cloud' } });++ const tree = {+ type: 'root',+ children: [+ {+ type: 'element',+ tagName: 'a',+ properties: { href: 'https://lobehub.com/f/file_abc123' },+ children: [{ type: 'text', value: 'bubble_sort.py' }],+ },+ ],+ };++ run(tree);++ expect((tree as any).children[0].tagName).toBe(LOBE_FILE_LINK_TAG);+ });++ it('rejects other official subdomains in cloud mode', () => {+ useElectronStore.setState({ dataSyncConfig: { storageMode: 'cloud' } });++ const tree = {+ type: 'root',+ children: [+ {+ type: 'element',+ tagName: 'a',+ properties: { href: 'https://docs.lobehub.com/f/file_abc123' },+ children: [{ type: 'text', value: 'not-ours' }],+ },+ ],+ };++ run(tree);++ expect((tree as any).children[0].tagName).toBe('a');+ });+it('classifies against the configured self-hosted remote server origin', () => {useElectronStore.setState({dataSyncConfig: {diff --git a/src/features/Conversation/Markdown/plugins/FileLink/rehypePlugin.ts b/src/features/Conversation/Markdown/plugins/FileLink/rehypePlugin.tsindex df3efde3113..8e732340d64 100644--- a/src/features/Conversation/Markdown/plugins/FileLink/rehypePlugin.ts+++ b/src/features/Conversation/Markdown/plugins/FileLink/rehypePlugin.ts@@ -1,4 +1,4 @@-import { isDesktop } from '@lobechat/const';+import { isDesktop, OFFICIAL_URL } from '@lobechat/const';import { SKIP, visit } from 'unist-util-visit';import { useElectronStore } from '@/store/electron';@@ -14,17 +14,37 @@ const getNodeText = (node: any): string => {};/**- * The origin file links should be classified against. On desktop the+ * The origins file links should be classified against. On desktop the* renderer's own origin isn't the app's — exported files are absolute URLs* pointing at the remote server, so that's what has to match (see useAppOrigin,* this plugin's non-hook equivalent).+ *+ * In cloud mode the remote server is the gateway apex (`OFFICIAL_CLOUD_URL`),+ * but the cloud server still writes file proxy links with its own `APP_URL`+ * (`OFFICIAL_URL`), so both origins count as the official cloud.*/-const getCurrentOrigin = (): string | undefined => {- if (typeof window === 'undefined') return undefined;- if (!isDesktop) return window.location.origin;+const getCurrentOrigins = (): string[] => {+ if (typeof window === 'undefined') return [];+ if (!isDesktop) return [window.location.origin];- const remoteServerUrl = electronSyncSelectors.remoteServerUrl(useElectronStore.getState());- return remoteServerUrl || undefined;+ const state = useElectronStore.getState();+ const remoteServerUrl = electronSyncSelectors.remoteServerUrl(state);+ if (electronSyncSelectors.storageMode(state) === 'cloud') {+ return [remoteServerUrl, OFFICIAL_URL].filter(Boolean);+ }++ return remoteServerUrl ? [remoteServerUrl] : [];+};++const parseAgainstOrigins = (href: string | undefined, origins: string[]) => {+ if (origins.length === 0) return parseFileLinkHref(href);++ for (const origin of origins) {+ const parsed = parseFileLinkHref(href, origin);+ if (parsed) return parsed;+ }++ return null;};/**@@ -39,7 +59,7 @@ export const rehypeFileLink = () => (tree: any) => {if (node.tagName !== 'a') return;const href = node.properties?.href as string | undefined;- const parsed = parseFileLinkHref(href, getCurrentOrigin());+ const parsed = parseAgainstOrigins(href, getCurrentOrigins());if (!parsed) return;const text = getNodeText(node).trim();