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:
@@ -34,7 +34,15 @@ import { execFile } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
import { ulid } from 'ulid'
|
||||
import { logger } from '@shumai/core/src/logger'
|
||||
import { ApplicationFailure, defineStep, getLocalTaskAbortSignal } from '@shumai/workflow-core'
|
||||
import {
|
||||
ApplicationFailure,
|
||||
defineStep,
|
||||
ensureLocalMediaFile,
|
||||
getErrorDetails,
|
||||
getLocalTaskAbortSignal,
|
||||
} from '@shumai/workflow-core'
|
||||
|
||||
export { ensureLocalMediaFile } from '@shumai/workflow-core'
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
|
||||
@@ -42,59 +50,6 @@ function getActivityCancellationSignal(taskId?: string): AbortSignal | undefined
|
||||
return getLocalTaskAbortSignal(taskId)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
export interface GetMediaInfoActivityParams {
|
||||
assetId: string
|
||||
assetKey: string
|
||||
|
||||
Reference in New Issue
Block a user