Files
k-photos/k-photos-frontend/hooks/use-storage-admin.ts
Gabriel Kaszewski 957737ac9b feat: frontend MVP — auth, timeline, upload, albums, admin, image viewer
Backend:
- user roles (DB + JWT + first-user-is-admin)
- volume-aware file resolver (multi-volume asset serving)
- directory scanner uses volume URI directly
- date-summary endpoint (capture date from EXIF)
- timeline ordered by capture date
- list endpoints: volumes, plugins, pipelines, library paths
- delete endpoints: volumes, library paths
- configurable upload body limit (MAX_UPLOAD_BYTES)

Frontend:
- auth: login/register, token refresh, role-based admin gate
- timeline: date-grouped grid, infinite scroll, date scrubber
- image viewer: fullscreen zoom/pan/pinch, metadata sidebar
- upload: drag-drop, sequential upload, progress tracking
- albums: create, add/remove photos, asset picker dialog
- admin: storage (import library), jobs (pagination, error details),
  plugins (list + toggle), pipelines, sidecars, duplicates
- multi-select mode with add-to-album action
- TanStack Query for all data fetching
2026-06-01 01:35:43 +02:00

84 lines
2.1 KiB
TypeScript

"use client"
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"
import api from "@/lib/api"
import type { VolumeResponse, LibraryPathResponse } from "@/lib/types"
export function useVolumes() {
return useQuery({
queryKey: ["admin", "volumes"],
queryFn: async () => {
const { data } = await api.get<VolumeResponse[]>("/storage/volumes")
return data
},
})
}
export function useRegisterVolume() {
const qc = useQueryClient()
return useMutation({
mutationFn: async (body: {
volume_name: string
uri_prefix: string
is_writable: boolean
}) => {
const { data } = await api.post<VolumeResponse>("/storage/volumes", body)
return data
},
onSuccess: () => qc.invalidateQueries({ queryKey: ["admin", "volumes"] }),
})
}
export function useDeleteVolume() {
const qc = useQueryClient()
return useMutation({
mutationFn: async (id: string) => {
await api.delete(`/storage/volumes/${id}`)
},
onSuccess: () => qc.invalidateQueries({ queryKey: ["admin", "volumes"] }),
})
}
export function useLibraryPaths() {
return useQuery({
queryKey: ["admin", "library-paths"],
queryFn: async () => {
const { data } = await api.get<LibraryPathResponse[]>(
"/storage/library-paths/all",
)
return data
},
})
}
export function useRegisterLibraryPath() {
const qc = useQueryClient()
return useMutation({
mutationFn: async (body: {
volume_id: string
relative_path: string
owner_id: string
is_ingest_destination: boolean
}) => {
const { data } = await api.post<LibraryPathResponse>(
"/storage/library-paths",
body,
)
return data
},
onSuccess: () =>
qc.invalidateQueries({ queryKey: ["admin", "library-paths"] }),
})
}
export function useDeleteLibraryPath() {
const qc = useQueryClient()
return useMutation({
mutationFn: async (id: string) => {
await api.delete(`/storage/library-paths/${id}`)
},
onSuccess: () =>
qc.invalidateQueries({ queryKey: ["admin", "library-paths"] }),
})
}