- provider_configs: add id TEXT PK; migrate existing rows (provider_type becomes id)
- local_files_index: add provider_id column + index; scope all queries per instance
- ProviderConfigRow: add id field; add get_by_id to trait
- LocalIndex:🆕 add provider_id param; all SQL scoped by provider_id
- factory: thread provider_id through build_local_files_bundle
- AppState.local_index: Option<Arc<LocalIndex>> → HashMap<String, Arc<LocalIndex>>
- admin_providers: restructured routes (POST /admin/providers create, PUT/DELETE /{id}, POST /test)
- admin_providers: use row.id as registry key for jellyfin and local_files
- files.rescan: optional ?provider=<id> query param
- frontend: add id to ProviderConfig, update api/hooks, new multi-instance panel UX
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
"use client";
|
|
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { api } from "@/lib/api";
|
|
import { useAuthContext } from "@/context/auth-context";
|
|
|
|
export function useProviderConfigs() {
|
|
const { token } = useAuthContext();
|
|
return useQuery({
|
|
queryKey: ["admin", "providers"],
|
|
queryFn: () => api.admin.providers.getProviders(token!),
|
|
enabled: !!token,
|
|
});
|
|
}
|
|
|
|
export function useCreateProvider() {
|
|
const { token } = useAuthContext();
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (payload: {
|
|
id: string;
|
|
provider_type: string;
|
|
config_json: Record<string, string>;
|
|
enabled: boolean;
|
|
}) => api.admin.providers.createProvider(token!, payload),
|
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["admin", "providers"] }),
|
|
});
|
|
}
|
|
|
|
export function useUpdateProvider() {
|
|
const { token } = useAuthContext();
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({
|
|
id,
|
|
payload,
|
|
}: {
|
|
id: string;
|
|
payload: { config_json: Record<string, string>; enabled: boolean };
|
|
}) => api.admin.providers.updateProvider(token!, id, payload),
|
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["admin", "providers"] }),
|
|
});
|
|
}
|
|
|
|
export function useDeleteProvider() {
|
|
const { token } = useAuthContext();
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (id: string) =>
|
|
api.admin.providers.deleteProvider(token!, id),
|
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["admin", "providers"] }),
|
|
});
|
|
}
|
|
|
|
export function useTestProvider() {
|
|
const { token } = useAuthContext();
|
|
return useMutation({
|
|
mutationFn: (payload: {
|
|
provider_type: string;
|
|
config_json: Record<string, string>;
|
|
}) => api.admin.providers.testProvider(token!, payload),
|
|
});
|
|
}
|