coddingtonbear / obsidian-local-rest-api

Unlock your automation needs by interacting with your notes in Obsidian over a secure REST API.
MIT License
607 stars 56 forks source link

[Bug] GET /vault/ doesn't response empty folder #21

Closed kaiiiz closed 2 years ago

kaiiiz commented 2 years ago

Consider the following folder structure:

.
├── a
│   └── a.md
└── b

What I get from the server response:

image

What I expected to get from the server response:

{
  "files": [
    "a/",
    "b/"
  ]
}

The server response should include the empty folder. I consider this as a bug since I'm implementing the function that chooses which directory should be used to create a new file, so all folders in the vault should be included in the response.

OS: MacOS Monterey 12.2.1 (M1) Obsidian version: 0.14.6 Obsidian local rest API version: 1.3.5

coddingtonbear commented 2 years ago

Thanks for the very complete and well-thought-through bug report, @kaiiiz! Unfortunately, this a limitation of the API in use here -- we're building a list of possible directories by enumerating all of the files Obsidian tells us it knows about. Since an empty directory will not include any files, providing the correct REST response in such a case isn't possible. I've added an API note in b8f0c60 noting that limitation.

I'm definitely open for somebody thinking through changing which API we use, but that's a little beyond what I'm willing to put effort into for such an edge case.