Skip to content

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

1.3 KB
Raw Blame
import {escapeAttr, escapeHtml} from "./escape";

// 笔记本名不做 HTML 过滤,拼接到对话框 HTML 前必须转义,否则名称中的标签会注入执行
// https://github.com/siyuan-note/siyuan/security/advisories/GHSA-8c2m-33v9-vvqm
export const genNotebookOptionsHTML = (notebooks: readonly {id: string, name: string, closed: boolean}[]) => {
    let optionsHTML = "";
    notebooks.forEach(item => {
        if (!item.closed) {
            optionsHTML += `<option value="${escapeAttr(item.id)}">${escapeHtml(item.name)}</option>`;
        }
    });
    return optionsHTML;
};

export const getLastDailyNoteNotebookId = (
    notebooks: readonly {id: string, closed: boolean}[],
    storedNotebookId: unknown,
) => {
    if (typeof storedNotebookId !== "string" || !storedNotebookId) {
        return undefined;
    }
    return notebooks.some(item => item.id === storedNotebookId && !item.closed) ? storedNotebookId : undefined;
};

// 加密文档只允许引用同一笔记本,普通文档不跨入加密笔记本。
export const canReferenceDailyNoteNotebook = (sourceID: string, targetID: string,
                                             sourceEncrypted: boolean, targetEncrypted: boolean) =>
    sourceEncrypted ? sourceID === targetID : !targetEncrypted;