An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/pull/17843
Vanessa07be79c1100f
diff --git a/app/src/block/popover.ts b/app/src/block/popover.tsindex 07faa41ac5..a2b3ddc23e 100644--- a/app/src/block/popover.ts+++ b/app/src/block/popover.ts@@ -2,7 +2,7 @@ import {BlockPanel} from "./Panel";import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName,} from "../protyle/util/hasClosest";import {fetchPost, fetchSyncPost} from "../util/fetch";import {hideTooltip, showTooltip, tooltipTargetElement} from "../dialog/tooltip";-import {getIdFromSYProtocol, isLocalPath} from "../util/pathName";+import {isLocalPath, parseSiYuanUriInfo} from "../util/pathName";import {App} from "../index";import {Constants} from "../constants";import {getCellText} from "../protyle/render/av/cell";@@ -459,10 +459,10 @@ export const showPopover = async (app: App, showRef = false) => {}} else if (popoverTargetElement.getAttribute("data-type")?.split(" ").includes("a")) {// 以思源协议开头的链接- refDefs = [{refID: getIdFromSYProtocol(popoverTargetElement.getAttribute("data-href"))}];+ refDefs = [{refID: parseSiYuanUriInfo(popoverTargetElement.getAttribute("data-href"))?.id ?? ""}];} else if (popoverTargetElement.dataset.type === "url") {// 在 database 的 url 列中以思源协议开头的链接- refDefs = [{refID: getIdFromSYProtocol(popoverTargetElement.textContent.trim())}];+ refDefs = [{refID: parseSiYuanUriInfo(popoverTargetElement.textContent.trim())?.id ?? ""}];} else if (popoverTargetElement.dataset.popoverUrl) {// 镜像数据库const postResponse = await fetchSyncPost(popoverTargetElement.dataset.popoverUrl, {avID: popoverTargetElement.dataset.avId});diff --git a/app/src/index.ts b/app/src/index.tsindex ad861868dc..50eeb07cc7 100644--- a/app/src/index.ts+++ b/app/src/index.ts@@ -10,8 +10,7 @@ import {fetchGet, fetchPost} from "./util/fetch";import {addBaseURL,getDocDisplayName,- getIdFromSYProtocol,- isSYProtocol,+ parseSiYuanUriInfo,redirectToCheckAuth,setNoteBook} from "./util/pathName";@@ -31,7 +30,7 @@ import {import {initMessage, showMessage} from "./dialog/message";import {getAllModels, getAllTabs} from "./layout/getAll";import {getLocalStorage, isChromeBrowser, isInMobileApp} from "./protyle/util/compatibility";-import {getSearch, isBrowser} from "./util/functions";+import {isBrowser} from "./util/functions";import {checkPublishServiceClosed} from "./util/processMessage";import {hideAllElements} from "./protyle/ui/hideElements";import {loadPlugins, reloadPlugin} from "./plugin/loader";@@ -276,13 +275,13 @@ export class App {const siyuanApp = new App();window.openFileByURL = (openURL) => {- if (openURL && isSYProtocol(openURL)) {- const isZoomIn = getSearch("focus", openURL) === "1";+ const blockInfo = parseSiYuanUriInfo(openURL);+ if (blockInfo != null) {openFileById({app: siyuanApp,- id: getIdFromSYProtocol(openURL),- action: isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],- zoomIn: isZoomIn+ id: blockInfo.id,+ action: blockInfo.focus ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],+ zoomIn: blockInfo.focus});return true;}diff --git a/app/src/layout/util.ts b/app/src/layout/util.tsindex 9ed6ffc6bc..884836aec3 100644--- a/app/src/layout/util.ts+++ b/app/src/layout/util.ts@@ -22,7 +22,7 @@ import {Backlink} from "./dock/Backlink";import {openFileById} from "../editor/util";import {isWindow} from "../util/functions";import {showMessage} from "../dialog/message";-import {getIdZoomInByPath} from "../util/pathName";+import {parseUriInfo} from "../util/pathName";import {Custom} from "./dock/Custom";import {newCardModel} from "../card/newCardTab";import {App} from "../index";@@ -494,13 +494,13 @@ export const JSONToLayout = (app: App, isStart: boolean) => {}});- const idZoomIn = getIdZoomInByPath();- if (idZoomIn.id) {+ const info = parseUriInfo();+ if (info.id) {openFileById({app,- id: idZoomIn.id,- action: idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],- zoomIn: idZoomIn.isZoomIn,+ id: info.id,+ action: info.focus ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],+ zoomIn: info.focus,});} else {let latestTabHeaderElement: HTMLElement;diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.tsindex 478fd3cb2d..992d192687 100644--- a/app/src/mobile/index.ts+++ b/app/src/mobile/index.ts@@ -11,7 +11,7 @@ import {import {Model} from "../layout/Model";import "../assets/scss/mobile.scss";import {Menus} from "../menus";-import {addBaseURL, getIdFromSYProtocol, isSYProtocol, setNoteBook} from "../util/pathName";+import {addBaseURL, parseSiYuanUriInfo, setNoteBook} from "../util/pathName";import {handleTouchEnd, handleTouchMove, handleTouchStart} from "./util/touch";import {fetchGet, fetchPost} from "../util/fetch";import {initFramework} from "./util/initFramework";@@ -22,7 +22,6 @@ import {goBack} from "./util/MobileBackFoward";import {activeBlur, hideKeyboardToolbar, showKeyboardToolbar} from "./util/keyboardToolbar";import {getLocalStorage, isChromeBrowser, isInMobileApp, writeText} from "../protyle/util/compatibility";import {getCurrentEditor, openMobileFileById} from "./editor";-import {getSearch} from "../util/functions";import {checkPublishServiceClosed} from "../util/processMessage";import {initRightMenu} from "./menu";import {openChangelog} from "../boot/openChangelog";@@ -244,9 +243,10 @@ window.processIOSPurchaseResponse = processIOSPurchaseResponse;window.showKeyboardToolbar = showKeyboardToolbar;window.hideKeyboardToolbar = hideKeyboardToolbar;window.openFileByURL = (openURL) => {- if (openURL && isSYProtocol(openURL)) {- openMobileFileById(siyuanApp, getIdFromSYProtocol(openURL),- getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);+ const blockInfo = parseSiYuanUriInfo(openURL);+ if (blockInfo != null) {+ openMobileFileById(siyuanApp, blockInfo.id,+ blockInfo.focus ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);return true;}return false;diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.tsindex 23f6afc65a..795bb3e3ad 100644--- a/app/src/mobile/util/initFramework.ts+++ b/app/src/mobile/util/initFramework.ts@@ -7,7 +7,7 @@ import {fetchPost} from "../../util/fetch";import {setInlineStyle} from "../../util/assets";import {renderSnippet} from "../../config/util/snippets";import {setEmpty} from "./setEmpty";-import {getIdZoomInByPath, getOpenNotebookCount} from "../../util/pathName";+import {getOpenNotebookCount, parseUriInfo} from "../../util/pathName";import {popMenu} from "../menu";import {MobileFiles} from "../dock/MobileFiles";import {MobileOutline} from "../dock/MobileOutline";@@ -183,10 +183,10 @@ export const initFramework = (app: App, isStart: boolean) => {if (window.JSAndroid && window.openFileByURL(window.JSAndroid.getBlockURL())) {return;}- const idZoomIn = getIdZoomInByPath();- if (idZoomIn.id) {- openMobileFileById(app, idZoomIn.id,- idZoomIn.isZoomIn ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);+ const info = parseUriInfo();+ if (info.id) {+ openMobileFileById(app, info.id,+ info.focus ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);return;}if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) {diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.tsindex 8004fb9206..2c074b5210 100644--- a/app/src/util/pathName.ts+++ b/app/src/util/pathName.ts@@ -70,46 +70,31 @@ export const parseSiYuanUriInfo = (uri: URL | string | null | undefined): ISiYua}};-export const getIdZoomInByPath = () => {+export const parseUriInfo = () => {const searchParams = new URLSearchParams(window.location.search);- const data = {- id: "",- isZoomIn: false,- };const PWAURL = searchParams.get("url");if (/^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(PWAURL)) {const dataInfo = parseSiYuanUriInfo(PWAURL);if (dataInfo != null) {- data.id = dataInfo.id;- data.isZoomIn = dataInfo.focus;window.siyuan.editorIsFullscreen = dataInfo.fullscreen;- return data;+ return dataInfo;}}if (window.JSAndroid) {const dataInfo = parseSiYuanUriInfo(window.JSAndroid.getBlockURL());if (dataInfo != null) {- data.id = dataInfo.id;- data.isZoomIn = dataInfo.focus;window.siyuan.editorIsFullscreen = dataInfo.fullscreen;- return data;+ return dataInfo;}}// 支持通过 URL 查询字符串参数 `id` 和 `focus` 跳转到 Web 端指定块 https://github.com/siyuan-note/siyuan/pull/7086- data.id = searchParams.get("id") ?? "";- data.isZoomIn = searchParams.get("focus") === "1";window.siyuan.editorIsFullscreen = searchParams.get("fullscreen") === "1";- return data;-};--export const isSYProtocol = (url: string) => {- return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);-};--export const getIdFromSYProtocol = (url: string) => {- return url.substring(16, 16 + 22);+ return {+ id: searchParams.get("id") ?? "",+ focus: searchParams.get("focus") === "1"+ };};/* redirect to auth page */