mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 22:14:50 +00:00
feat(video): generate transcripts with the local embedding server
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import * as fs from 'node:fs'
|
||||
import * as path from 'node:path'
|
||||
import { ApplicationFailure } from '../workflow-utils'
|
||||
|
||||
export function getErrorDetails(err: unknown): { code?: string; message: string; name?: string } {
|
||||
if (err && typeof err === 'object') {
|
||||
const record = err as Record<string, unknown>
|
||||
return {
|
||||
code: typeof record.code === 'string' ? record.code : undefined,
|
||||
message:
|
||||
typeof record.message === 'string'
|
||||
? record.message
|
||||
: err instanceof Error
|
||||
? err.message
|
||||
: String(err),
|
||||
name: typeof record.name === 'string' ? record.name : undefined,
|
||||
}
|
||||
}
|
||||
return {
|
||||
message: String(err),
|
||||
}
|
||||
}
|
||||
|
||||
export async function ensureLocalMediaFile(assetKey: string, filePath: string): Promise<string> {
|
||||
if (fs.existsSync(filePath)) {
|
||||
return filePath
|
||||
}
|
||||
const dir = path.dirname(filePath)
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true })
|
||||
}
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
try {
|
||||
await s3Service.downloadToFile(bucket, assetKey, filePath)
|
||||
} catch (err) {
|
||||
const { code, message, name } = getErrorDetails(err)
|
||||
const lowerMsg = message.toLowerCase()
|
||||
const lowerCode = (code || '').toLowerCase()
|
||||
const lowerName = (name || '').toLowerCase()
|
||||
if (
|
||||
lowerCode === 'enoent' ||
|
||||
lowerCode === 'nosuchkey' ||
|
||||
lowerName === 'nosuchkey' ||
|
||||
lowerMsg.includes('enoent') ||
|
||||
lowerMsg.includes('nosuchkey')
|
||||
) {
|
||||
throw ApplicationFailure.create({
|
||||
message: `Failed to download media to local file: ${message}`,
|
||||
nonRetryable: true,
|
||||
cause: err instanceof Error ? err : undefined,
|
||||
})
|
||||
}
|
||||
throw err
|
||||
}
|
||||
return filePath
|
||||
}
|
||||
@@ -57,6 +57,7 @@ export function getDbosDatabaseUrl(rawUrl?: string): string {
|
||||
export function getQueueForTaskType(type: string | null | undefined): string {
|
||||
switch (type) {
|
||||
case WorkflowTaskType.ai_embedding:
|
||||
case WorkflowTaskType.ai_transcription:
|
||||
case WorkflowTaskType.ai_metadata_autofill:
|
||||
case WorkflowTaskType.chat:
|
||||
return TaskQueueAgent
|
||||
|
||||
@@ -2,4 +2,5 @@ export * from './dbos-executor'
|
||||
export * from './workflow-utils'
|
||||
export * from './workflow'
|
||||
export * from './activities/task'
|
||||
export * from './activities/media'
|
||||
export * from './local-task-storage'
|
||||
|
||||
Reference in New Issue
Block a user