diff --git a/kernel/mobile/kernel.go b/kernel/mobile/kernel.go index 4906a3ab8..05b88cca6 100644 --- a/kernel/mobile/kernel.go +++ b/kernel/mobile/kernel.go @@ -279,3 +279,15 @@ func SetTimezone(container, appDir, timezoneID string) { func DisableFeature(feature string) { util.DisableFeature(feature) } + +func FilepathBase(path string) string { + return filepath.Base(path) +} + +func FilterUploadFileName(name string) string { + return util.FilterUploadFileName(name) +} + +func AssetName(name string) string { + return util.AssetName(name) +} diff --git a/kernel/model/shortcuts.go b/kernel/model/shortcuts.go index 53dd42037..9bcc81fbe 100644 --- a/kernel/model/shortcuts.go +++ b/kernel/model/shortcuts.go @@ -41,9 +41,28 @@ func MoveLocalShorthands(boxID, hPath, parentID, id string) (retID string, err e buff := bytes.Buffer{} var toRemoves []string + assetsDir := filepath.Join(util.DataDir, "assets") for _, entry := range entries { if entry.IsDir() { - continue + if "assets" == entry.Name() { + assetsEntries, readErr := os.ReadDir(filepath.Join(shorthandsDir, entry.Name())) + if nil != readErr { + logging.LogErrorf("read dir [%s] failed: %s", shorthandsDir, readErr) + continue + } + for _, assetEntry := range assetsEntries { + if assetEntry.IsDir() { + continue + } + + p := filepath.Join(shorthandsDir, entry.Name(), assetEntry.Name()) + assetWritePath := filepath.Join(assetsDir, assetEntry.Name()) + if renameErr := os.Rename(p, assetWritePath); nil != renameErr { + logging.LogErrorf("rename file [%s] to [%s] failed: %s", p, assetWritePath, renameErr) + continue + } + } + } } if filepath.Ext(entry.Name()) != ".md" { @@ -59,7 +78,6 @@ func MoveLocalShorthands(boxID, hPath, parentID, id string) (retID string, err e buff.Write(bytes.TrimSpace(data)) buff.WriteString("\n\n") - logging.LogInfof("read shorthand [%s] content [%s]", p, data) toRemoves = append(toRemoves, p) } @@ -77,8 +95,6 @@ func MoveLocalShorthands(boxID, hPath, parentID, id string) (retID string, err e return } - logging.LogInfof("shorthand content [%s]", content) - retID, err = CreateWithMarkdown("", boxID, hPath, content, parentID, id, false, "") if nil != err { logging.LogErrorf("create doc failed: %s", err)