An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Support data snapshot versions in document history https://github.com/siyuan-note/siyuan/issues/17724
Daniel236cd18c0d10
diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scssindex 60801d2fdd..1a5fcbdf5e 100644--- a/app/src/assets/scss/main/_mobile.scss+++ b/app/src/assets/scss/main/_mobile.scss@@ -394,7 +394,8 @@}}-#historyContainer {+#historyContainer,+#docHistoryContainer {& > div {flex-direction: column;diff --git a/app/src/history/doc.ts b/app/src/history/doc.tsindex 507f4555c4..cd04f5384f 100644--- a/app/src/history/doc.ts+++ b/app/src/history/doc.ts@@ -4,11 +4,12 @@ import {Constants} from "../constants";import {Protyle} from "../protyle";import {disabledProtyle, onGet} from "../protyle/util/onGet";import * as dayjs from "dayjs";-import {fetchPost} from "../util/fetch";+import {fetchPost, fetchSyncPost} from "../util/fetch";import {isMobile} from "../util/functions";import type {App} from "../index";import {resizeSide} from "./resizeSide";import {escapeHtml} from "../util/escape";+import {openRepoFile, renderRepoFileList, rollbackRepoFile, saveRepoFile} from "./repoFile";let historyEditor: Protyle;let isLoading = false;@@ -66,40 +67,110 @@ const renderDoc = (element: HTMLElement, currentPage: number, id: string) => {});};+const renderRepo = async (element: HTMLElement, currentPage: number, id: string) => {+ const previousElement = element.querySelector('[data-type="snapshotprevious"]');+ const nextElement = element.querySelector('[data-type="snapshotnext"]');+ const pageNumElement = element.querySelector('[data-type="jumpSnapshotPage"]');+ const pageInfoElement = nextElement.nextElementSibling.nextElementSibling;+ const listElement = element.querySelector(".b3-list--background");+ element.setAttribute("data-init", "true");+ element.setAttribute("data-page", currentPage.toString());+ pageNumElement.textContent = currentPage.toString();+ previousElement.setAttribute("disabled", "disabled");+ nextElement.setAttribute("disabled", "disabled");+ listElement.innerHTML = '<li style="position: relative;height: 100%;"><div class="fn__loading"><img width="64px" src="/stage/loading-pure.svg"></div></li>';++ let response: IWebSocketData;+ try {+ response = await fetchSyncPost("/api/repo/getRepoDocHistory", {+ id,+ page: currentPage+ });+ } catch (e) {+ console.warn("get repo doc history failed", e);+ listElement.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;+ return;+ }+ if (response.code !== 0) {+ listElement.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;+ return;+ }++ const pageCount = response.data.pageCount || 0;+ if (currentPage > 1) {+ previousElement.removeAttribute("disabled");+ }+ if (currentPage < pageCount) {+ nextElement.removeAttribute("disabled");+ }+ pageNumElement.setAttribute("data-totalpage", Math.max(pageCount, 1).toString());+ pageInfoElement.textContent = window.siyuan.languages.pageCountAndSnapshotCount+ .replace("${x}", pageCount)+ .replace("${y}", response.data.totalCount);+ pageInfoElement.classList.remove("fn__none");+ renderRepoFileList(response.data.files, listElement, false);+};+export const openDocHistory = (options: {app: App,id: string,notebookId: string,pathString: string}) => {- const contentHTML = `<div class="history__action">- <div class="block__icons">- <span data-type="docprevious" class="block__icon block__icon--show b3-tooltips b3-tooltips__e" disabled="disabled" aria-label="${window.siyuan.languages.previousLabel}"><svg><use xlink:href="#iconLeft"></use></svg></span>- <button class="b3-button b3-button--text ft__selectnone" data-type="jumpRepoPage" disabled>1</button>- <span data-type="docnext" class="block__icon block__icon--show b3-tooltips b3-tooltips__e" disabled="disabled" aria-label="${window.siyuan.languages.nextLabel}"><svg><use xlink:href="#iconRight"></use></svg></span>- <span class="fn__space"></span>- <span class="ft__on-surface fn__flex-shrink ft__selectnone fn__none">${window.siyuan.languages.pageCountAndHistoryCount}</span>- <span class="fn__space"></span>- <div class="fn__flex-1"></div>- <select data-type="opselect" class="b3-select">- <option value="all" selected>${window.siyuan.languages.allOp}</option>- <option value="update">${window.siyuan.languages.historyUpdate}</option>- <option value="format">${window.siyuan.languages.historyFormat}</option>- <option value="sync">${window.siyuan.languages.historySync}</option>- <option value="replace">${window.siyuan.languages.historyReplace}</option>- <option value="outline">${window.siyuan.languages.historyOutline}</option>- </select>+ const contentHTML = `<div class="fn__flex-column" style="height: 100%;">+ <div class="layout-tab-bar fn__flex" ${isMobile() ? "" : 'style="border-radius: var(--b3-border-radius-b) var(--b3-border-radius-b) 0 0"'}>+ <div data-type="doc" class="item item--full item--focus"><span class="fn__flex-1"></span><span class="item__text">${window.siyuan.languages.fileHistory}</span><span class="fn__flex-1"></span></div>+ <div data-type="repo" class="item item--full"><span class="fn__flex-1"></span><span class="item__text">${window.siyuan.languages.dataSnapshot}</span><span class="fn__flex-1"></span></div></div>-</div>-<div class="fn__flex fn__flex-1 history__panel">- <ul class="b3-list b3-list--background history__side" ${isMobile() ? "" : `style="width: ${window.siyuan.storage[Constants.LOCAL_HISTORY].sideDocWidth}"`}>- <li class="fn__loading"><img style="height: 64px;width: 64px" src="/stage/loading-pure.svg"></li>- </ul>- <div class="history__resize"></div>- <div class="fn__flex-1 fn__flex-column">- <div class="protyle-title__input fn__none ft__center ft__breakword"></div>- <textarea class="fn__flex-1 history__text fn__none" readonly data-type="mdPanel"></textarea>- <div class="fn__flex-1 history__text fn__none" style="padding: 0" data-type="docPanel"></div>+ <div class="fn__flex-1 fn__flex" id="docHistoryContainer">+ <div data-type="doc" class="history__repo fn__block" data-init="true">+ <div class="history__action">+ <div class="block__icons">+ <span data-type="docprevious" class="block__icon block__icon--show b3-tooltips b3-tooltips__e" disabled="disabled" aria-label="${window.siyuan.languages.previousLabel}"><svg><use xlink:href="#iconLeft"></use></svg></span>+ <button class="b3-button b3-button--text ft__selectnone" data-type="jumpRepoPage" disabled>1</button>+ <span data-type="docnext" class="block__icon block__icon--show b3-tooltips b3-tooltips__e" disabled="disabled" aria-label="${window.siyuan.languages.nextLabel}"><svg><use xlink:href="#iconRight"></use></svg></span>+ <span class="fn__space"></span>+ <span class="ft__on-surface fn__flex-shrink ft__selectnone fn__none">${window.siyuan.languages.pageCountAndHistoryCount}</span>+ <span class="fn__space"></span>+ <div class="fn__flex-1"></div>+ <select data-type="opselect" class="b3-select">+ <option value="all" selected>${window.siyuan.languages.allOp}</option>+ <option value="update">${window.siyuan.languages.historyUpdate}</option>+ <option value="format">${window.siyuan.languages.historyFormat}</option>+ <option value="sync">${window.siyuan.languages.historySync}</option>+ <option value="replace">${window.siyuan.languages.historyReplace}</option>+ <option value="outline">${window.siyuan.languages.historyOutline}</option>+ </select>+ </div>+ </div>+ <div class="fn__flex fn__flex-1 history__panel">+ <ul class="b3-list b3-list--background history__side" ${isMobile() ? "" : `style="width: ${window.siyuan.storage[Constants.LOCAL_HISTORY].sideDocWidth}"`}>+ <li class="fn__loading"><img style="height: 64px;width: 64px" src="/stage/loading-pure.svg"></li>+ </ul>+ <div class="history__resize"></div>+ <div class="fn__flex-1 fn__flex-column">+ <div class="protyle-title__input fn__none ft__center ft__breakword"></div>+ <textarea class="fn__flex-1 history__text fn__none" readonly data-type="mdPanel"></textarea>+ <div class="fn__flex-1 history__text fn__none" style="padding: 0" data-type="docPanel"></div>+ </div>+ </div>+ </div>+ <div data-type="repo" class="fn__none history__repo">+ <div class="history__action">+ <div class="block__icons">+ <span data-type="snapshotprevious" class="block__icon block__icon--show b3-tooltips b3-tooltips__e" disabled="disabled" aria-label="${window.siyuan.languages.previousLabel}"><svg><use xlink:href="#iconLeft"></use></svg></span>+ <button class="b3-button b3-button--text ft__selectnone" data-type="jumpSnapshotPage" data-totalpage="1">1</button>+ <span data-type="snapshotnext" class="block__icon block__icon--show b3-tooltips b3-tooltips__e" disabled="disabled" aria-label="${window.siyuan.languages.nextLabel}"><svg><use xlink:href="#iconRight"></use></svg></span>+ <span class="fn__space"></span>+ <span class="ft__on-surface fn__flex-shrink ft__selectnone fn__none">${window.siyuan.languages.pageCountAndSnapshotCount}</span>+ <span class="fn__space"></span>+ <div class="fn__flex-1"></div>+ </div>+ </div>+ <ul class="b3-list b3-list--background fn__flex-1" style="padding: 8px 0">+ <li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>+ </ul>+ </div></div></div>`;const dialog = new Dialog({@@ -114,13 +185,15 @@ export const openDocHistory = (options: {});dialog.element.setAttribute("data-key", Constants.DIALOG_HISTORYDOC);- const opElement = dialog.element.querySelector(".b3-select") as HTMLSelectElement;+ const fileElement = dialog.element.querySelector('#docHistoryContainer [data-type="doc"]') as HTMLElement;+ const repoElement = dialog.element.querySelector('#docHistoryContainer [data-type="repo"]') as HTMLElement;+ const opElement = fileElement.querySelector(".b3-select") as HTMLSelectElement;opElement.addEventListener("change", () => {- renderDoc(dialog.element, 1, options.id);+ renderDoc(fileElement, 1, options.id);});- const docElement = dialog.element.querySelector('.history__text[data-type="docPanel"]') as HTMLElement;- const mdElement = dialog.element.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement;- renderDoc(dialog.element, 1, options.id);+ const docElement = fileElement.querySelector('.history__text[data-type="docPanel"]') as HTMLElement;+ const mdElement = fileElement.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement;+ renderDoc(fileElement, 1, options.id);historyEditor = new Protyle(options.app, docElement, {blockId: "",history: {@@ -136,13 +209,47 @@ export const openDocHistory = (options: {typewriterMode: false,});disabledProtyle(historyEditor.protyle);- const pageNumElement = dialog.element.querySelector('[data-type="jumpRepoPage"]');- const titleElement = dialog.element.querySelector(".protyle-title__input");+ const pageNumElement = fileElement.querySelector('[data-type="jumpRepoPage"]');+ const titleElement = fileElement.querySelector(".protyle-title__input");dialog.element.addEventListener("click", (event) => {let target = event.target as HTMLElement;while (target && !target.isEqualNode(dialog.element)) {const type = target.getAttribute("data-type");- if (type === "rollback" && !isLoading) {+ const repoFileElement = target.closest('[data-type="searchFileItem"]');+ if (target.classList.contains("item")) {+ target.parentElement.querySelector(".item--focus").classList.remove("item--focus");+ Array.from(dialog.element.querySelector("#docHistoryContainer").children).forEach((item: HTMLElement) => {+ if (item.getAttribute("data-type") === type) {+ item.classList.remove("fn__none");+ item.classList.add("fn__block");+ target.classList.add("item--focus");+ if (type === "repo" && item.getAttribute("data-init") !== "true") {+ renderRepo(item, 1, options.id);+ }+ } else {+ item.classList.add("fn__none");+ item.classList.remove("fn__block");+ }+ });+ event.stopPropagation();+ event.preventDefault();+ break;+ } else if (type === "rollback" && repoFileElement) {+ rollbackRepoFile(repoFileElement);+ event.stopPropagation();+ event.preventDefault();+ break;+ } else if (type === "saveAs" && repoFileElement) {+ saveRepoFile(repoFileElement);+ event.stopPropagation();+ event.preventDefault();+ break;+ } else if (type === "view" && repoFileElement) {+ openRepoFile(options.app, repoFileElement);+ event.stopPropagation();+ event.preventDefault();+ break;+ } else if (type === "rollback" && !isLoading) {getHistoryPath(target.parentElement, opElement.value, options.id, (item) => {const dataPath = item.path;isLoading = false;@@ -157,7 +264,8 @@ export const openDocHistory = (options: {event.stopPropagation();event.preventDefault();break;- } else if (target.classList.contains("b3-list-item") && !isLoading) {+ } else if (target.classList.contains("b3-list-item") &&+ target.getAttribute("data-type") !== "searchFileItem" && !isLoading) {getHistoryPath(target, opElement.value, options.id, (item) => {const dataPath = item.path;fetchPost("/api/history/getDocHistoryContent", {@@ -188,7 +296,7 @@ export const openDocHistory = (options: {break;} else if ((type === "docprevious" || type === "docnext") && target.getAttribute("disabled") !== "disabled") {const currentPage = parseInt(pageNumElement.textContent);- renderDoc(dialog.element, type === "docprevious" ? currentPage - 1 : currentPage + 1, options.id);+ renderDoc(fileElement, type === "docprevious" ? currentPage - 1 : currentPage + 1, options.id);event.stopPropagation();event.preventDefault();break;@@ -202,7 +310,27 @@ export const openDocHistory = (options: {if (inputElement.value === "") {return;}- renderDoc(dialog.element, Math.max(1, Math.min(parseInt(inputElement.value), totalPage)), options.id);+ renderDoc(fileElement, Math.max(1, Math.min(parseInt(inputElement.value), totalPage)), options.id);+ }+ );+ } else if ((type === "snapshotprevious" || type === "snapshotnext") &&+ target.getAttribute("disabled") !== "disabled") {+ const currentPage = parseInt(repoElement.getAttribute("data-page") || "1");+ renderRepo(repoElement, type === "snapshotprevious" ? currentPage - 1 : currentPage + 1, options.id);+ event.stopPropagation();+ event.preventDefault();+ break;+ } else if (type === "jumpSnapshotPage") {+ const totalPage = parseInt(target.getAttribute("data-totalpage") || "1");+ confirmDialog(+ window.siyuan.languages.jumpToPage.replace("${x}", totalPage),+ `<input class="b3-text-field fn__block" type="number" min="1" max="${totalPage}" value="${target.textContent}">`,+ (confirmD) => {+ const inputElement = confirmD.element.querySelector(".b3-text-field") as HTMLInputElement;+ if (inputElement.value === "") {+ return;+ }+ renderRepo(repoElement, Math.max(1, Math.min(parseInt(inputElement.value), totalPage)), options.id);});}diff --git a/app/src/history/history.ts b/app/src/history/history.tsindex 9fbb7a94bc..57b2edad1a 100644--- a/app/src/history/history.ts+++ b/app/src/history/history.ts@@ -10,13 +10,13 @@ import {fetchPost} from "../util/fetch";import {escapeAttr, escapeHtml} from "../util/escape";import {isMobile} from "../util/functions";import {showDiff} from "./diff";-import {saveExportFile, setStorageVal} from "../protyle/util/compatibility";+import {setStorageVal} from "../protyle/util/compatibility";import {openModel} from "../mobile/menu/model";import {closeModel} from "../mobile/util/closePanel";import type {App} from "../index";import {resizeSide} from "./resizeSide";import {isSupportCSSHL, searchMarkRender} from "../protyle/render/searchMarkRender";-import {pathPosix} from "../util/pathName";+import {openRepoFile, renderRepoFileList, rollbackRepoFile, saveRepoFile} from "./repoFile";let historyEditor: Protyle;@@ -269,73 +269,7 @@ ${actionHTML}};const renderRepoSearchResult = (response: IWebSocketData, element: Element) => {- if (response.data.files.length === 0) {- element.lastElementChild.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;- return;- }- let html = "";- response.data.files.forEach((item: {- fileID: string,- indexID: string,- title: string,- hPath: string,- path: string,- hSize: string,- updated: number- }) => {- /// #if MOBILE- html += `<li class="b3-list-item" data-type="searchFileItem" data-id="${item.fileID}" data-snapshot="${item.indexID}" data-created="${item.updated}">- <div class="fn__flex-1">- <div style="padding-top:8px" class="b3-list-item__text">${escapeHtml(item.title)}</div>- <div class="b3-list-item__meta">- ${item.hSize}- <span class="fn__space"></span>- ${dayjs(item.updated).format("YYYY-MM-DD HH:mm:ss")}- </div>- <div class="fn__flex" style="height: 26px">- <span class="fn__flex-1"></span>- <span class="b3-list-item__action" data-type="view">- <svg><use xlink:href="#iconEye"></use></svg>- <span class="fn__space"></span>${window.siyuan.languages.cardPreview}- </span>- <span class="fn__space"></span>- <span class="b3-list-item__action" data-type="saveAs">- <svg><use xlink:href="#iconDownload"></use></svg>- <span class="fn__space"></span>${window.siyuan.languages.saveAs}- </span>- <span class="fn__space"></span>- <span class="b3-list-item__action" data-type="rollback">- <svg><use xlink:href="#iconUndo"></use></svg>- <span class="fn__space"></span> ${window.siyuan.languages.rollback}- </span>- </div>- </div>-</li>`;- /// #else- html += `<li class="b3-list-item b3-list-item--hide-action" data-type="searchFileItem" data-id="${item.fileID}" data-snapshot="${item.indexID}" data-created="${item.updated}">- <div class="fn__flex-1">- <span class="b3-list-item__text">${escapeHtml(item.title)}</span>- <div class="b3-list-item__meta">- ${escapeHtml(item.hPath)}- <span class="fn__space"></span>- ${item.hSize}- <span class="fn__space"></span>- ${dayjs(item.updated).format("YYYY-MM-DD HH:mm:ss")}- </div>- </div>- <span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="view" aria-label="${window.siyuan.languages.cardPreview}">- <svg><use xlink:href="#iconEye"></use></svg>- </span>- <span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="saveAs" aria-label="${window.siyuan.languages.saveAs}">- <svg><use xlink:href="#iconDownload"></use></svg>- </span>- <span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="rollback" aria-label="${window.siyuan.languages.rollback}">- <svg><use xlink:href="#iconUndo"></use></svg>- </span>-</li>`;- /// #endif- });- element.lastElementChild.innerHTML = html;+ renderRepoFileList(response.data.files, element.lastElementChild, true);};const renderRepo = (element: Element, currentPage: number) => {@@ -694,6 +628,12 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {} else if (target.classList.contains("b3-list-item__action") && type === "rollback" && !window.siyuan.config.readonly) {const liElement = target.closest(".b3-list-item");const dataType = target.parentElement.getAttribute("data-type") || liElement.getAttribute("data-type");+ if (dataType === "searchFileItem") {+ rollbackRepoFile(liElement);+ event.stopPropagation();+ event.preventDefault();+ break;+ }let name;let time;if (dataType === "notebook") {@@ -702,9 +642,6 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {} else if (dataType === "repoitem") {name = window.siyuan.languages.workspaceData;time = (isMobile() ? target.parentElement.parentElement : target.parentElement).querySelector("span[data-type='hCreated']").textContent.trim();- } else if (dataType === "searchFileItem") {- name = liElement.querySelector(".b3-list-item__text").textContent.trim();- time = dayjs(parseInt(liElement.getAttribute("data-created"))).format("YYYY-MM-DD HH:mm:ss");} else {name = target.previousElementSibling.previousElementSibling.textContent.trim();time = dayjs(parseInt(target.parentElement.getAttribute("data-created")) * 1000).format("YYYY-MM-DD HH:mm:ss");@@ -728,10 +665,6 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {fetchPost("/api/history/rollbackNotebookHistory", {historyPath: target.parentElement.getAttribute("data-path")});- } else if (dataType === "searchFileItem") {- fetchPost("/api/repo/rollbackRepoSnapshotFile", {- id: liElement.getAttribute("data-id")- });} else {fetchPost("/api/repo/checkoutRepo", {id: target.parentElement.getAttribute("data-id")@@ -742,55 +675,12 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {event.preventDefault();break;} else if (type === "saveAs") {- const liElement = target.closest(".b3-list-item") as HTMLElement;- const fileId = liElement.getAttribute("data-id");- fetchPost("/api/repo/exportRepoFile", {id: fileId}, (response) => {- saveExportFile(response.data.path);- });+ saveRepoFile(target.closest(".b3-list-item"));event.stopPropagation();event.preventDefault();break;} else if (type === "view") {- const liElement = target.closest(".b3-list-item");- const snapshotId = liElement.getAttribute("data-snapshot") || "";- const dialog = new Dialog({- title: liElement.querySelector(".b3-list-item__text").textContent.trim(),- content: '<div class="b3-dialog__content"><div style="border-radius: var(--b3-border-radius-b);"></div></div>',- width: isMobile() ? "100vw" : "80vw",- height: isMobile() ? "100dvh" : "70vh",- disableAnimation: true,- });- const contentElement = dialog.element.querySelector(".b3-dialog__content");- fetchPost("/api/repo/openRepoSnapshotFile", {id: liElement.getAttribute("data-id")}, (response) => {- const type = pathPosix().extname(response.data.content).toLowerCase();- if (Constants.SIYUAN_ASSETS_IMAGE.concat(Constants.SIYUAN_ASSETS_AUDIO).concat(Constants.SIYUAN_ASSETS_VIDEO).includes(type)) {- contentElement.firstElementChild.innerHTML = renderAssetsPreview(response.data.content);- } else if (response.data.displayInText) {- contentElement.innerHTML = '<textarea readonly class="b3-text-field fn__block" style="height: 100%"></textarea>';- (contentElement.firstElementChild as HTMLTextAreaElement).value = response.data.content || response.data.title;- } else {- const viewEditor = new Protyle(app, contentElement.firstElementChild as HTMLElement, {- blockId: "",- action: [Constants.CB_GET_HISTORY],- history: {- snapshot: snapshotId- },- render: {- background: false,- gutter: false,- breadcrumb: false,- breadcrumbDocName: false,- },- typewriterMode: false- });- disabledProtyle(viewEditor.protyle);- onGet({- data: response,- protyle: viewEditor.protyle,- action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],- });- }- });+ openRepoFile(app, target.closest(".b3-list-item"));event.stopPropagation();event.preventDefault();break;diff --git a/app/src/history/repoFile.ts b/app/src/history/repoFile.tsnew file mode 100644index 0000000000..aa2c8e0168--- /dev/null+++ b/app/src/history/repoFile.ts@@ -0,0 +1,152 @@+import {renderAssetsPreview} from "../asset/renderAssets";+import {Constants} from "../constants";+import {Dialog} from "../dialog";+import {confirmDialog} from "../dialog/confirmDialog";+import type {App} from "../index";+import {Protyle} from "../protyle";+import {saveExportFile} from "../protyle/util/compatibility";+import {disabledProtyle, onGet} from "../protyle/util/onGet";+import {escapeHtml} from "../util/escape";+import {fetchPost} from "../util/fetch";+import {isMobile} from "../util/functions";+import {pathPosix} from "../util/pathName";+import * as dayjs from "dayjs";++interface IRepoFile {+ fileID: string;+ indexID: string;+ title: string;+ hPath?: string;+ hSize: string;+ updated: number;+}++export const renderRepoFileList = (files: IRepoFile[], element: Element, showPath: boolean) => {+ if (files.length === 0) {+ element.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;+ return;+ }++ let html = "";+ files.forEach((item) => {+ const pathHTML = showPath && item.hPath ? `${escapeHtml(item.hPath)}<span class="fn__space"></span>` : "";+ /// #if MOBILE+ html += `<li class="b3-list-item" data-type="searchFileItem" data-id="${item.fileID}" data-snapshot="${item.indexID}" data-created="${item.updated}">+ <div class="fn__flex-1">+ <div style="padding-top:8px" class="b3-list-item__text">${escapeHtml(item.title)}</div>+ <div class="b3-list-item__meta">+ ${item.hSize}+ <span class="fn__space"></span>+ ${dayjs(item.updated).format("YYYY-MM-DD HH:mm:ss")}+ </div>+ <div class="fn__flex" style="height: 26px">+ <span class="fn__flex-1"></span>+ <span class="b3-list-item__action" data-type="view">+ <svg><use xlink:href="#iconEye"></use></svg>+ <span class="fn__space"></span>${window.siyuan.languages.cardPreview}+ </span>+ <span class="fn__space"></span>+ <span class="b3-list-item__action" data-type="saveAs">+ <svg><use xlink:href="#iconDownload"></use></svg>+ <span class="fn__space"></span>${window.siyuan.languages.saveAs}+ </span>+ <span class="fn__space"></span>+ <span class="b3-list-item__action" data-type="rollback">+ <svg><use xlink:href="#iconUndo"></use></svg>+ <span class="fn__space"></span> ${window.siyuan.languages.rollback}+ </span>+ </div>+ </div>+</li>`;+ /// #else+ html += `<li class="b3-list-item b3-list-item--hide-action" data-type="searchFileItem" data-id="${item.fileID}" data-snapshot="${item.indexID}" data-created="${item.updated}">+ <div class="fn__flex-1">+ <span class="b3-list-item__text">${escapeHtml(item.title)}</span>+ <div class="b3-list-item__meta">+ ${pathHTML}${item.hSize}+ <span class="fn__space"></span>+ ${dayjs(item.updated).format("YYYY-MM-DD HH:mm:ss")}+ </div>+ </div>+ <span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="view" aria-label="${window.siyuan.languages.cardPreview}">+ <svg><use xlink:href="#iconEye"></use></svg>+ </span>+ <span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="saveAs" aria-label="${window.siyuan.languages.saveAs}">+ <svg><use xlink:href="#iconDownload"></use></svg>+ </span>+ <span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="rollback" aria-label="${window.siyuan.languages.rollback}">+ <svg><use xlink:href="#iconUndo"></use></svg>+ </span>+</li>`;+ /// #endif+ });+ element.innerHTML = html;+};++export const rollbackRepoFile = (element: Element) => {+ if (window.siyuan.config.readonly) {+ return;+ }++ const name = element.querySelector(".b3-list-item__text").textContent.trim();+ const time = dayjs(parseInt(element.getAttribute("data-created"))).format("YYYY-MM-DD HH:mm:ss");+ confirmDialog("⚠️ " + window.siyuan.languages.rollback,+ window.siyuan.languages.rollbackConfirm.replace("${name}", name).replace("${time}", time),+ () => {+ fetchPost("/api/repo/rollbackRepoSnapshotFile", {+ id: element.getAttribute("data-id")+ });+ });+};++export const saveRepoFile = (element: Element) => {+ fetchPost("/api/repo/exportRepoFile", {+ id: element.getAttribute("data-id")+ }, (response) => {+ saveExportFile(response.data.path);+ });+};++export const openRepoFile = (app: App, element: Element) => {+ const snapshotId = element.getAttribute("data-snapshot") || "";+ const dialog = new Dialog({+ title: element.querySelector(".b3-list-item__text").textContent.trim(),+ content: '<div class="b3-dialog__content"><div style="border-radius: var(--b3-border-radius-b);"></div></div>',+ width: isMobile() ? "100vw" : "80vw",+ height: isMobile() ? "100dvh" : "70vh",+ disableAnimation: true,+ });+ const contentElement = dialog.element.querySelector(".b3-dialog__content");+ fetchPost("/api/repo/openRepoSnapshotFile", {+ id: element.getAttribute("data-id")+ }, (response) => {+ const type = pathPosix().extname(response.data.content).toLowerCase();+ if (Constants.SIYUAN_ASSETS_IMAGE.concat(Constants.SIYUAN_ASSETS_AUDIO).concat(Constants.SIYUAN_ASSETS_VIDEO).includes(type)) {+ contentElement.firstElementChild.innerHTML = renderAssetsPreview(response.data.content);+ } else if (response.data.displayInText) {+ contentElement.innerHTML = '<textarea readonly class="b3-text-field fn__block" style="height: 100%"></textarea>';+ (contentElement.firstElementChild as HTMLTextAreaElement).value = response.data.content || response.data.title;+ } else {+ const viewEditor = new Protyle(app, contentElement.firstElementChild as HTMLElement, {+ blockId: "",+ action: [Constants.CB_GET_HISTORY],+ history: {+ snapshot: snapshotId+ },+ render: {+ background: false,+ gutter: false,+ breadcrumb: false,+ breadcrumbDocName: false,+ },+ typewriterMode: false+ });+ disabledProtyle(viewEditor.protyle);+ onGet({+ data: response,+ protyle: viewEditor.protyle,+ action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],+ });+ }+ });+};diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.tsindex 77374e5cb8..da0b552d9c 100644--- a/app/src/menus/navigation.ts+++ b/app/src/menus/navigation.ts@@ -747,7 +747,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, lif (!window.siyuan.config.readonly) {window.siyuan.menus.menu.append(new MenuItem({id: "fileHistory",- label: window.siyuan.languages.fileHistory,+ label: window.siyuan.languages.dataHistory,icon: "iconHistory",click() {openDocHistory({app, id, notebookId, pathString: name});diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.tsindex c5b5f8bafa..da0df751bb 100644--- a/app/src/protyle/header/openTitleMenu.ts+++ b/app/src/protyle/header/openTitleMenu.ts@@ -310,7 +310,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition, from: striif (!protyle.disabled) {window.siyuan.menus.menu.append(new MenuItem({id: "fileHistory",- label: window.siyuan.languages.fileHistory,+ label: window.siyuan.languages.dataHistory,icon: "iconHistory",click() {openDocHistory({diff --git a/kernel/api/repo.go b/kernel/api/repo.goindex 7234a47e55..1c70c6c5b0 100644--- a/kernel/api/repo.go+++ b/kernel/api/repo.go@@ -357,6 +357,38 @@ func searchRepoFile(c *gin.Context) {}}+func getRepoDocHistory(c *gin.Context) {+ ret := gulu.Ret.NewResult()+ defer c.JSON(http.StatusOK, ret)++ arg, ok := util.JsonArg(c, ret)+ if !ok {+ return+ }++ var id string+ var page float64+ if !util.ParseJsonArgs(arg, ret,+ util.BindJsonArg("id", &id, true, true),+ util.BindJsonArg("page", &page, true, false),+ ) || util.InvalidIDPattern(id, ret) {+ return+ }++ files, pageCount, totalCount, err := model.GetRepoDocHistory(id, int(page))+ if err != nil {+ ret.Code = -1+ ret.Msg = err.Error()+ return+ }++ ret.Data = map[string]any{+ "files": files,+ "pageCount": pageCount,+ "totalCount": totalCount,+ }+}+func exportRepoFile(c *gin.Context) {ret := gulu.Ret.NewResult()defer c.JSON(http.StatusOK, ret)diff --git a/kernel/api/router.go b/kernel/api/router.goindex 03428224b0..f8ad14c4e5 100644--- a/kernel/api/router.go+++ b/kernel/api/router.go@@ -492,6 +492,7 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/repo/checkoutRepo", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, checkoutRepo)ginServer.Handle("POST", "/api/repo/getRepoSnapshots", model.CheckAuth, model.CheckAdminRole, getRepoSnapshots)ginServer.Handle("POST", "/api/repo/searchRepoFile", model.CheckAuth, model.CheckAdminRole, searchRepoFile)+ ginServer.Handle("POST", "/api/repo/getRepoDocHistory", model.CheckAuth, model.CheckAdminRole, getRepoDocHistory)ginServer.Handle("POST", "/api/repo/getRepoTagSnapshots", model.CheckAuth, model.CheckAdminRole, getRepoTagSnapshots)ginServer.Handle("POST", "/api/repo/removeRepoTagSnapshot", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, removeRepoTagSnapshot)ginServer.Handle("POST", "/api/repo/getCloudRepoTagSnapshots", model.CheckAuth, model.CheckAdminRole, getCloudRepoTagSnapshots)@@ -501,7 +502,7 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/repo/downloadCloudSnapshot", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, downloadCloudSnapshot)ginServer.Handle("POST", "/api/repo/diffRepoSnapshots", model.CheckAuth, model.CheckAdminRole, diffRepoSnapshots)ginServer.Handle("POST", "/api/repo/openRepoSnapshotFile", model.CheckAuth, model.CheckAdminRole, openRepoSnapshotFile)- ginServer.Handle("POST", "/api/repo/rollbackRepoSnapshotFile", model.CheckAuth, model.CheckAdminRole, rollbackRepoSnapshotFile)+ ginServer.Handle("POST", "/api/repo/rollbackRepoSnapshotFile", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, rollbackRepoSnapshotFile)ginServer.Handle("POST", "/api/repo/exportRepoFile", model.CheckAuth, model.CheckAdminRole, exportRepoFile)ginServer.Handle("POST", "/api/repo/getRepoFile", model.CheckAuth, model.CheckAdminRole, getRepoFile)ginServer.Handle("POST", "/api/repo/setRepoIndexRetentionDays", model.CheckAuth, model.CheckAdminRole, setRepoIndexRetentionDays)diff --git a/kernel/go.mod b/kernel/go.modindex ca41d395df..0af3945447 100644--- a/kernel/go.mod+++ b/kernel/go.mod@@ -70,7 +70,7 @@ require (github.com/sashabaranov/go-openai v1.41.2github.com/shirou/gopsutil/v4 v4.26.6github.com/siyuan-note/dataparser v0.0.0-20260115084335-b57cb8bc7c17- github.com/siyuan-note/dejavu v0.0.0-20260728095009-fbada56e83c0+ github.com/siyuan-note/dejavu v0.0.0-20260729040332-c78b6cd83f01github.com/siyuan-note/encryption v0.0.0-20260715062728-9cb8e9548044github.com/siyuan-note/eventbus v0.0.0-20260530125927-d77c74260dcegithub.com/siyuan-note/filelock v0.0.0-20260411141728-bf44452627c0diff --git a/kernel/go.sum b/kernel/go.sumindex b0695bacb7..f4a5884973 100644--- a/kernel/go.sum+++ b/kernel/go.sum@@ -397,8 +397,8 @@ github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05Utgithub.com/simplereach/timeutils v1.2.0/go.mod h1:VVbQDfN/FHRZa1LSqcwo4kNZ62OOyqLLGQKYB3pB0Q8=github.com/siyuan-note/dataparser v0.0.0-20260115084335-b57cb8bc7c17 h1:cZbH1QcW/LWYtaKBv2i0O96qVm6HXKeEE3Z74VYdUHM=github.com/siyuan-note/dataparser v0.0.0-20260115084335-b57cb8bc7c17/go.mod h1:zE2SJ4t+2lFAeLgmhi27YtfzdyOWh3l9DXXUr9m/xU0=-github.com/siyuan-note/dejavu v0.0.0-20260728095009-fbada56e83c0 h1:AgTUMjPXgid8asx3S/d0o/2UUoadstfwh96dEcKcPog=-github.com/siyuan-note/dejavu v0.0.0-20260728095009-fbada56e83c0/go.mod h1:7yPSZX7EvgUx0Zh6FXlsXtFt3IFUq0WVMxyKRNd9STI=+github.com/siyuan-note/dejavu v0.0.0-20260729040332-c78b6cd83f01 h1:3LJ4lKSJ94mPSBNNKpTiupWfMR8IKM/6nEft5pXh1PE=+github.com/siyuan-note/dejavu v0.0.0-20260729040332-c78b6cd83f01/go.mod h1:7yPSZX7EvgUx0Zh6FXlsXtFt3IFUq0WVMxyKRNd9STI=github.com/siyuan-note/encryption v0.0.0-20260715062728-9cb8e9548044 h1:b1/Q4DSREDvGh1/NbzR9873EKrjakdoUtsNlghWxUOI=github.com/siyuan-note/encryption v0.0.0-20260715062728-9cb8e9548044/go.mod h1:t6jXpJdrXzRsdQF+XGaw35f16JVZcDyIkk5/6//ywnY=github.com/siyuan-note/eventbus v0.0.0-20260530125927-d77c74260dce h1:356bfC3pucxXuYpZIwaQ3viVCbq5RbRuvBhb4xtoBR0=diff --git a/kernel/model/repository.go b/kernel/model/repository.goindex 7c527b5de5..9b89f395b9 100644--- a/kernel/model/repository.go+++ b/kernel/model/repository.go@@ -535,6 +535,14 @@ type DiffFile struct {Updated int64 `json:"updated"`}+type RepoDocHistory struct {+ FileID string `json:"fileID"`+ IndexID string `json:"indexID"`+ Title string `json:"title"`+ HSize string `json:"hSize"`+ Updated int64 `json:"updated"`+}+type DiffIndex struct {ID string `json:"id"`Created int64 `json:"created"`@@ -782,6 +790,41 @@ func SearchRepoFile(keyword string, page int) (ret []*DiffFile, pageCount, totalreturn}+func GetRepoDocHistory(id string, page int) (ret []*RepoDocHistory, pageCount, totalCount int, err error) {+ ret = []*RepoDocHistory{}+ if 1 > len(Conf.Repo.Key) {+ err = errors.New(Conf.Language(26))+ return+ }++ repo, err := newRepository()+ if err != nil {+ return+ }++ files, fileIndexIDs, totalCount, pageCount, err := repo.SearchFileByName(id+".sy", page, 32)+ if err != nil {+ logging.LogErrorf("get repo doc history failed: %s", err)+ return+ }++ luteEngine := NewLute()+ for _, file := range files {+ title, _, parseErr := parseTitleInSnapshot(file.ID, repo, luteEngine)+ if "" == title || nil != parseErr {+ title = path.Base(file.Path)+ }+ ret = append(ret, &RepoDocHistory{+ FileID: file.ID,+ IndexID: fileIndexIDs[file.ID],+ Title: title,+ HSize: humanize.BytesCustomCeil(uint64(file.Size), 2),+ Updated: file.Updated,+ })+ }+ return+}+func ExportRepoFile(id string) (exportPath string, err error) {if 1 > len(Conf.Repo.Key) {err = errors.New(Conf.Language(26))