2026-06-01 23:08:58 +08:00
|
|
|
import { prisma } from '@shumai/db'
|
2026-06-01 23:16:22 +08:00
|
|
|
import { WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
|
2026-06-01 23:08:58 +08:00
|
|
|
import '@shumai/db/src/prisma-json-types'
|
2026-05-19 16:05:09 +08:00
|
|
|
|
|
|
|
|
type TransactionClient = Omit<
|
|
|
|
|
typeof prisma,
|
|
|
|
|
'$connect' | '$disconnect' | '$on' | '$transaction' | '$use' | '$extends'
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
export class VideoTranscoder {
|
|
|
|
|
private spec: PrismaJson.TaskSpec = {}
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly db: TransactionClient,
|
|
|
|
|
private readonly assetId: string,
|
|
|
|
|
private readonly teamId: string,
|
|
|
|
|
private readonly projectId: string,
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
setStrategy(strategy: PrismaJson.VideoTranscodeStrategy): this {
|
|
|
|
|
this.spec.videoStrategy = strategy
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-01 13:27:50 +08:00
|
|
|
setVideoResolutions(resolutions?: PrismaJson.VideoResolutionLadder[]): this {
|
|
|
|
|
if (resolutions) {
|
|
|
|
|
this.spec.videoResolutions = resolutions
|
|
|
|
|
}
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-26 16:28:14 +08:00
|
|
|
setHardwareAcceleration(hardwareAcceleration?: PrismaJson.HardwareAcceleration): this {
|
|
|
|
|
if (hardwareAcceleration) {
|
|
|
|
|
this.spec.hardwareAcceleration = hardwareAcceleration
|
|
|
|
|
}
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-18 13:30:33 +08:00
|
|
|
setThreads(threads?: number): this {
|
|
|
|
|
if (threads !== undefined) {
|
|
|
|
|
this.spec.threads = threads
|
|
|
|
|
}
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-19 16:05:09 +08:00
|
|
|
withSprite(): this {
|
|
|
|
|
this.spec.sprite = true
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
withPoster(): this {
|
|
|
|
|
this.spec.poster = true
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 16:31:40 +08:00
|
|
|
setHls(enabled?: boolean, resolutions?: PrismaJson.HlsResolutionLadder[]): this {
|
|
|
|
|
if (enabled !== undefined) {
|
|
|
|
|
this.spec.hlsEnabled = enabled
|
|
|
|
|
}
|
|
|
|
|
if (resolutions) {
|
|
|
|
|
this.spec.hlsResolutions = resolutions
|
|
|
|
|
}
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-19 16:05:09 +08:00
|
|
|
async submit(): Promise<string> {
|
|
|
|
|
const task = await this.db.workflowTask.create({
|
|
|
|
|
data: {
|
|
|
|
|
assetId: this.assetId,
|
|
|
|
|
teamId: this.teamId,
|
|
|
|
|
projectId: this.projectId,
|
2026-07-19 12:32:08 +08:00
|
|
|
type: WorkflowTaskType.transcode_video,
|
2026-05-19 16:05:09 +08:00
|
|
|
status: WorkflowTaskStatus.pending,
|
2026-05-28 09:48:05 +08:00
|
|
|
payload: {
|
|
|
|
|
projectId: this.projectId,
|
|
|
|
|
transcode: this.spec,
|
|
|
|
|
},
|
2026-05-19 16:05:09 +08:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
return task.id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ImageTranscoder {
|
|
|
|
|
private spec: PrismaJson.TaskSpec = {}
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly db: TransactionClient,
|
|
|
|
|
private readonly assetId: string,
|
|
|
|
|
private readonly teamId: string,
|
|
|
|
|
private readonly projectId: string,
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
withThumbnail(): this {
|
|
|
|
|
this.spec.thumbnail = true
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async submit(): Promise<string> {
|
|
|
|
|
const task = await this.db.workflowTask.create({
|
|
|
|
|
data: {
|
|
|
|
|
assetId: this.assetId,
|
|
|
|
|
teamId: this.teamId,
|
|
|
|
|
projectId: this.projectId,
|
2026-07-19 12:32:08 +08:00
|
|
|
type: WorkflowTaskType.transcode_image,
|
2026-05-19 16:05:09 +08:00
|
|
|
status: WorkflowTaskStatus.pending,
|
2026-05-28 09:48:05 +08:00
|
|
|
payload: {
|
|
|
|
|
projectId: this.projectId,
|
|
|
|
|
transcode: this.spec,
|
|
|
|
|
},
|
2026-05-19 16:05:09 +08:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
return task.id
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-18 10:32:38 +08:00
|
|
|
|
|
|
|
|
export class PdfTranscoder {
|
|
|
|
|
private spec: PrismaJson.TaskSpec = {}
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly db: TransactionClient,
|
|
|
|
|
private readonly assetId: string,
|
|
|
|
|
private readonly teamId: string,
|
|
|
|
|
private readonly projectId: string,
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
withSprite(): this {
|
|
|
|
|
this.spec.sprite = true
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
withPoster(): this {
|
|
|
|
|
this.spec.poster = true
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async submit(): Promise<string> {
|
|
|
|
|
const task = await this.db.workflowTask.create({
|
|
|
|
|
data: {
|
|
|
|
|
assetId: this.assetId,
|
|
|
|
|
teamId: this.teamId,
|
|
|
|
|
projectId: this.projectId,
|
2026-07-19 12:32:08 +08:00
|
|
|
type: WorkflowTaskType.transcode_pdf,
|
2026-07-18 10:32:38 +08:00
|
|
|
status: WorkflowTaskStatus.pending,
|
|
|
|
|
payload: {
|
|
|
|
|
projectId: this.projectId,
|
|
|
|
|
transcode: this.spec,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
return task.id
|
|
|
|
|
}
|
|
|
|
|
}
|