Vanessa 2023-04-19 11:27:32 +08:00
parent 7c653d3689
commit a18e3a585c
9 changed files with 44 additions and 46 deletions

View file

@ -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);
}

View file

@ -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) {