Add image listing and asset management
Show images in asset directories with preview, rename, replacement, and trash recovery. Update local Markdown references when images move and restore original files if related metadata cannot be committed. Refresh image previews after replacement and compare actual contents when deduplicating subsequent uploads.
This commit is contained in:
1 parent
8b54ccba18
commit
d253536009
25 files changed
+801
-103
No files matched your search
@@ -70,7 +70,7 @@ func TestMoveRollsBackWhenAssetDestinationIsTooLong(t *testing.T) {
|
||||
}
|
||||
// 笔记名可写入,但派生的 .assets 名超过文件系统的单段长度限制。
|
||||
destination := strings.Repeat("a", 250) + ".md"
|
||||
if _, err := v.Move("n.md", destination); err == nil {
|
||||
if _, err := v.Move("n.md", destination, nil); err == nil {
|
||||
t.Fatal("图片目录移动应失败")
|
||||
}
|
||||
if content, _, err := v.Read("n.md"); err != nil || string(content) != "原文" {
|
||||
@@ -170,7 +170,7 @@ func TestMoveCarriesAssetsAndRewritesLinks(t *testing.T) {
|
||||
if !strings.HasPrefix(link, "笔记%20A.assets/") {
|
||||
t.Fatalf("资源链接不符: %s", link)
|
||||
}
|
||||
if rewritten, err := v.Move("dir/笔记 A.md", "other/B.md"); err != nil || !rewritten {
|
||||
if rewritten, err := v.Move("dir/笔记 A.md", "other/B.md", nil); err != nil || !rewritten {
|
||||
t.Fatalf("应报告正文改写: %v %v", rewritten, err)
|
||||
}
|
||||
data, _, err := v.Read("other/B.md")
|
||||
@@ -184,7 +184,7 @@ func TestMoveCarriesAssetsAndRewritesLinks(t *testing.T) {
|
||||
if _, err := os.Stat(filepath.Join(v.Root(), "other", "B.assets", strings.TrimPrefix(link, "笔记%20A.assets/"))); err != nil {
|
||||
t.Fatal("图片目录未随笔记移动:", err)
|
||||
}
|
||||
if _, err := v.Move("other", "other/sub"); !errors.Is(err, ErrInvalidPath) {
|
||||
if _, err := v.Move("other", "other/sub", nil); !errors.Is(err, ErrInvalidPath) {
|
||||
t.Fatal("文件夹移入自身应被拒绝")
|
||||
}
|
||||
}
|
||||
@@ -221,10 +221,13 @@ func TestDeleteRestore(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTreeHidesMetaAndAssets(t *testing.T) {
|
||||
func TestTreeShowsImagesButHidesMeta(t *testing.T) {
|
||||
v := newVault(t)
|
||||
v.Write("a.md", []byte("x"), Precondition{})
|
||||
v.SaveAsset("a.md", "i.png", strings.NewReader("i"), 10)
|
||||
link, err := v.SaveAsset("a.md", "i.png", strings.NewReader("i"), 10)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v.Mkdir("folder")
|
||||
os.WriteFile(filepath.Join(v.Root(), "note.txt"), []byte("x"), 0o644)
|
||||
entries, err := v.Tree()
|
||||
@@ -235,7 +238,7 @@ func TestTreeHidesMetaAndAssets(t *testing.T) {
|
||||
for _, e := range entries {
|
||||
paths = append(paths, e.Path)
|
||||
}
|
||||
if strings.Join(paths, ",") != "a.md,folder" {
|
||||
if strings.Join(paths, ",") != "a.assets,"+link+",a.md,folder" {
|
||||
t.Fatalf("目录树不符: %v", paths)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user