Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-05-12 21:48:07 +08:00
commit e4020c31fe
7 changed files with 60 additions and 10 deletions

File diff suppressed because one or more lines are too long

View file

@ -36,6 +36,21 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func getUniqueFilename(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
filePath := arg["path"].(string)
ret.Data = map[string]interface{}{
"path": util.GetUniqueFilename(filePath),
}
}
func globalCopyFiles(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

View file

@ -208,6 +208,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/file/removeFile", model.CheckAuth, model.CheckReadonly, removeFile)
ginServer.Handle("POST", "/api/file/renameFile", model.CheckAuth, model.CheckReadonly, renameFile)
ginServer.Handle("POST", "/api/file/readDir", model.CheckAuth, readDir)
ginServer.Handle("POST", "/api/file/getUniqueFilename", model.CheckAuth, getUniqueFilename)
ginServer.Handle("POST", "/api/ref/refreshBacklink", model.CheckAuth, refreshBacklink)
ginServer.Handle("POST", "/api/ref/getBacklink", model.CheckAuth, getBacklink)

View file

@ -8,7 +8,7 @@ require (
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866
github.com/88250/lute v1.7.7-0.20240512041141-6c1f1ce0c38c
github.com/88250/lute v1.7.7-0.20240512043816-60f8b15b61d5
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4

View file

@ -12,8 +12,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866 h1:RFfNFS0hv6TbOuwET6xZAfGlV4hNlXiWTnfbLN1eF6k=
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
github.com/88250/lute v1.7.7-0.20240512041141-6c1f1ce0c38c h1:qyS4tOLwR9Ftmu7esfrBJEn98tH4vdsD9tqyXu5q050=
github.com/88250/lute v1.7.7-0.20240512041141-6c1f1ce0c38c/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/lute v1.7.7-0.20240512043816-60f8b15b61d5 h1:TzZsQ9JYThW9vnX+luaB06jYdm4WH2aq28hqsE3NXeI=
github.com/88250/lute v1.7.7-0.20240512043816-60f8b15b61d5/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -1603,6 +1603,7 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
name := strings.TrimSpace(operation.Name)
if "" == name {
name = srcAv.Name + " " + operation.Format
name = strings.TrimSpace(name)
}
destKeyValues := &av.KeyValues{
@ -1629,10 +1630,18 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
continue
}
srcKeyValues := keyValues
for _, srcVal := range srcKeyValues.Values {
for _, srcVal := range keyValues.Values {
for _, blockID := range srcVal.Relation.BlockIDs {
destVal := &av.Value{ID: ast.NewNodeID(), KeyID: destKeyValues.Key.ID, BlockID: blockID, Type: keyValues.Key.Type, Relation: &av.ValueRelation{}, CreatedAt: now, UpdatedAt: now + 1000}
destVal := destAv.GetValue(destKeyValues.Key.ID, blockID)
if nil == destVal {
destVal = &av.Value{ID: ast.NewNodeID(), KeyID: destKeyValues.Key.ID, BlockID: blockID, Type: keyValues.Key.Type, Relation: &av.ValueRelation{}, CreatedAt: now, UpdatedAt: now + 1000}
} else {
destVal.Type = keyValues.Key.Type
if nil == destVal.Relation {
destVal.Relation = &av.ValueRelation{}
}
destVal.UpdatedAt = now
}
destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, srcVal.BlockID)
destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs)
destKeyValues.Values = append(destKeyValues.Values, destVal)
@ -3227,17 +3236,23 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
// val.IsDetached 只有更新主键的时候才会传入,所以下面需要结合 isUpdatingBlockKey 来判断
if oldIsDetached { // 之前是游离行
if oldIsDetached {
// 之前是游离行
if !val.IsDetached { // 现在绑定了块
// 将游离行绑定到新建的块上
bindBlockAv(tx, avID, rowID)
}
} else { // 之前绑定了块
} else {
// 之前绑定了块
if isUpdatingBlockKey { // 正在更新主键
if val.IsDetached { // 现在是游离行
// 将绑定的块从属性视图中移除
unbindBlockAv(tx, avID, rowID)
} else { // 现在绑定了块
} else {
// 现在绑定了块
if oldBoundBlockID != val.BlockID { // 之前绑定的块和现在绑定的块不一样
// 换绑块
unbindBlockAv(tx, avID, oldBoundBlockID)

View file

@ -24,6 +24,7 @@ import (
"os"
"path"
"path/filepath"
"strconv"
"strings"
"unicode/utf8"
@ -34,6 +35,24 @@ import (
"github.com/siyuan-note/logging"
)
func GetUniqueFilename(filePath string) string {
if !gulu.File.IsExist(filePath) {
return filePath
}
ext := filepath.Ext(filePath)
base := strings.TrimSuffix(filepath.Base(filePath), ext)
dir := filepath.Dir(filePath)
i := 1
for {
newPath := filepath.Join(dir, base+" ("+strconv.Itoa(i)+")"+ext)
if !gulu.File.IsExist(newPath) {
return newPath
}
i++
}
}
func GetMimeTypeByExt(filePath string) (ret string) {
ret = mime.TypeByExtension(filepath.Ext(filePath))
if "" == ret {