fix(library): ignore current library during folder prescan

Prevent an edited library from treating its own persisted folders as conflicts while preserving overlap warnings for other libraries.

Fixes #1340
This commit is contained in:
neon
2026-09-10 11:02:32 +00:00
parent 3a4d467255
commit e514be151a
7 changed files with 83 additions and 4 deletions
@@ -69,6 +69,24 @@ describe('useLibraryCreator', () => {
expect(creator.prescanResult.value).toEqual(result)
})
it('includes the current library ID when prescanning an edit', async () => {
const { useLibraryCreator } = await import('../useLibraryCreator')
const creator = useLibraryCreator()
const result: PrescanResult = { paths: [{ path: '/books', accessible: true, fileCount: 2 }], totalFiles: 2 }
apiMock.mockResolvedValue(jsonResponse(result))
creator.initEdit(makeLibrary({ id: 12 }))
await creator.runPrescan()
expect(apiMock).toHaveBeenCalledWith(
'/api/v1/libraries/prescan',
expect.objectContaining({
method: 'POST',
body: JSON.stringify({ paths: ['/books'], libraryId: 12 }),
}),
)
})
it('surfaces prescan connection failures', async () => {
const { useLibraryCreator } = await import('../useLibraryCreator')
const creator = useLibraryCreator()
@@ -141,10 +141,14 @@ export function useLibraryCreator() {
prescanResult.value = null
error.value = null
try {
const payload = {
paths: form.folders,
...(editingLibraryId.value === null ? {} : { libraryId: editingLibraryId.value }),
}
const res = await api('/api/v1/libraries/prescan', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ paths: form.folders }),
body: JSON.stringify(payload),
})
if (res.ok) {
prescanResult.value = await res.json()