Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/pull/8012

Vanessaa18e3a585cd3
diff --git a/app/src/block/popover.ts b/app/src/block/popover.ts
index 7129ecea9e..3a75b6afa0 100644
--- a/app/src/block/popover.ts
+++ b/app/src/block/popover.ts
@@ -1,8 +1,8 @@
import {BlockPanel} from "./Panel";
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
import {fetchSyncPost} from "../util/fetch";
-import {getIdFromSiyuanUrl} from "../util/functions";
import {hideTooltip, showTooltip} from "../dialog/tooltip";
+import {getIdFromSYProtocol} from "../util/pathName";
let popoverTargetElement: HTMLElement;
export const initBlockPopover = () => {
@@ -200,7 +200,7 @@ export const showPopover = async () => {
}
} else if (popoverTargetElement.getAttribute("data-type")?.split(" ").includes("a")) {
// 以思源协议开头的链接
- ids = [getIdFromSiyuanUrl(popoverTargetElement.getAttribute("data-href"))];
+ ids = [getIdFromSYProtocol(popoverTargetElement.getAttribute("data-href"))];
} else {
// pdf
let targetId;
diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts
index af13be19f5..c5fafe9b84 100644
--- a/app/src/boot/onGetConfig.ts
+++ b/app/src/boot/onGetConfig.ts
@@ -17,7 +17,7 @@ import {renderSnippet} from "../config/util/snippets";
import {openFileById} from "../editor/util";
import {focusByRange} from "../protyle/util/selection";
import {exitSiYuan} from "../dialog/processSystem";
-import {getSearch, isWindow, isSiyuanUrl, getIdFromSiyuanUrl} from "../util/functions";
+import {getSearch, isWindow} from "../util/functions";
import {initStatus} from "../layout/status";
import {showMessage} from "../dialog/message";
import {replaceLocalPath} from "../editor/rename";
@@ -25,6 +25,7 @@ import {setTabPosition} from "../window/setHeader";
import {initBar} from "../layout/topBar";
import {setProxy} from "../config/util/setProxy";
import {openChangelog} from "./openChangelog";
+import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
if (key1 === "general") {
@@ -212,10 +213,10 @@ export const initWindow = () => {
});
if (!isWindow()) {
ipcRenderer.on(Constants.SIYUAN_OPENURL, (event, url) => {
- if (!isSiyuanUrl(url)) {
+ if (!isSYProtocol(url)) {
return;
}
- const id = getIdFromSiyuanUrl(url);
+ const id = getIdFromSYProtocol(url);
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
if (existResponse.data) {
openFileById({
diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts
index 21753e7b30..128dadefc2 100644
--- a/app/src/dialog/processSystem.ts
+++ b/app/src/dialog/processSystem.ts
@@ -9,11 +9,12 @@ import {getCurrentWindow} from "@electron/remote";
/// #endif
import {hideMessage, showMessage} from "./message";
import {Dialog} from "./index";
-import {isMobile, redirectToCheckAuth} from "../util/functions";
+import {isMobile} from "../util/functions";
import {confirmDialog} from "./confirmDialog";
import {escapeHtml} from "../util/escape";
import {getWorkspaceName} from "../util/noRelyPCFunction";
import {needSubscribe} from "../util/needSubscribe";
+import { redirectToCheckAuth } from "../util/pathName";
export const lockScreen = () => {
if (window.siyuan.config.readonly) {
diff --git a/app/src/index.ts b/app/src/index.ts
index 80e7b0ea21..cf21f757cf 100644
--- a/app/src/index.ts
+++ b/app/src/index.ts
@@ -8,7 +8,7 @@ import {account} from "./config/account";
import {addScript, addScriptSync} from "./protyle/util/addScript";
import {genUUID} from "./util/genID";
import {fetchGet, fetchPost} from "./util/fetch";
-import {addBaseURL, setNoteBook} from "./util/pathName";
+import {addBaseURL, getIdFromSYProtocol, isSYProtocol, setNoteBook} from "./util/pathName";
import {registerServiceWorker} from "./util/serviceWorker";
import {openFileById} from "./editor/util";
import {
@@ -27,12 +27,13 @@ import {resizeDrag} from "./layout/util";
import {getAllTabs} from "./layout/getAll";
import {getLocalStorage} from "./protyle/util/compatibility";
import {updateEditModeElement} from "./layout/topBar";
-import {getIdFromSiyuanUrl, getSearch, isSiyuanUrl} from "./util/functions";
+import {getSearch} from "./util/functions";
import {hideAllElements} from "./protyle/ui/hideElements";
import {initPluginSystem} from 'siyuan-petal';
class App {
constructor() {
+ // TODO
/// #if BROWSER
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
/// #endif
@@ -183,9 +184,9 @@ class App {
new App();
window.openFileByURL = (openURL) => {
- if (openURL && isSiyuanUrl(openURL)) {
+ if (openURL && isSYProtocol(openURL)) {
openFileById({
- id: getIdFromSiyuanUrl(openURL),
+ id: getIdFromSYProtocol(openURL),
action: getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
return true;
diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts
index 3105510e4b..d4d752f630 100644
--- a/app/src/layout/util.ts
+++ b/app/src/layout/util.ts
@@ -27,11 +27,12 @@ import {saveScroll} from "../protyle/scroll/saveScroll";
import {pdfResize} from "../asset/renderAssets";
import {Backlink} from "./dock/Backlink";
import {openFileById} from "../editor/util";
-import {getSearch, isWindow, isSiyuanUrl, isWebSiyuanUrl, getIdFromSiyuanUrl, getIdFromWebSiyuanUrl} from "../util/functions";
+import {getSearch, isWindow} from "../util/functions";
/// #if !BROWSER
import {setTabPosition} from "../window/setHeader";
/// #endif
import {showMessage} from "../dialog/message";
+import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
export const setPanelFocus = (element: Element) => {
if (element.classList.contains("layout__tab--active") || element.classList.contains("layout__wnd--active")) {
@@ -369,17 +370,19 @@ export const JSONToLayout = (isStart: boolean) => {
});
}
- // PWA 捕获 siyuan://
+ // TODO PWA 捕获 siyuan://
const searchParams = new URLSearchParams(window.location.search);
const url = searchParams.get("url");
- if (isSiyuanUrl(url) || isWebSiyuanUrl(url)) {
+
+ const isWebSiyuanUrl = /^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
+ if (isSYProtocol(url) || isWebSiyuanUrl) {
searchParams.delete("url");
switch (true) {
- case isSiyuanUrl(url):
- searchParams.set("id", getIdFromSiyuanUrl(url));
+ case isSYProtocol(url):
+ searchParams.set("id", getIdFromSYProtocol(url));
break;
- case isWebSiyuanUrl(url):
- searchParams.set("id", getIdFromWebSiyuanUrl(url));
+ case isWebSiyuanUrl:
+ searchParams.set("id", url.substring(20, 20 + 22));
break;
}
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index c9c4aa4226..109336121e 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -6,7 +6,7 @@ import {hasClosestByAttribute} from "../protyle/util/hasClosest";
import {Model} from "../layout/Model";
import "../assets/scss/mobile.scss";
import {Menus} from "../menus";
-import {addBaseURL, setNoteBook} from "../util/pathName";
+import {addBaseURL, getIdFromSYProtocol, isSYProtocol, setNoteBook} from "../util/pathName";
import {handleTouchEnd, handleTouchMove, handleTouchStart} from "./util/touch";
import {fetchGet, fetchPost} from "../util/fetch";
import {initFramework} from "./util/initFramework";
@@ -18,7 +18,7 @@ import {goBack} from "./util/MobileBackFoward";
import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/keyboardToolbar";
import {getLocalStorage} from "../protyle/util/compatibility";
import {openMobileFileById} from "./editor";
-import {getSearch, isSiyuanUrl, getIdFromSiyuanUrl} from "../util/functions";
+import {getSearch} from "../util/functions";
import {initRightMenu} from "./menu";
import {openChangelog} from "../boot/openChangelog";
@@ -90,8 +90,8 @@ window.showKeyboardToolbar = (height) => {
};
window.hideKeyboardToolbar = hideKeyboardToolbar;
window.openFileByURL = (openURL) => {
- if (openURL && isSiyuanUrl(openURL)) {
- openMobileFileById(getIdFromSiyuanUrl(openURL),
+ if (openURL && isSYProtocol(openURL)) {
+ openMobileFileById(getIdFromSYProtocol(openURL),
getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
return true;
}
diff --git a/app/src/util/functions.ts b/app/src/util/functions.ts
index 63660fa147..e566541c47 100644
--- a/app/src/util/functions.ts
+++ b/app/src/util/functions.ts
@@ -46,27 +46,3 @@ export const isFileAnnotation = (text: string) => {
export const looseJsonParse = (text: string) => {
return Function(`"use strict";return (${text})`)();
};
-
-/* redirect to auth page */
-export const redirectToCheckAuth = (to: string = window.location.href) => {
- const url = new URL(window.location.origin);
- url.pathname = '/check-auth';
- url.searchParams.set('to', to);
- window.location.href = url.href;
-}
-
-export const isSiyuanUrl = (url: string) => {
- return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
-}
-
-export const isWebSiyuanUrl = (url: string) => {
- return /^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
-}
-
-export const getIdFromSiyuanUrl = (url: string) => {
- return url.substring(16, 16 + 22);
-}
-
-export const getIdFromWebSiyuanUrl = (url: string) => {
- return url.substring(20, 20 + 22);
-}
diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts
index 165cab41cf..a8b6f3b2fb 100644
--- a/app/src/util/pathName.ts
+++ b/app/src/util/pathName.ts
@@ -8,6 +8,22 @@ import {unicode2Emoji} from "../emoji";
import {Constants} from "../constants";
import {showMessage} from "../dialog/message";
+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);
+}
+
+/* redirect to auth page */
+export const redirectToCheckAuth = (to: string = window.location.href) => {
+ const url = new URL(window.location.origin);
+ url.pathname = '/check-auth';
+ url.searchParams.set('to', to);
+ window.location.href = url.href;
+}
+
export const addBaseURL = () => {
let baseURLElement = document.getElementById("baseURL");
if (!baseURLElement) {
diff --git a/app/src/window/onWindowsMsg.ts b/app/src/window/onWindowsMsg.ts
index cf4f641846..9bd8334d1b 100644
--- a/app/src/window/onWindowsMsg.ts
+++ b/app/src/window/onWindowsMsg.ts
@@ -1,7 +1,7 @@
import {exportLayout, getInstanceById} from "../layout/util";
import {Tab} from "../layout/Tab";
import {fetchPost} from "../util/fetch";
-import {redirectToCheckAuth} from "../util/functions";
+import {redirectToCheckAuth} from "../util/pathName";
const closeTab = (ipcData: IWebSocketData) => {
const tab = getInstanceById(ipcData.data);