feat: watcher source-root resolution, folder rename, alt-drag copy

Three small phase-11 follow-ups in one commit since they all touch the
same surface area.

1. Watcher source-root resolution
   The watch_folders task previously called scan_folder.delay(parent_dir)
   when files arrived, with no source_root_id. scan_folder would then
   auto-create a fresh SourceRoot for that arbitrary subdir, polluting
   the source_root list. Now the watcher loads (path, id) pairs at
   startup, defines find_source_root_for() that walks the parent chain,
   and dispatches with the resolved id. Events under no known root are
   logged at debug and ignored instead of creating stale rows.

2. Folder rename via UI
   - Backend: PATCH /folders/{id} accepts { name } and updates the
     SourceRoot display label only. The on-disk path is controlled by
     the docker mount and intentionally not editable from the UI.
   - Frontend: double-click a folder row in the LeftSidebar to start
     editing; Enter or blur commits, Esc reverts. New renamingId /
     renameDraft local state and a renameMutation that invalidates
     ['folders']. The click handler ignores clicks while the row is
     in edit mode so it doesn't navigate.
   - api.ts: new sourceFolders.rename(id, name) helper.

3. Bulk copy via Alt-drag onto folder
   - Backend: new POST /photos/copy that mirrors /photos/move but uses
     shutil.copy2 and creates fresh Photo rows with is_duplicate=true.
     Name collisions are resolved by appending " (copy)", " (copy 2)",
     etc., up to 100 tries before erroring. Same target_id resolution
     as /move (folder id or source root id).
   - Frontend: photos.copy(ids, targetId) helper. LeftSidebar's
     handleDrop now takes a `copy` flag derived from e.altKey on the
     drop event; folder targets dispatch copyDropMutation when held,
     moveDropMutation otherwise. The drop-effect cursor flips to
     'copy' on dragover when Alt is pressed so the user gets visual
     confirmation. Discard target ignores the modifier.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-08 00:58:49 +02:00
parent a8750afef0
commit 63383ecf1c
5 changed files with 290 additions and 24 deletions

View File

@@ -10,7 +10,8 @@ const api = axios.create({
})
// Source Folders API. Source roots are config-driven now (PHOTO_DIRS in
// .env → bootstrap on backend startup), so the UI only reads them.
// .env → bootstrap on backend startup), so the UI only reads them and
// optionally renames the display label.
export const sourceFolders = {
list: async () => {
const response = await api.get('/folders')
@@ -21,6 +22,13 @@ export const sourceFolders = {
const response = await api.post(`/folders/${folderId}/scan`)
return response.data
},
/** Rename the display label only — the on-disk path is controlled by
* the docker mount and cannot be changed from the UI. */
rename: async (folderId: string, name: string) => {
const response = await api.patch(`/folders/${folderId}`, { name })
return response.data
},
}
// Photos API
@@ -84,6 +92,16 @@ export const photos = {
return response.data as { status: string; moved: number; errors: Array<{ id: string; error: string }> }
},
/** Copy photos into a target folder. Originals are unaffected; new
* rows are created with is_duplicate=true. */
copy: async (photoIds: string[], targetId: string) => {
const response = await api.post('/photos/copy', {
photo_ids: photoIds,
target_id: targetId,
})
return response.data as { status: string; copied: number; errors: Array<{ id: string; error: string }> }
},
getThumbnailUrl: (photoId: string, size: 'small' | 'medium' | 'large' = 'medium') => {
return `${API_BASE_URL}/photos/${photoId}/thumb/${size}`
},