//! 项目资源存储命令

use crate::ApiResponse;
use crate::StringResultExt;
use crate::storage::project as project_storage;

#[tauri::command]
pub async fn save_project_asset(
    project_id: String,
    filename: String,
    base64_data: String,
) -> ApiResponse<String> {
    match project_storage::save_project_asset(&project_id, &filename, &base64_data).map_err_string() {
        Ok(path) => ApiResponse {
            code: 200,
            message: "资源保存成功".to_string(),
            data: Some(path),
        },
        Err(e) => ApiResponse {
            code: 500,
            message: format!("保存资源失败: {}", e),
            data: None,
        },
    }
}

#[tauri::command]
pub async fn get_video_save_path(
    project_id: String,
    filename: String,
) -> ApiResponse<String> {
    match project_storage::get_video_save_path(&project_id, &filename).map_err_string() {
        Ok(path) => ApiResponse {
            code: 200,
            message: "获取路径成功".to_string(),
            data: Some(path.to_string_lossy().to_string()),
        },
        Err(e) => ApiResponse {
            code: 500,
            message: format!("获取路径失败: {}", e),
            data: None,
        },
    }
}


