feat(video): generate transcripts with the local embedding server

This commit is contained in:
yiling
2026-12-02 22:12:33 +08:00
parent 17ba2631c5
commit e806435e49
46 changed files with 5233 additions and 88 deletions
@@ -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
}