Skip to content

Commit ff6eddd

Browse files
authored
Merge pull request #345 from jumpserver-south/pr@dev@perf_transcoding
perf: Optimize Transcoding Prompt
2 parents 700212e + 0150725 commit ff6eddd

4 files changed

Lines changed: 43 additions & 12 deletions

File tree

i18n/locales/en.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
},
7272
"Transcode": {
7373
"Title": "Replay Transcode",
74-
"Description": "Choose one or multiple .tar recording archive files for MP4 conversion.",
74+
"Description": "Choose one or multiple RDP/VNC recording archive (.tar) files for MP4 conversion.",
7575
"SelectedArchives": "{count} archive(s) selected",
7676
"TotalProgress": "Overall {progress}%",
7777
"CompletedCount": "Completed {completed}/{total}",
@@ -82,7 +82,7 @@
8282
"ArchivesHint": "Single and multiple selection are both supported, and you can append more archives later.",
8383
"SelectArchives": "Add archives",
8484
"ClearArchives": "Clear list",
85-
"EmptyArchives": "Add replay archives to transcode",
85+
"EmptyArchives": "Add RDP/VNC recording archives to transcode",
8686
"OutputTitle": "Output directory",
8787
"OutputHint": "Generated MP4 files will be written to this directory.",
8888
"OutputDirectory": "Output directory",
@@ -130,7 +130,7 @@
130130
"Close": "Close",
131131
"Cancel": "Cancel",
132132
"Confirm": "Confirm",
133-
"FilenameStyle": "Filename style",
133+
"FilenameStyle": "Output filename style",
134134
"FilenameOriginal": "Original (UUID)",
135135
"FilenameFriendly": "Friendly name (user-asset-account)",
136136
"FilenameFriendlyUuid": "Friendly name + UUID",
@@ -147,7 +147,10 @@
147147
"PowerFull": "Full speed (all CPUs)",
148148
"PowerFast": "Fast (3/4 CPU)",
149149
"PowerMedium": "Medium (1/2 CPU)",
150-
"PowerLow": "Low (1/4 CPU)"
150+
"PowerLow": "Low (1/4 CPU)",
151+
"ERR_ALREADY_TRANSCODED": "This recording has already been transcoded. Please extract and play the MP4 file directly.",
152+
"ERR_REPLAY_JSON_NOT_FOUND": "replay.json not found. Please ensure the tar file is an RDP/VNC recording.",
153+
"ERR_RECORDING_DATA_NOT_FOUND": "Recording data not found. Please ensure the tar file is an RDP/VNC recording."
151154
},
152155
"VideoPlayer": {
153156
"ImportingFiles": "Importing {count} file(s)…",

i18n/locales/zh.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
},
7272
"Transcode": {
7373
"Title": "录像转码",
74-
"Description": "选择一个或多个录像压缩文件(.tar),将录像转换为 mp4 格式。",
74+
"Description": "选择一个或多个录像压缩文件(.tar),将 RDP/VNC 原生录像转换为 mp4 格式。",
7575
"SelectedArchives": "已选择 {count} 个录像包",
7676
"TotalProgress": "总进度 {progress}%",
7777
"CompletedCount": "已完成 {completed}/{total}",
@@ -82,7 +82,7 @@
8282
"ArchivesHint": "支持单选或多选,可继续追加录像文件。",
8383
"SelectArchives": "添加文件",
8484
"ClearArchives": "清空列表",
85-
"EmptyArchives": "请添加要转码的录像压缩文件",
85+
"EmptyArchives": "请添加要转码的 RDP/VNC 录像压缩文件",
8686
"OutputTitle": "输出目录",
8787
"OutputHint": "转码后的 MP4 文件会输出到该目录下。",
8888
"OutputDirectory": "输出目录",
@@ -130,7 +130,7 @@
130130
"Close": "关闭",
131131
"Cancel": "取消",
132132
"Confirm": "确认",
133-
"FilenameStyle": "文件名风格",
133+
"FilenameStyle": "输出文件名风格",
134134
"FilenameOriginal": "原文件名(UUID)",
135135
"FilenameFriendly": "友好名称(用户-资产-账号)",
136136
"FilenameFriendlyUuid": "友好名称 + UUID",
@@ -147,7 +147,10 @@
147147
"PowerFull": "全速(所有CPU)",
148148
"PowerFast": "极速(3/4 CPU)",
149149
"PowerMedium": "中等(1/2 CPU)",
150-
"PowerLow": "低速(1/4 CPU)"
150+
"PowerLow": "低速(1/4 CPU)",
151+
"ERR_ALREADY_TRANSCODED": "该录像已转码,请直接解压 tar 包后在播放器中播放",
152+
"ERR_REPLAY_JSON_NOT_FOUND": "未找到 replay.json,请确认 tar 包为 RDP/VNC 录像文件",
153+
"ERR_RECORDING_DATA_NOT_FOUND": "未找到录像数据文件,请确认 tar 包为 RDP/VNC 录像文件"
151154
},
152155
"VideoPlayer": {
153156
"ImportingFiles": "正在导入 {count} 个文件…",

src-tauri/src/transcode/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ fn extract_tar_payloads(
540540

541541
let mut replay_json: Option<Vec<u8>> = None;
542542
let mut parts: Vec<(usize, Vec<u8>)> = Vec::new();
543+
let mut mp4_files: Vec<String> = Vec::new();
543544

544545
for entry_result in archive.entries().map_err(|e| {
545546
(
@@ -586,19 +587,33 @@ fn extract_tar_payloads(
586587
)
587588
})?;
588589
parts.push((index, buf));
590+
} else if filename.ends_with(".mp4") {
591+
mp4_files.push(filename);
589592
}
590593
}
591594

592595
let replay_json = replay_json.ok_or_else(|| {
596+
if !mp4_files.is_empty() {
597+
return (
598+
fallback_session_id.to_string(),
599+
"ERR_ALREADY_TRANSCODED".to_string(),
600+
);
601+
}
593602
(
594603
fallback_session_id.to_string(),
595-
"replay.json not found in tar archive".to_string(),
604+
"ERR_REPLAY_JSON_NOT_FOUND".to_string(),
596605
)
597606
})?;
598607
if parts.is_empty() {
608+
if !mp4_files.is_empty() {
609+
return Err((
610+
fallback_session_id.to_string(),
611+
"ERR_ALREADY_TRANSCODED".to_string(),
612+
));
613+
}
599614
return Err((
600615
fallback_session_id.to_string(),
601-
".part.gz file not found in tar archive".to_string(),
616+
"ERR_RECORDING_DATA_NOT_FOUND".to_string(),
602617
));
603618
}
604619
parts.sort_by_key(|(index, _)| *index);

ui/store/modules/transcode.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,23 @@ export interface TranscodeTaskItem {
5757
duration?: number | null
5858
}
5959

60+
const transcodeErrorKeyMap: Record<string, string> = {
61+
ERR_ALREADY_TRANSCODED: "Transcode.ERR_ALREADY_TRANSCODED",
62+
ERR_REPLAY_JSON_NOT_FOUND: "Transcode.ERR_REPLAY_JSON_NOT_FOUND",
63+
ERR_RECORDING_DATA_NOT_FOUND: "Transcode.ERR_RECORDING_DATA_NOT_FOUND",
64+
};
65+
6066
let listenerRegistered = false;
6167

6268
export const useTranscodeStore = defineStore(
6369
"transcode",
6470
() => {
6571
const { t } = useI18n();
6672
const toast = useToast();
73+
const resolveError = (raw: string): string => {
74+
const key = transcodeErrorKeyMap[raw];
75+
return key ? t(key) : raw;
76+
};
6777

6878
const archivePaths = ref<string[]>([]);
6979
const outputDir = ref("");
@@ -299,7 +309,7 @@ export const useTranscodeStore = defineStore(
299309
const incomingDuration = payload.duration ?? null;
300310

301311
if (successFlag === true || successFlag === false) {
302-
const message = successFlag ? t("Transcode.Completed") : payload.message || t("Transcode.StatusFailed");
312+
const message = successFlag ? t("Transcode.Completed") : resolveError(payload.message) || t("Transcode.StatusFailed");
303313
markTaskCompleted(targetIndex, successFlag, outputValue, message, incomingMetadata, incomingDuration);
304314
return;
305315
}
@@ -353,7 +363,7 @@ export const useTranscodeStore = defineStore(
353363
targetIndex,
354364
result.success,
355365
result.output,
356-
result.success ? t("Transcode.Completed") : result.error || t("Transcode.StatusFailed"),
366+
result.success ? t("Transcode.Completed") : resolveError(result.error || "") || t("Transcode.StatusFailed"),
357367
result.metadata ?? null
358368
);
359369
});

0 commit comments

Comments
 (0)