* Lists entries in a single vault directory (non-recursive). * Returns raw entries: files as names, subdirectories with trailing slash.
( baseUrl: string, accessToken: string, dirPath: string, retryOptions?: Parameters<typeof secureFetchWithRetry>[2] )
| 52 | * Returns raw entries: files as names, subdirectories with trailing slash. |
| 53 | */ |
| 54 | async function listDirectory( |
| 55 | baseUrl: string, |
| 56 | accessToken: string, |
| 57 | dirPath: string, |
| 58 | retryOptions?: Parameters<typeof secureFetchWithRetry>[2] |
| 59 | ): Promise<string[]> { |
| 60 | const encodedDir = dirPath ? dirPath.split('/').map(encodeURIComponent).join('/') : '' |
| 61 | const endpoint = encodedDir ? `${baseUrl}/vault/${encodedDir}/` : `${baseUrl}/vault/` |
| 62 | |
| 63 | const response = await secureFetchWithRetry( |
| 64 | endpoint, |
| 65 | { |
| 66 | method: 'GET', |
| 67 | headers: { |
| 68 | Authorization: `Bearer ${accessToken}`, |
| 69 | Accept: 'application/json', |
| 70 | }, |
| 71 | }, |
| 72 | retryOptions |
| 73 | ) |
| 74 | |
| 75 | if (!response.ok) { |
| 76 | throw new Error(`Obsidian API error: ${response.status} ${response.statusText}`) |
| 77 | } |
| 78 | |
| 79 | const data = (await response.json()) as { files: string[] } |
| 80 | return data.files ?? [] |
| 81 | } |
| 82 | |
| 83 | const MAX_RECURSION_DEPTH = 20 |
| 84 |
no test coverage detected