mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-11-05 14:53:38 -05:00
- Add ReactComponent export to *.svg module declarations - Fix SdPath imports to use generated types (device_slug, Cloud/Sidecar variants) - Create useJobs barrel file for JobManager hooks - Remove unused imports across ~65 files - Add type annotations for implicit any params (d3, callbacks, map iterators) - Remove stale @ts-expect-error directives in MeshViewer - Add declare module for gaussian-splats-3d and qrcode - Fix Location field names (path→sd_path, total_file_count→file_count, etc) - Fix SdPath discriminated union narrowing (remove stale Local variant) - Fix React 19 RefObject<T|null> vs RefObject<T> mismatches - Fix null vs undefined mismatches throughout - Add missing required fields to ApplyTagsInput, policy types, etc
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import {useLibraryMutation} from "../contexts/SpacedriveContext";
|
|
|
|
export interface JobConfig {
|
|
job_type: "thumbnail" | "ocr" | "speech_to_text" | "thumbstrip" | "proxy";
|
|
file_ids: string[];
|
|
params?: Record<string, any>;
|
|
}
|
|
|
|
/**
|
|
* Hook for dispatching media processing jobs from the context menu
|
|
*
|
|
* Provides a simple interface to trigger thumbnail generation, OCR,
|
|
* speech-to-text transcription, thumbstrip generation, and proxy creation.
|
|
*
|
|
* @example
|
|
* ```tsx
|
|
* const { runJob, isDispatching } = useJobDispatch();
|
|
*
|
|
* // Generate thumbnails with blurhash
|
|
* await runJob("thumbnail", {
|
|
* file_ids: [file.id],
|
|
* generate_blurhash: true
|
|
* });
|
|
*
|
|
* // Run OCR on images
|
|
* await runJob("ocr", {
|
|
* file_ids: selectedFiles.map(f => f.id)
|
|
* });
|
|
* ```
|
|
*/
|
|
export function useJobDispatch() {
|
|
const dispatchJob = useLibraryMutation("jobs.dispatch" as any);
|
|
|
|
const runJob = async (jobType: string, params: any) => {
|
|
try {
|
|
console.log(`Dispatching ${jobType} job:`, params);
|
|
const result = await dispatchJob.mutateAsync({
|
|
job_type: jobType,
|
|
...params,
|
|
});
|
|
|
|
console.log(`${jobType} job dispatched:`, result);
|
|
|
|
// TODO: Show toast notification
|
|
// toast.success(`${jobType} job started`);
|
|
|
|
return result;
|
|
} catch (err) {
|
|
console.error(`Failed to dispatch ${jobType} job:`, err);
|
|
// TODO: Show error toast
|
|
// toast.error(`Failed to start ${jobType} job`);
|
|
throw err;
|
|
}
|
|
};
|
|
|
|
return {runJob, isDispatching: dispatchJob.isPending};
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|