mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 19:38:47 +00:00
feat(asset): replace mediaType/mimeType logic with proxyType
This commit is contained in:
@@ -117,6 +117,7 @@ describe('Transcode Activities', () => {
|
||||
const result = await getMediaInfoActivity({
|
||||
assetId: asset.id,
|
||||
filePath: '/tmp/v.mp4',
|
||||
proxyType: 'video',
|
||||
mediaType: 'video/mp4',
|
||||
})
|
||||
|
||||
@@ -153,6 +154,7 @@ describe('Transcode Activities', () => {
|
||||
const result = await getMediaInfoActivity({
|
||||
assetId: asset.id,
|
||||
filePath: '/tmp/i.png',
|
||||
proxyType: 'image',
|
||||
mediaType: 'image/png',
|
||||
})
|
||||
|
||||
@@ -188,6 +190,7 @@ describe('Transcode Activities', () => {
|
||||
const result = await getMediaInfoActivity({
|
||||
assetId: asset.id,
|
||||
filePath: '/tmp/a.mp3',
|
||||
proxyType: 'audio',
|
||||
mediaType: 'audio/mpeg',
|
||||
})
|
||||
|
||||
@@ -221,6 +224,7 @@ describe('Transcode Activities', () => {
|
||||
await getMediaInfoActivity({
|
||||
assetId: asset.id,
|
||||
filePath: '/tmp/d.pdf',
|
||||
proxyType: 'pdf',
|
||||
mediaType: 'application/pdf',
|
||||
})
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { transcodeService } from '@shumai/core/src/transcode/transcode'
|
||||
import { metadataService } from '@shumai/core/src/metadata/metadata'
|
||||
import { stemFromKey } from '@shumai/core/src/utils/filename'
|
||||
import { getProxyType } from '@shumai/core/src/utils/mime'
|
||||
import { ApplicationFailure } from '@temporalio/activity'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
@@ -24,7 +25,12 @@ function getErrorDetails(err: unknown): { code?: string; message: string; name?:
|
||||
const record = err as Record<string, unknown>
|
||||
return {
|
||||
code: typeof record.code === 'string' ? record.code : undefined,
|
||||
message: typeof record.message === 'string' ? record.message : String(err),
|
||||
message:
|
||||
typeof record.message === 'string'
|
||||
? record.message
|
||||
: err instanceof Error
|
||||
? err.message
|
||||
: String(err),
|
||||
name: typeof record.name === 'string' ? record.name : undefined,
|
||||
}
|
||||
}
|
||||
@@ -36,18 +42,16 @@ function getErrorDetails(err: unknown): { code?: string; message: string; name?:
|
||||
export async function getMediaInfoActivity(params: {
|
||||
filePath: string
|
||||
assetId: string
|
||||
mediaType: string
|
||||
proxyType?: 'image' | 'video' | 'audio' | 'pdf' | null
|
||||
mediaType?: string
|
||||
}): Promise<PrismaJson.MediaInfo> {
|
||||
try {
|
||||
const isVideo = params.mediaType.startsWith('video/')
|
||||
const isImage = params.mediaType.startsWith('image/')
|
||||
const isAudio = params.mediaType.startsWith('audio/')
|
||||
const isDocument =
|
||||
params.mediaType.startsWith('text/') ||
|
||||
params.mediaType === 'application/pdf' ||
|
||||
params.mediaType.includes('msword') ||
|
||||
params.mediaType.includes('officedocument') ||
|
||||
params.mediaType.includes('vnd.ms-')
|
||||
const proxyType =
|
||||
params.proxyType || getProxyType(params.mediaType, params.filePath) || undefined
|
||||
const isVideo = proxyType === 'video'
|
||||
const isImage = proxyType === 'image'
|
||||
const isAudio = proxyType === 'audio'
|
||||
const isPdf = proxyType === 'pdf'
|
||||
|
||||
const fileType = isVideo
|
||||
? 'video'
|
||||
@@ -55,25 +59,10 @@ export async function getMediaInfoActivity(params: {
|
||||
? 'audio'
|
||||
: isImage
|
||||
? 'image'
|
||||
: isDocument
|
||||
: isPdf
|
||||
? 'document'
|
||||
: 'file'
|
||||
|
||||
const isPdf =
|
||||
params.mediaType === 'application/pdf' ||
|
||||
params.mediaType === 'text/plain' ||
|
||||
params.mediaType === 'text/csv'
|
||||
|
||||
const proxyType: 'image' | 'video' | 'audio' | 'pdf' | undefined = isVideo
|
||||
? 'video'
|
||||
: isAudio
|
||||
? 'audio'
|
||||
: isImage
|
||||
? 'image'
|
||||
: isPdf || isDocument
|
||||
? 'pdf'
|
||||
: undefined
|
||||
|
||||
const mediaInfo: PrismaJson.MediaInfo = {
|
||||
duration: 0,
|
||||
filesize: 0,
|
||||
@@ -84,7 +73,7 @@ export async function getMediaInfoActivity(params: {
|
||||
videoPreview: { width: 0, height: 0 },
|
||||
finishedAt: new Date().toISOString(),
|
||||
metadata: null,
|
||||
mimeType: params.mediaType,
|
||||
mimeType: params.mediaType || '',
|
||||
original: {
|
||||
key: '', // Will be filled by caller or updated later
|
||||
downloadUrl: '',
|
||||
@@ -182,7 +171,7 @@ export async function getMediaInfoActivity(params: {
|
||||
{ key: 'resolution_width', value: info.originalWidth },
|
||||
{ key: 'resolution_height', value: info.originalHeight },
|
||||
)
|
||||
} else if (isPdf || isDocument) {
|
||||
} else if (isPdf) {
|
||||
const info = await transcodeService.getPdfInfo(params.filePath)
|
||||
mediaInfo.frames = info.totalFrames
|
||||
mediaInfo.metadata = {
|
||||
|
||||
@@ -18,9 +18,10 @@ export async function renderPdfPagesWorkflow(task: WorkflowTask): Promise<void>
|
||||
|
||||
const { asset, key } = await fetchAssetWithKey(workerQueue, task.assetId)
|
||||
const { renderPdfPagesActivity } = getActivities()
|
||||
const pdfKey = (asset.media as PrismaJson.MediaInfo | null)?.pdfTranscode?.key || key
|
||||
|
||||
const pages = await executeActivity(workerQueue, renderPdfPagesActivity, {
|
||||
assetKey: key,
|
||||
assetKey: pdfKey,
|
||||
assetId: asset.id,
|
||||
start: payload.pdfPages.start,
|
||||
end: payload.pdfPages.end,
|
||||
|
||||
@@ -43,6 +43,7 @@ export async function transcodeImageWorkflow(task: WorkflowTask): Promise<void>
|
||||
const mediaInfo = await executeActivity(workerQueue, getMediaInfoActivity, {
|
||||
filePath,
|
||||
assetId: asset.id,
|
||||
proxyType: 'image',
|
||||
mediaType: asset.mediaType || '',
|
||||
})
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ export async function transcodePdfWorkflow(task: WorkflowTask): Promise<void> {
|
||||
const mediaInfo = await executeActivity(workerQueue, getMediaInfoActivity, {
|
||||
filePath: currentFilePath,
|
||||
assetId: asset.id,
|
||||
proxyType: 'pdf',
|
||||
mediaType: asset.mediaType || '',
|
||||
})
|
||||
|
||||
|
||||
@@ -43,9 +43,11 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
tmpDir = download.tmpDir
|
||||
|
||||
const spec = task.payload?.transcode || {}
|
||||
const proxyType = asset.mediaType?.startsWith('audio/') ? 'audio' : 'video'
|
||||
const mediaInfo = await executeActivity(workerQueue, getMediaInfoActivity, {
|
||||
filePath,
|
||||
assetId: asset.id,
|
||||
proxyType,
|
||||
mediaType: asset.mediaType || '',
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user