Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/cms/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,12 @@ enum ENUM_KEYWORD_SOURCE {
manager
}

enum ENUM_KEYWORD_TYPE {
keyword
speaker
topic
}

enum ENUM_LANGUAGEAUDIOPREVIEW_SOURCE {
core
manager
Expand Down Expand Up @@ -1413,6 +1419,7 @@ type EnrichmentJob {
languages: JSON
muxAssetId: String!
muxPlaybackId: String
options: JSON
publishedAt: DateTime
retries: Int
startedAt: DateTime
Expand Down Expand Up @@ -1466,6 +1473,7 @@ input EnrichmentJobInput {
languages: JSON
muxAssetId: String
muxPlaybackId: String
options: JSON
publishedAt: DateTime
retries: Int
startedAt: DateTime
Expand Down Expand Up @@ -1724,6 +1732,7 @@ type Keyword {
language: Language
publishedAt: DateTime
source: ENUM_KEYWORD_SOURCE!
type: ENUM_KEYWORD_TYPE
updatedAt: DateTime
value: String
videos(filters: VideoFiltersInput, pagination: PaginationArg = {}, sort: [String] = []): [Video]!
Expand Down Expand Up @@ -1754,6 +1763,7 @@ input KeywordFiltersInput {
or: [KeywordFiltersInput]
publishedAt: DateTimeFilterInput
source: StringFilterInput
type: StringFilterInput
updatedAt: DateTimeFilterInput
value: StringFilterInput
videos: VideoFiltersInput
Expand All @@ -1764,6 +1774,7 @@ input KeywordInput {
language: ID
publishedAt: DateTime
source: ENUM_KEYWORD_SOURCE
type: ENUM_KEYWORD_TYPE
value: String
videos: [ID]
}
Expand Down Expand Up @@ -3570,4 +3581,4 @@ input VideoVariantInput {

type VideoVariantRelationResponseCollection {
nodes: [VideoVariant!]!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"languages": {
"type": "json"
},
"options": {
"type": "json"
},
"status": {
"type": "enumeration",
"enum": ["pending", "running", "completed", "failed"],
Expand Down
5 changes: 5 additions & 0 deletions apps/cms/src/api/keyword/content-types/keyword/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"enum": ["core", "manager"],
"default": "core",
"required": true
},
"type": {
"type": "enumeration",
"enum": ["keyword", "topic", "speaker"],
"default": "keyword"
}
}
}
5 changes: 4 additions & 1 deletion apps/manager/src/app/api/enrich/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export async function POST(request: Request) {
}

try {
const job = await createJob(muxAssetId, muxPlaybackId, languages)
const job = await createJob(muxAssetId, muxPlaybackId, languages, {
options: { notifyCms: true },
videoDocumentId: video.documentId,
})
jobs.push({ videoId: coreId, jobId: job.id })

// Run enrichment in the background after the response is sent
Expand Down
42 changes: 41 additions & 1 deletion apps/manager/src/lib/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
JobRecord,
JobStatus,
JobStepState,
JobOptions,
WorkflowStepName,
StepStatus,
} from "@/types/job"
Expand All @@ -23,6 +24,7 @@ const JOB_FIELDS = graphql(`
documentId
muxAssetId
muxPlaybackId
options
languages
status
currentStep
Expand All @@ -41,6 +43,11 @@ const JOB_FIELDS = graphql(`
finishedAt
error
}
video {
documentId
coreId
title
}
}
`)

Expand Down Expand Up @@ -93,6 +100,10 @@ const LIST_JOBS = graphql(
// ---------------------------------------------------------------------------

type EnrichmentJobNode = NonNullable<ResultOf<typeof GET_JOB>["enrichmentJob"]>
type CreateJobContext = {
options?: JobOptions
videoDocumentId?: string
}

// ---------------------------------------------------------------------------
// Mapping helpers
Expand All @@ -104,8 +115,11 @@ export function toJobRecord(node: EnrichmentJobNode): JobRecord {
id: node.documentId,
muxAssetId: node.muxAssetId,
muxPlaybackId: node.muxPlaybackId ?? "",
videoDocumentId: node.video?.documentId,
videoCoreId: node.video?.coreId ?? undefined,
languages: (node.languages ?? []) as string[],
options: {},
sourceMediaTitle: node.video?.title ?? undefined,
options: toJobOptions(node.options),
status: node.status as JobStatus,
currentStep: node.currentStep as WorkflowStepName | undefined,
retries: node.retries ?? 0,
Expand All @@ -119,6 +133,25 @@ export function toJobRecord(node: EnrichmentJobNode): JobRecord {
}
}

function toJobOptions(value: unknown): JobOptions {
if (!value || typeof value !== "object" || Array.isArray(value)) {
return {}
}

const raw = value as Record<string, unknown>
const options: JobOptions = {}
if (typeof raw.generateVoiceover === "boolean") {
options.generateVoiceover = raw.generateVoiceover
}
if (typeof raw.uploadMux === "boolean") {
options.uploadMux = raw.uploadMux
}
if (typeof raw.notifyCms === "boolean") {
options.notifyCms = raw.notifyCms
}
return options
}

function toStepState(
s: NonNullable<EnrichmentJobNode["steps"]>[number],
): JobStepState {
Expand Down Expand Up @@ -169,9 +202,14 @@ export async function createJob(
muxAssetId: string,
muxPlaybackId: string,
languages: string[] = [],
context: CreateJobContext = {},
): Promise<JobRecord> {
const client = getClient()
const steps = buildInitialSteps()
const options: JobOptions = { ...context.options }
if (options.notifyCms && !context.videoDocumentId) {
options.notifyCms = false
}

const result = await client.mutate({
mutation: CREATE_JOB,
Expand All @@ -180,6 +218,8 @@ export async function createJob(
muxAssetId,
muxPlaybackId,
languages,
options,
...(context.videoDocumentId ? { video: context.videoDocumentId } : {}),
status: "pending",
retries: 0,
artifacts: {},
Expand Down
2 changes: 2 additions & 0 deletions apps/manager/src/types/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export interface JobRecord {
id: string
muxAssetId: string
muxPlaybackId: string // Forge extension — stored at job creation
videoDocumentId?: string
videoCoreId?: string
languages: string[]
sourceCollectionTitle?: string
sourceMediaTitle?: string
Expand Down
Loading
Loading