Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion routes/mux/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,22 @@ export default defineEventHandler(async (event) => {
encoding_tier: 'baseline',
})

return { id: asset.id, playbackId: asset.playback_ids?.[0].id }
let processing = true

const checkAssetStatus = async (assetId) => {
const assetDetails = await Video.Assets.get(assetId)
if (assetDetails.status === 'ready' || assetDetails.status === 'errored') {
processing = false
return assetDetails.status
} else {
await new Promise(resolve => setTimeout(resolve, 5000)) // 5 seconds delay

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come the delay is necessary?

return checkAssetStatus(assetId)
}
}

const finalStatus = await checkAssetStatus(asset.id)

return { id: asset.id, playbackId: asset.playback_ids?.[0].id, processing, status: finalStatus }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of finalStatus it is processingStatus or just status?

} catch (e) {
console.error('Error creating Mux asset:', e.message, 'Details:', e.details || 'None')
return createError({
Expand Down