94 lines
3.1 KiB
TypeScript
94 lines
3.1 KiB
TypeScript
// Author: fruit.com.cn
|
|
// 剧集转码面板的状态映射与展示格式化
|
|
|
|
export type TranscodeTagType = 'primary' | 'success' | 'warning' | 'danger' | 'info'
|
|
export type TranscodeProgressStatus = 'success' | 'exception' | undefined
|
|
|
|
export const THUMBNAIL_PAGE_SIZE = 100
|
|
export const THUMBNAIL_PAGE_SIZES = [100, 200, 500]
|
|
|
|
const STATUS_KEYS: Record<string, string> = {
|
|
QUEUED: 'queued',
|
|
RUNNING: 'running',
|
|
SUCCESS: 'success',
|
|
FAILED: 'failed',
|
|
EMPTY: 'empty',
|
|
NO_VIDEO: 'noVideo',
|
|
NO_MEDIA_ASSET: 'noMediaAsset',
|
|
NO_TASK: 'noTask',
|
|
NO_EPISODE: 'noEpisode',
|
|
EPISODE_NOT_FOUND: 'episodeNotFound',
|
|
INVALID: 'invalid',
|
|
READY: 'ready'
|
|
}
|
|
const BYTES_PER_KB = 1024
|
|
const BYTES_PER_MB = BYTES_PER_KB * 1024
|
|
const BYTES_PER_GB = BYTES_PER_MB * 1024
|
|
const SECONDS_PER_MINUTE = 60
|
|
const MILLIS_PER_SECOND = 1000
|
|
|
|
export function transcodeStatusKey(status?: string): string {
|
|
return STATUS_KEYS[String(status || '').toUpperCase()] || 'unknown'
|
|
}
|
|
|
|
export function transcodeStatusType(status?: string): TranscodeTagType {
|
|
switch (String(status || '').toUpperCase()) {
|
|
case 'SUCCESS':
|
|
return 'success'
|
|
case 'RUNNING':
|
|
return 'warning'
|
|
case 'FAILED':
|
|
return 'danger'
|
|
case 'QUEUED':
|
|
return 'primary'
|
|
default:
|
|
return 'info'
|
|
}
|
|
}
|
|
|
|
export function transcodeProgressStatus(status?: string): TranscodeProgressStatus {
|
|
const normalized = String(status || '').toUpperCase()
|
|
if (normalized === 'SUCCESS') return 'success'
|
|
if (normalized === 'FAILED') return 'exception'
|
|
return undefined
|
|
}
|
|
|
|
export function safeTranscodeProgress(value?: number): number {
|
|
return Math.min(100, Math.max(0, Number(value || 0)))
|
|
}
|
|
|
|
export function renditionStatusLabelKey(status?: string): string {
|
|
return transcodeStatusKey(status)
|
|
}
|
|
|
|
export function renditionStatusType(status?: string): TranscodeTagType {
|
|
const normalized = String(status || '').toUpperCase()
|
|
if (normalized === 'READY') return 'success'
|
|
if (normalized === 'FAILED') return 'danger'
|
|
return 'info'
|
|
}
|
|
|
|
export function formatBytes(value?: number): string {
|
|
const size = Number(value || 0)
|
|
if (size >= BYTES_PER_GB) return `${(size / BYTES_PER_GB).toFixed(2)} GB`
|
|
if (size >= BYTES_PER_MB) return `${(size / BYTES_PER_MB).toFixed(1)} MB`
|
|
if (size >= BYTES_PER_KB) return `${Math.round(size / BYTES_PER_KB)} KB`
|
|
return `${size} B`
|
|
}
|
|
|
|
export function formatDuration(seconds?: number): string {
|
|
const total = Math.max(0, Number(seconds || 0))
|
|
const minutes = Math.floor(total / SECONDS_PER_MINUTE)
|
|
const remainder = total % SECONDS_PER_MINUTE
|
|
return `${String(minutes).padStart(2, '0')}:${String(remainder).padStart(2, '0')}`
|
|
}
|
|
|
|
export function formatTimeMs(milliseconds?: number): string {
|
|
const totalMs = Math.max(0, Number(milliseconds || 0))
|
|
const totalSeconds = Math.floor(totalMs / MILLIS_PER_SECOND)
|
|
const minutes = Math.floor(totalSeconds / SECONDS_PER_MINUTE)
|
|
const seconds = totalSeconds % SECONDS_PER_MINUTE
|
|
const tenths = Math.floor((totalMs % MILLIS_PER_SECOND) / 100)
|
|
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}.${tenths}`
|
|
}
|