feat: 素材处理管线——自动处理、审核流程、6状态机
This commit is contained in:
@@ -23,11 +23,26 @@ export function createMaterial(args: { body: CreateMaterialRequest; projectId: s
|
||||
return response.then((r) => handleResponse(r, (data) => (data as MaterialResponse).material));
|
||||
}
|
||||
|
||||
export function approveMaterial(args: { materialId: string; projectId: string }): Promise<Material> {
|
||||
const response = fetch(`/api/projects/${args.projectId}/materials/${args.materialId}/approve`, { method: "POST" });
|
||||
return response.then((r) => handleResponse(r, (data) => (data as MaterialResponse).material));
|
||||
}
|
||||
|
||||
export function deleteMaterial(args: { materialId: string; projectId: string }): Promise<void> {
|
||||
const response = fetch(`/api/projects/${args.projectId}/materials/${args.materialId}`, { method: "DELETE" });
|
||||
return response.then(handleVoidResponse);
|
||||
}
|
||||
|
||||
export function discardMaterial(args: { materialId: string; projectId: string }): Promise<Material> {
|
||||
const response = fetch(`/api/projects/${args.projectId}/materials/${args.materialId}/discard`, { method: "POST" });
|
||||
return response.then((r) => handleResponse(r, (data) => (data as MaterialResponse).material));
|
||||
}
|
||||
|
||||
export function retryMaterial(args: { materialId: string; projectId: string }): Promise<Material> {
|
||||
const response = fetch(`/api/projects/${args.projectId}/materials/${args.materialId}/retry`, { method: "POST" });
|
||||
return response.then((r) => handleResponse(r, (data) => (data as MaterialResponse).material));
|
||||
}
|
||||
|
||||
export async function fetchMaterial(args: { materialId: string; projectId: string }): Promise<Material> {
|
||||
const response = await fetch(`/api/projects/${args.projectId}/materials/${args.materialId}`);
|
||||
return handleResponse(response, (data) => (data as MaterialResponse).material);
|
||||
@@ -65,6 +80,18 @@ export function useCreateMaterial(projectId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useApproveMaterial(projectId: string) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: approveMaterial,
|
||||
onSuccess: (data) => {
|
||||
logger.info("素材通过成功", { materialId: data.id, projectId });
|
||||
void queryClient.invalidateQueries({ queryKey: [...MATERIALS_KEY, "list", projectId] });
|
||||
void queryClient.invalidateQueries({ queryKey: [...MATERIALS_KEY, "detail", projectId, data.id] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteMaterial(projectId: string) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
@@ -76,6 +103,30 @@ export function useDeleteMaterial(projectId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useDiscardMaterial(projectId: string) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: discardMaterial,
|
||||
onSuccess: (data) => {
|
||||
logger.info("素材放弃成功", { materialId: data.id, projectId });
|
||||
void queryClient.invalidateQueries({ queryKey: [...MATERIALS_KEY, "list", projectId] });
|
||||
void queryClient.invalidateQueries({ queryKey: [...MATERIALS_KEY, "detail", projectId, data.id] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useRetryMaterial(projectId: string) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: retryMaterial,
|
||||
onSuccess: (data) => {
|
||||
logger.info("素材重试成功", { materialId: data.id, projectId });
|
||||
void queryClient.invalidateQueries({ queryKey: [...MATERIALS_KEY, "list", projectId] });
|
||||
void queryClient.invalidateQueries({ queryKey: [...MATERIALS_KEY, "detail", projectId, data.id] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useMaterial(args: { materialId: null | string; projectId: string }) {
|
||||
return useQuery({
|
||||
enabled: !!args.materialId,
|
||||
|
||||
Reference in New Issue
Block a user