Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
e2fe854777
11 changed files with 78 additions and 22 deletions
|
@ -39,7 +39,7 @@ func main() {
|
|||
|
||||
model.BootSyncData()
|
||||
model.InitBoxes()
|
||||
model.InitFlashcards()
|
||||
model.LoadFlashcards()
|
||||
model.LoadAssetsTexts()
|
||||
|
||||
go model.AutoGenerateDocHistory()
|
||||
|
|
|
@ -53,7 +53,7 @@ func StartKernel(container, appDir, workspaceBaseDir, timezoneID, localIPs, lang
|
|||
|
||||
model.BootSyncData()
|
||||
model.InitBoxes()
|
||||
model.InitFlashcards()
|
||||
model.LoadFlashcards()
|
||||
model.LoadAssetsTexts()
|
||||
|
||||
go model.AutoGenerateDocHistory()
|
||||
|
|
|
@ -176,7 +176,7 @@ func NetImg2LocalAssets(rootID string) (err error) {
|
|||
}
|
||||
}
|
||||
name = strings.TrimSuffix(name, ext)
|
||||
name = gulu.Str.SubStr(name, 63) // 插入资源文件时文件名长度最大限制 189 字节 https://github.com/siyuan-note/siyuan/issues/7099
|
||||
name = gulu.Str.SubStr(name, 63) // 插入资源文件时文件名长度最大限制 63 个字 https://github.com/siyuan-note/siyuan/issues/7099
|
||||
name = util.FilterFileName(name)
|
||||
name = "net-img-" + name + "-" + ast.NewNodeID() + ext
|
||||
writePath := filepath.Join(assetsDirPath, name)
|
||||
|
|
|
@ -523,7 +523,7 @@ func FullReindex() {
|
|||
}
|
||||
IndexRefs()
|
||||
treenode.SaveBlockTree(true)
|
||||
InitFlashcards()
|
||||
LoadFlashcards()
|
||||
|
||||
util.PushEndlessProgress(Conf.Language(58))
|
||||
isFullReindexing = false
|
||||
|
|
|
@ -359,7 +359,7 @@ func AddFlashcards(deckID string, blockIDs []string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func InitFlashcards() {
|
||||
func LoadFlashcards() {
|
||||
riffSavePath := getRiffDir()
|
||||
if err := os.MkdirAll(riffSavePath, 0755); nil != err {
|
||||
logging.LogErrorf("create riff dir [%s] failed: %s", riffSavePath, err)
|
||||
|
@ -445,7 +445,7 @@ func RemoveDeck(deckID string) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
InitFlashcards()
|
||||
LoadFlashcards()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -501,6 +501,8 @@ func InitRepoKey() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var isCheckoutRepo bool
|
||||
|
||||
func CheckoutRepo(id string) (err error) {
|
||||
if 1 > len(Conf.Repo.Key) {
|
||||
err = errors.New(Conf.Language(26))
|
||||
|
@ -523,6 +525,16 @@ func CheckoutRepo(id string) (err error) {
|
|||
Conf.Sync.Enabled = false
|
||||
Conf.Save()
|
||||
|
||||
if util.IsMutexLocked(&syncLock) {
|
||||
err = errors.New("sync is running, please try again later")
|
||||
return
|
||||
}
|
||||
|
||||
isCheckoutRepo = true
|
||||
defer func() {
|
||||
isCheckoutRepo = false
|
||||
}()
|
||||
|
||||
_, _, err = repo.Checkout(id, map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress})
|
||||
if nil != err {
|
||||
util.PushClearProgress()
|
||||
|
@ -977,13 +989,17 @@ func syncRepo(exit, byHand bool) (err error) {
|
|||
// 有数据变更,需要重建索引
|
||||
var upserts, removes []string
|
||||
var upsertTrees int
|
||||
var needReloadFlashcard bool
|
||||
var needReloadFlashcard, needReloadOcrTexts bool
|
||||
for _, file := range mergeResult.Upserts {
|
||||
upserts = append(upserts, file.Path)
|
||||
if strings.HasPrefix(file.Path, "/storage/riff/") {
|
||||
needReloadFlashcard = true
|
||||
}
|
||||
|
||||
if strings.HasPrefix(file.Path, "/data/assets/ocr-texts.json") {
|
||||
needReloadOcrTexts = true
|
||||
}
|
||||
|
||||
if strings.HasSuffix(file.Path, ".sy") {
|
||||
upsertTrees++
|
||||
}
|
||||
|
@ -993,10 +1009,18 @@ func syncRepo(exit, byHand bool) (err error) {
|
|||
if strings.HasPrefix(file.Path, "/storage/riff/") {
|
||||
needReloadFlashcard = true
|
||||
}
|
||||
|
||||
if strings.HasPrefix(file.Path, "/data/assets/ocr-texts.json") {
|
||||
needReloadOcrTexts = true
|
||||
}
|
||||
}
|
||||
|
||||
if needReloadFlashcard {
|
||||
InitFlashcards()
|
||||
LoadFlashcards()
|
||||
}
|
||||
|
||||
if needReloadOcrTexts {
|
||||
LoadAssetsTexts()
|
||||
}
|
||||
|
||||
cache.ClearDocsIAL() // 同步后文档树文档图标没有更新 https://github.com/siyuan-note/siyuan/issues/4939
|
||||
|
|
|
@ -1244,6 +1244,11 @@ func autoFixIndex() {
|
|||
return
|
||||
}
|
||||
|
||||
if isCheckoutRepo {
|
||||
logging.LogInfof("skip check index caused by checkout repo")
|
||||
return
|
||||
}
|
||||
|
||||
if util.IsMutexLocked(&autoFixLock) {
|
||||
return
|
||||
}
|
||||
|
@ -1286,6 +1291,12 @@ func autoFixIndex() {
|
|||
break
|
||||
}
|
||||
|
||||
id := path.Base(p)
|
||||
id = strings.TrimSuffix(id, ".sy")
|
||||
if !ast.IsNodeIDPattern(id) {
|
||||
continue
|
||||
}
|
||||
|
||||
reindexTreeByPath(box.ID, p, i, size)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -342,8 +342,7 @@ func buildRef(tree *parse.Tree, refNode *ast.Node) *Ref {
|
|||
}
|
||||
|
||||
func buildEmbedRef(tree *parse.Tree, embedNode *ast.Node) *Ref {
|
||||
markdown := treenode.ExportNodeStdMd(embedNode, luteEngine)
|
||||
defBlockID, text := getEmbedRef(embedNode)
|
||||
defBlockID := getEmbedRef(embedNode)
|
||||
var defBlockParentID, defBlockRootID, defBlockPath string
|
||||
defBlock := treenode.GetBlockTree(defBlockID)
|
||||
if nil != defBlock {
|
||||
|
@ -362,19 +361,14 @@ func buildEmbedRef(tree *parse.Tree, embedNode *ast.Node) *Ref {
|
|||
RootID: tree.ID,
|
||||
Box: tree.Box,
|
||||
Path: tree.Path,
|
||||
Content: text,
|
||||
Markdown: markdown,
|
||||
Content: "",
|
||||
Markdown: "",
|
||||
Type: treenode.TypeAbbr(embedNode.Type.String()),
|
||||
}
|
||||
}
|
||||
|
||||
func getEmbedRef(embedNode *ast.Node) (queryBlockID, refText string) {
|
||||
func getEmbedRef(embedNode *ast.Node) (queryBlockID string) {
|
||||
queryBlockID = treenode.GetEmbedBlockRef(embedNode)
|
||||
if "" == queryBlockID {
|
||||
return
|
||||
}
|
||||
|
||||
refText = getRefText(queryBlockID)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ func FilterUploadFileName(name string) string {
|
|||
ret = strings.ReplaceAll(ret, "#", "")
|
||||
ret = strings.ReplaceAll(ret, "%", "")
|
||||
ret = strings.ReplaceAll(ret, "$", "")
|
||||
// 插入资源文件时文件名长度最大限制 189 字节 https://github.com/siyuan-note/siyuan/issues/7099
|
||||
// 插入资源文件时文件名长度最大限制 63 个字 https://github.com/siyuan-note/siyuan/issues/7099
|
||||
ret = gulu.Str.SubStr(ret, 63)
|
||||
return ret
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/88250/lute/html"
|
||||
)
|
||||
|
@ -39,3 +41,30 @@ func Reverse(s string) string {
|
|||
}
|
||||
return string(runes)
|
||||
}
|
||||
|
||||
func RemoveRedundantSpace(str string) string {
|
||||
buf := bytes.Buffer{}
|
||||
lastIsChinese := false
|
||||
lastIsSpace := false
|
||||
for _, r := range str {
|
||||
if unicode.IsSpace(r) {
|
||||
if lastIsChinese || lastIsSpace {
|
||||
continue
|
||||
}
|
||||
buf.WriteRune(' ')
|
||||
lastIsChinese = false
|
||||
lastIsSpace = true
|
||||
continue
|
||||
}
|
||||
|
||||
lastIsSpace = false
|
||||
buf.WriteRune(r)
|
||||
if unicode.Is(unicode.Han, r) {
|
||||
lastIsChinese = true
|
||||
continue
|
||||
} else {
|
||||
lastIsChinese = false
|
||||
}
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -90,8 +89,7 @@ func Tesseract(imgAbsPath string) string {
|
|||
|
||||
ret := string(output)
|
||||
ret = gulu.Str.RemoveInvisible(ret)
|
||||
reg := regexp.MustCompile("\\s{2,}")
|
||||
ret = reg.ReplaceAllString(ret, " ")
|
||||
ret = RemoveRedundantSpace(ret)
|
||||
msg := fmt.Sprintf("OCR [%s] [%s]", info.Name(), ret)
|
||||
PushStatusBar(msg)
|
||||
return ret
|
||||
|
|
Loading…
Add table
Reference in a new issue