#!/bin/bash

# 课程资料预览功能启动脚本
# 用途：重建Docker镜像并启动服务

set -e

echo "========================================="
echo "课程资料预览功能启动脚本"
echo "========================================="
echo ""

# 切换到后端目录
cd "$(dirname "$0")/kaopeilian-backend"

echo "步骤 1/4: 停止现有服务..."
docker-compose -f docker-compose.dev.yml down

echo ""
echo "步骤 2/4: 重建后端镜像（安装LibreOffice）..."
echo "注意：首次构建可能需要5-10分钟，请耐心等待..."
docker-compose -f docker-compose.dev.yml build backend

echo ""
echo "步骤 3/4: 启动所有服务..."
docker-compose -f docker-compose.dev.yml up -d

echo ""
echo "步骤 4/4: 等待服务启动（30秒）..."
sleep 30

echo ""
echo "========================================="
echo "服务启动完成！"
echo "========================================="
echo ""
echo "📋 服务信息："
echo "  - 后端API: http://localhost:8000"
echo "  - 前端页面: http://localhost:3001"
echo "  - 课程详情: http://localhost:3001/trainee/course-detail?id=1"
echo ""
echo "🔍 检查LibreOffice安装状态："
echo "  curl http://localhost:8000/api/v1/preview/check-converter"
echo ""
echo "📝 测试建议："
echo "  1. 先在课程管理中上传各种格式的测试文件"
echo "  2. 访问课程详情页查看资料列表"
echo "  3. 点击不同类型的文件测试预览功能"
echo "  4. 特别测试Office文档的转换预览"
echo ""
echo "📖 详细测试指南："
echo "  查看文件: kaopeilian-frontend/课程资料预览功能测试指南.md"
echo ""
echo "🔧 查看服务日志："
echo "  docker-compose -f docker-compose.dev.yml logs -f backend"
echo ""

