feat: 完善模板导入功能

新增功能:
- 添加详细的模板导入日志系统
- 实现全局进度存储机制
- 完善模板状态管理

 修复问题:
- 修复进度监控无限轮询问题
- 修复模板列表状态显示不正确问题
- 修复所有unwrap()导致的panic错误
- 修复外键约束失败问题

 改进:
- 优化素材上传逻辑,只上传视频/音频/图片
- 上传失败时自动跳过而不是中断导入
- 缺失文件时继续导入而不是失败
- 改进错误处理机制
This commit is contained in:
imeepos
2025-07-14 21:34:07 +08:00
parent b3321114ac
commit 939efd70d4
39 changed files with 9152 additions and 6 deletions

View File

@@ -0,0 +1,155 @@
pub mod draft_parser_tests;
pub mod cloud_upload_service_tests;
pub mod template_service_tests;
pub mod template_integration_tests;
// 测试工具函数
pub mod test_utils {
use std::path::PathBuf;
use tempfile::TempDir;
use std::fs;
/// 创建临时测试目录
pub fn create_temp_dir() -> TempDir {
tempfile::tempdir().expect("Failed to create temp dir")
}
/// 创建测试用的draft_content.json文件
pub fn create_test_draft_file(temp_dir: &TempDir, content: &str) -> PathBuf {
let file_path = temp_dir.path().join("draft_content.json");
fs::write(&file_path, content).expect("Failed to write test file");
file_path
}
/// 创建测试用的视频文件
pub fn create_test_video_file(temp_dir: &TempDir, filename: &str) -> PathBuf {
let file_path = temp_dir.path().join(filename);
fs::write(&file_path, b"fake video content").expect("Failed to write test video file");
file_path
}
/// 获取测试用的draft_content.json内容
pub fn get_test_draft_content() -> String {
serde_json::json!({
"id": "test-template-id",
"canvas_config": {
"width": 1920,
"height": 1080,
"ratio": "16:9"
},
"duration": 30000000,
"fps": 30.0,
"materials": {
"videos": [
{
"id": "video-1",
"material_name": "test_video.mp4",
"path": "test_video.mp4",
"duration": 15000000,
"width": 1920,
"height": 1080,
"has_audio": true,
"type": "video"
}
],
"audios": [
{
"id": "audio-1",
"name": "test_audio.mp3",
"path": "test_audio.mp3",
"duration": 30000000,
"type": "audio"
}
],
"images": [
{
"id": "image-1",
"material_name": "test_image.jpg",
"path": "test_image.jpg",
"width": 1920,
"height": 1080,
"type": "image"
}
],
"texts": [
{
"id": "text-1",
"content": "测试文本",
"font_family": "Arial",
"font_size": 24.0,
"color": "#FFFFFF"
}
]
},
"tracks": [
{
"id": "track-1",
"type": "video",
"segments": [
{
"id": "segment-1",
"material_id": "video-1",
"start": 0,
"duration": 15000000,
"target_timerange": {
"start": 0,
"duration": 15000000
}
}
]
},
{
"id": "track-2",
"type": "audio",
"segments": [
{
"id": "segment-2",
"material_id": "audio-1",
"start": 0,
"duration": 30000000,
"target_timerange": {
"start": 0,
"duration": 30000000
}
}
]
}
]
}).to_string()
}
/// 获取无效的draft_content.json内容
pub fn get_invalid_draft_content() -> String {
r#"{
"invalid": "json"
}"#.to_string()
}
/// 获取缺失文件的draft_content.json内容
pub fn get_missing_files_draft_content() -> String {
r#"{
"id": "test-template-id",
"canvas_config": {
"width": 1920,
"height": 1080,
"ratio": "16:9"
},
"duration": 30000000,
"fps": 30.0,
"materials": {
"videos": [
{
"id": "video-1",
"material_name": "missing_video.mp4",
"path": "missing_video.mp4",
"duration": 15000000,
"width": 1920,
"height": 1080,
"has_audio": true,
"type": "video"
}
]
}
}"#.to_string()
}
}