diff --git a/src/api/admin/transcode.ts b/src/api/admin/transcode.ts index fe436fa..88d7d27 100644 --- a/src/api/admin/transcode.ts +++ b/src/api/admin/transcode.ts @@ -1,7 +1,12 @@ // Author: fruit.com.cn import request from '@/axios' -import type { EpisodeTranscodeItem, MediaThumbnailResult, TranscodeTriggerResult } from './types' +import type { + EpisodeTranscodeItem, + MediaThumbnailResult, + TranscodeBackfillResult, + TranscodeTriggerResult +} from './types' /** 分集编辑页聚合查询转码任务、清晰度与帧图。 */ export const getEpisodeTranscodeApi = (episodeId: number | string) => { @@ -28,3 +33,11 @@ export const triggerMediaTranscodeApi = (mediaAssetId: string) => { url: `/admin/media/${mediaAssetId}/transcode` }) } + +/** 手动补齐转码:扫描缺码率产物/帧图的分集并入队。 */ +export const runTranscodeBackfillApi = (batchSize?: number) => { + return request.post({ + url: '/admin/media/transcode/backfill', + params: batchSize ? { batchSize } : undefined + }) +} diff --git a/src/api/admin/types.ts b/src/api/admin/types.ts index 8641c5f..ccda91e 100644 --- a/src/api/admin/types.ts +++ b/src/api/admin/types.ts @@ -321,6 +321,16 @@ export interface TranscodeTriggerResult { status: string } +export interface TranscodeBackfillItem { + episodeId: string + taskId: string +} + +export interface TranscodeBackfillResult { + triggered: number + items: TranscodeBackfillItem[] +} + export interface BannerItem { id: number imageUrl: string diff --git a/src/locales/en.ts b/src/locales/en.ts index 26c7faa..88a012c 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -657,6 +657,11 @@ export default { saveFailed: 'Failed to save transcode settings', loadFailed: 'Failed to load transcode settings', noPermission: 'This account cannot manage transcode settings', + backfill: 'Backfill transcodes', + backfillTip: 'Scan episodes missing renditions or thumbnails and enqueue them for transcoding', + backfillDone: 'Enqueued {count} episodes into the transcode queue', + backfillEmpty: 'No episodes need transcoding', + backfillFailed: 'Failed to run transcode backfill', enabled: 'Enable transcode profile', enabledDescription: 'Marks whether this transcode profile is enabled; the quality ladder is still validated when saved.', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 1387d44..47411df 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -648,6 +648,11 @@ export default { saveFailed: '转码设置保存失败', loadFailed: '转码设置加载失败', noPermission: '当前账号没有转码设置权限', + backfill: '立即补齐转码', + backfillTip: '扫描缺少清晰度产物或帧图的分集并自动入队转码', + backfillDone: '本轮已补入 {count} 个分集进入转码队列', + backfillEmpty: '没有需要补转的分集', + backfillFailed: '补齐转码执行失败', enabled: '启用转码配置', enabledDescription: '标记当前转码配置是否启用;保存时仍会校验下方档位。', segmentSeconds: 'HLS 分片时长(秒)', diff --git a/src/views/systemManagement/TranscodeSettingsView.vue b/src/views/systemManagement/TranscodeSettingsView.vue index a3fb062..4786497 100644 --- a/src/views/systemManagement/TranscodeSettingsView.vue +++ b/src/views/systemManagement/TranscodeSettingsView.vue @@ -14,6 +14,7 @@ const { rules, loading, saving, + backfilling, loadError, canManage, qualityRules, @@ -23,7 +24,8 @@ const { loadProfile, addRung, deleteRung, - saveProfile + saveProfile, + runBackfill } = useTranscodeSettings() @@ -33,6 +35,18 @@ const { :title="t('transcodeSettings.title')" :description="t('transcodeSettings.description')" > + + + + {{ t('transcodeSettings.backfill') }} + + {{ t('transcodeSettings.reload') }} diff --git a/src/views/systemManagement/composables/transcodeSettingsActions.ts b/src/views/systemManagement/composables/transcodeSettingsActions.ts index 126184a..aeb7af0 100644 --- a/src/views/systemManagement/composables/transcodeSettingsActions.ts +++ b/src/views/systemManagement/composables/transcodeSettingsActions.ts @@ -5,6 +5,7 @@ import type { ComputedRef, Ref } from 'vue' import { ElMessage } from 'element-plus' import type { FormInstance } from 'element-plus' import { getMediaTranscodeProfileApi, saveMediaTranscodeProfileApi } from '@/api/admin/media' +import { runTranscodeBackfillApi } from '@/api/admin/transcode' import type { MediaTranscodeProfile } from '@/api/admin/types' import { applyProfileToForm, buildProfilePayload } from './transcodeProfileModel' @@ -15,6 +16,7 @@ interface SettingsContext { formRef: Ref loading: Ref saving: Ref + backfilling: Ref loadError: Ref canManage: ComputedRef t: Translate @@ -77,3 +79,28 @@ export const saveTranscodeProfile = async (context: SettingsContext): Promise => { + if (!context.canManage.value || context.backfilling.value) { + return + } + context.backfilling.value = true + try { + const response = await runTranscodeBackfillApi() + if (response.code !== 0) { + ElMessage.error(response.message || context.t('transcodeSettings.backfillFailed')) + return + } + const triggered = response.data?.triggered ?? 0 + if (triggered > 0) { + ElMessage.success(context.t('transcodeSettings.backfillDone', { count: triggered })) + } else { + ElMessage.info(context.t('transcodeSettings.backfillEmpty')) + } + } catch { + ElMessage.error(context.t('transcodeSettings.backfillFailed')) + } finally { + context.backfilling.value = false + } +} diff --git a/src/views/systemManagement/composables/useTranscodeSettings.ts b/src/views/systemManagement/composables/useTranscodeSettings.ts index 31a94d8..aafc395 100644 --- a/src/views/systemManagement/composables/useTranscodeSettings.ts +++ b/src/views/systemManagement/composables/useTranscodeSettings.ts @@ -13,7 +13,11 @@ import { positiveEvenRule, positiveIntegerRule } from './transcodeProfileRules' -import { loadTranscodeProfile, saveTranscodeProfile } from './transcodeSettingsActions' +import { + loadTranscodeProfile, + runTranscodeBackfill, + saveTranscodeProfile +} from './transcodeSettingsActions' /** 转码设置页的响应式状态与动作装配。 */ export function useTranscodeSettings() { @@ -22,10 +26,11 @@ export function useTranscodeSettings() { const formRef = ref() const loading = ref(false) const saving = ref(false) + const backfilling = ref(false) const loadError = ref('') const form = reactive(defaultProfile()) const canManage = computed(() => can('episode:upload')) - const context = { form, formRef, loading, saving, loadError, canManage, t } + const context = { form, formRef, loading, saving, backfilling, loadError, canManage, t } const rules = computed(() => createProfileRules(t)) const enabledRules = computed(() => createEnabledRules(form, t)) const qualityRules = (index: number) => createQualityRules(form, index, t) @@ -50,6 +55,7 @@ export function useTranscodeSettings() { rules, loading, saving, + backfilling, loadError, canManage, qualityRules, @@ -59,6 +65,7 @@ export function useTranscodeSettings() { loadProfile, addRung, deleteRung, - saveProfile + saveProfile, + runBackfill: () => runTranscodeBackfill(context) } }