"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const router_1 = __importDefault(require("@koa/router"));
const search_service_1 = require("./search.service");
const router = new router_1.default();
/**
 * 搜索音频
 * GET /api/search?q=关键词
 */
router.get('/', async (ctx) => {
    try {
        const { q, limit } = ctx.query;
        if (!q || q.trim() === '') {
            ctx.body = {
                code: 0,
                message: 'success',
                data: [],
            };
            return;
        }
        const results = await search_service_1.searchService.searchAudio(q, parseInt(limit || '20'));
        ctx.body = {
            code: 0,
            message: 'success',
            data: results,
        };
    }
    catch (error) {
        ctx.body = {
            code: 400,
            message: error.message || '搜索失败',
        };
    }
});
exports.default = router;
