114 lines
3.1 KiB
TypeScript
114 lines
3.1 KiB
TypeScript
/**
|
|
* GraphQL API client
|
|
*/
|
|
|
|
import { gql } from "../../common/api/graphql";
|
|
import { getAssets, scanMediaFolder } from "../../common/api/media";
|
|
import type {
|
|
TranscodePreset,
|
|
TranscodeJob,
|
|
CreateJobRequest,
|
|
SystemStatus,
|
|
MediaAsset,
|
|
} from "./types";
|
|
|
|
export { getAssets, scanMediaFolder };
|
|
|
|
export async function getAsset(id: string): Promise<MediaAsset> {
|
|
const data = await gql<{ asset: MediaAsset }>(`
|
|
query($id: UUID!) {
|
|
asset(id: $id) {
|
|
id filename file_path status error_message file_size duration
|
|
video_codec audio_codec width height framerate bitrate
|
|
properties comments tags created_at updated_at
|
|
}
|
|
}
|
|
`, { id });
|
|
return data.asset;
|
|
}
|
|
|
|
// Presets
|
|
export async function getPresets(): Promise<TranscodePreset[]> {
|
|
const data = await gql<{ presets: TranscodePreset[] }>(`
|
|
query {
|
|
presets {
|
|
id name description is_builtin container
|
|
video_codec video_bitrate video_crf video_preset resolution framerate
|
|
audio_codec audio_bitrate audio_channels audio_samplerate
|
|
extra_args created_at updated_at
|
|
}
|
|
}
|
|
`);
|
|
return data.presets;
|
|
}
|
|
|
|
// Jobs
|
|
export async function getJobs(): Promise<TranscodeJob[]> {
|
|
const data = await gql<{ jobs: TranscodeJob[] }>(`
|
|
query {
|
|
jobs {
|
|
id source_asset_id preset_id preset_snapshot trim_start trim_end
|
|
output_filename output_path output_asset_id status progress
|
|
current_frame current_time speed error_message celery_task_id
|
|
execution_arn priority created_at started_at completed_at
|
|
}
|
|
}
|
|
`);
|
|
return data.jobs;
|
|
}
|
|
|
|
export async function getJob(id: string): Promise<TranscodeJob> {
|
|
const data = await gql<{ job: TranscodeJob }>(`
|
|
query($id: UUID!) {
|
|
job(id: $id) {
|
|
id source_asset_id preset_id preset_snapshot trim_start trim_end
|
|
output_filename output_path output_asset_id status progress
|
|
current_frame current_time speed error_message celery_task_id
|
|
execution_arn priority created_at started_at completed_at
|
|
}
|
|
}
|
|
`, { id });
|
|
return data.job;
|
|
}
|
|
|
|
export async function createJob(req: CreateJobRequest): Promise<TranscodeJob> {
|
|
const data = await gql<{ create_job: TranscodeJob }>(`
|
|
mutation($input: CreateJobInput!) {
|
|
create_job(input: $input) {
|
|
id source_asset_id status output_filename progress created_at
|
|
}
|
|
}
|
|
`, {
|
|
input: {
|
|
source_asset_id: req.source_asset_id,
|
|
preset_id: req.preset_id,
|
|
trim_start: req.trim_start,
|
|
trim_end: req.trim_end,
|
|
output_filename: req.output_filename ?? null,
|
|
priority: req.priority ?? 0,
|
|
},
|
|
});
|
|
return data.create_job;
|
|
}
|
|
|
|
export async function cancelJob(id: string): Promise<TranscodeJob> {
|
|
const data = await gql<{ cancel_job: TranscodeJob }>(`
|
|
mutation($id: UUID!) {
|
|
cancel_job(id: $id) {
|
|
id status
|
|
}
|
|
}
|
|
`, { id });
|
|
return data.cancel_job;
|
|
}
|
|
|
|
// System
|
|
export async function getSystemStatus(): Promise<SystemStatus> {
|
|
const data = await gql<{ system_status: SystemStatus }>(`
|
|
query {
|
|
system_status { status version }
|
|
}
|
|
`);
|
|
return data.system_status;
|
|
}
|