/** * Chunker-specific API functions. * Shared functions (getAssets, scanMediaFolder) come from common. */ import { gql } from "../../common/api/graphql"; import type { ChunkOutputFile } from "../../common/types/generated"; // Re-export shared functions export { getAssets, scanMediaFolder } from "../../common/api/media"; /** Create a chunk job via GraphQL mutation. */ export async function createChunkJob(config: { source_asset_id: string; chunk_duration: number; num_workers: number; max_retries: number; processor_type: string; start_time?: number | null; end_time?: number | null; }): Promise<{ id: string; celery_task_id: string | null }> { const data = await gql<{ create_chunk_job: { id: string; status: string; celery_task_id: string | null; }; }>( ` mutation CreateChunkJob($input: CreateChunkJobInput!) { create_chunk_job(input: $input) { id status celery_task_id } } `, { input: config }, ); return data.create_chunk_job; } /** Cancel a running chunk job. */ export async function cancelChunkJob( celeryTaskId: string, ): Promise<{ ok: boolean; message: string | null }> { const data = await gql<{ cancel_chunk_job: { ok: boolean; message: string | null }; }>( ` mutation CancelChunkJob($celery_task_id: String!) { cancel_chunk_job(celery_task_id: $celery_task_id) { ok message } } `, { celery_task_id: celeryTaskId }, ); return data.cancel_chunk_job; } /** Fetch output chunk files for a completed job. */ export async function getChunkOutputFiles( jobId: string, ): Promise { const data = await gql<{ chunk_output_files: ChunkOutputFile[]; }>( ` query ChunkOutputFiles($job_id: String!) { chunk_output_files(job_id: $job_id) { key size url } } `, { job_id: jobId }, ); return data.chunk_output_files; }