package com.emoon.modules.chat.controller;

import com.emoon.common.core.domain.R;
import com.emoon.knowledge.service.IFileParseService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/parse")
@CrossOrigin(
    origins = "${cors.file-parse.origins}",
    allowedHeaders = "*",
    methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE}
)
public class FileParseController {

    @Resource
    private IFileParseService fileParseService;

    /**
     * 上传文件并直接解析返回原文
     */
    @PostMapping("/file")
    public R<String> parseFile(@RequestParam("file") MultipartFile file) {
        try {
            String content = fileParseService.parseFileContent(file);
            return R.ok(content);
        } catch (Exception e) {
            return R.fail("文件解析失败: " + e.getMessage());
        }
    }
}
