/**
 * 健康检查和公共配置路由
 * 提供服务健康状态和公共配置信息
 */

const express = require('express');
const router = express.Router();
const { SettingsDB } = require('../database');

/**
 * 健康检查端点
 * GET /api/health
 */
router.get('/health', (req, res) => {
  res.json({ success: true, message: 'Server is running' });
});

/**
 * 获取公开的系统配置（不需要登录）
 * GET /api/config
 */
router.get('/config', (req, res) => {
  const maxUploadSize = parseInt(SettingsDB.get('max_upload_size') || '10737418240');
  res.json({
    success: true,
    config: {
      max_upload_size: maxUploadSize
    }
  });
});

/**
 * 获取公开的全局主题设置（不需要登录）
 * GET /api/public/theme
 */
router.get('/public/theme', (req, res) => {
  try {
    const globalTheme = SettingsDB.get('global_theme') || 'dark';
    res.json({
      success: true,
      theme: globalTheme
    });
  } catch (error) {
    console.error('获取全局主题失败:', error);
    res.status(500).json({
      success: false,
      message: '获取主题失败'
    });
  }
});

module.exports = router;
