mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-07-03 14:09:06 +02:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -76,7 +76,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
|
||||
disabledProtyle(rightEditor.protyle);
|
||||
}
|
||||
|
||||
fetchPost("/api/repo/openRepoSnapshotDoc", {id: element.getAttribute("data-id")}, (response) => {
|
||||
fetchPost("/api/repo/openRepoSnapshotFile", {id: element.getAttribute("data-id")}, (response) => {
|
||||
leftElement.classList.remove("fn__none");
|
||||
const textElement = leftElement.querySelector("textarea");
|
||||
const type = pathPosix().extname(response.data.content).toLowerCase();
|
||||
@@ -108,7 +108,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
|
||||
const id2 = element.getAttribute("data-id2");
|
||||
if (id2) {
|
||||
rightElement.classList.remove("fn__none");
|
||||
fetchPost("/api/repo/openRepoSnapshotDoc", {id: id2}, (response) => {
|
||||
fetchPost("/api/repo/openRepoSnapshotFile", {id: id2}, (response) => {
|
||||
const textElement = rightElement.querySelector("textarea");
|
||||
const type = pathPosix().extname(response.data.content).toLowerCase();
|
||||
const titleElement = rightElement.querySelector(".protyle-title__input");
|
||||
|
||||
+25
-2
@@ -107,7 +107,7 @@ func getRepoFile(c *gin.Context) {
|
||||
c.Data(http.StatusOK, contentType, data)
|
||||
}
|
||||
|
||||
func openRepoSnapshotDoc(c *gin.Context) {
|
||||
func rollbackRepoSnapshotFile(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
@@ -120,7 +120,30 @@ func openRepoSnapshotDoc(c *gin.Context) {
|
||||
if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("id", true, &id)) {
|
||||
return
|
||||
}
|
||||
title, content, displayInText, updated, err := model.OpenRepoSnapshotDoc(id)
|
||||
|
||||
err := model.RollbackRepoSnapshotFile(id)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func openRepoSnapshotFile(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
|
||||
if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("id", true, &id)) {
|
||||
return
|
||||
}
|
||||
|
||||
title, content, displayInText, updated, err := model.OpenRepoSnapshotFile(id)
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
||||
@@ -438,7 +438,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||
ginServer.Handle("POST", "/api/repo/uploadCloudSnapshot", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, uploadCloudSnapshot)
|
||||
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/openRepoSnapshotDoc", model.CheckAuth, model.CheckAdminRole, openRepoSnapshotDoc)
|
||||
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/getRepoFile", model.CheckAuth, model.CheckAdminRole, getRepoFile)
|
||||
ginServer.Handle("POST", "/api/repo/setRepoIndexRetentionDays", model.CheckAuth, model.CheckAdminRole, setRepoIndexRetentionDays)
|
||||
ginServer.Handle("POST", "/api/repo/setRetentionIndexesDaily", model.CheckAuth, model.CheckAdminRole, setRetentionIndexesDaily)
|
||||
|
||||
@@ -51,9 +51,11 @@ import (
|
||||
"github.com/siyuan-note/dejavu/entity"
|
||||
"github.com/siyuan-note/encryption"
|
||||
"github.com/siyuan-note/eventbus"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/task"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
@@ -186,7 +188,87 @@ func GetRepoFile(fileID string) (ret []byte, p string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func OpenRepoSnapshotDoc(fileID string) (title, content string, displayInText bool, updated int64, err error) {
|
||||
func RollbackRepoSnapshotFile(fileID string) (err error) {
|
||||
if 1 > len(Conf.Repo.Key) {
|
||||
err = errors.New(Conf.Language(26))
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
file, err := repo.GetFile(fileID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := repo.OpenFile(file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
dir, f := filepath.Split(file.Path)
|
||||
tempRepoDiffDir := filepath.Join(util.TempDir, "repo", "rollback", dir)
|
||||
if err = os.MkdirAll(tempRepoDiffDir, 0755); nil != err {
|
||||
logging.LogErrorf("mkdir [%s] failed: %v", tempRepoDiffDir, err)
|
||||
return
|
||||
}
|
||||
|
||||
from := filepath.Join(tempRepoDiffDir, f)
|
||||
if err = os.WriteFile(from, data, 0644); nil != err {
|
||||
logging.LogErrorf("write file [%s] failed: %v", filepath.Join(tempRepoDiffDir, file.Path), err)
|
||||
return
|
||||
}
|
||||
|
||||
to := filepath.Join(util.DataDir, file.Path)
|
||||
if err = filelock.CopyNewtimes(from, to); nil != err {
|
||||
logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
|
||||
return
|
||||
}
|
||||
|
||||
if strings.HasSuffix(file.Path, ".sy") {
|
||||
var destPath, parentHPath string
|
||||
rootID := util.GetTreeID(file.Path)
|
||||
workingDoc := treenode.GetBlockTree(rootID)
|
||||
boxID := strings.TrimPrefix(file.Path, "/")
|
||||
boxID = strings.Split(boxID, "/")[0]
|
||||
destPath, parentHPath, err = getRollbackDockPath(boxID, file.Path, workingDoc)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
tree, _ := loadTree(to, util.NewLute())
|
||||
if nil == tree {
|
||||
msg := fmt.Sprintf("no such file or directory: %s", to)
|
||||
logging.LogErrorf(msg)
|
||||
err = errors.New(msg)
|
||||
return
|
||||
}
|
||||
|
||||
tree.Box = boxID
|
||||
tree.Path = filepath.ToSlash(strings.TrimPrefix(destPath, util.DataDir+string(os.PathSeparator)+boxID))
|
||||
tree.HPath = parentHPath + "/" + tree.Root.IALAttr("title")
|
||||
|
||||
if nil != workingDoc {
|
||||
treenode.RemoveBlockTreesByRootID(rootID)
|
||||
}
|
||||
|
||||
sql.RemoveTreeQueue(rootID)
|
||||
if writeErr := indexWriteTreeIndexQueue(tree); nil != writeErr {
|
||||
return
|
||||
}
|
||||
ReloadFiletree()
|
||||
ReloadProtyle(rootID)
|
||||
}
|
||||
|
||||
IncSync()
|
||||
util.PushMsg(Conf.Language(102), 3000)
|
||||
return
|
||||
}
|
||||
|
||||
func OpenRepoSnapshotFile(fileID string) (title, content string, displayInText bool, updated int64, err error) {
|
||||
if 1 > len(Conf.Repo.Key) {
|
||||
err = errors.New(Conf.Language(26))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user