import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Files, Inject, Post } from '@midwayjs/core';
import { KnowLoaderService } from '../../service/loader';

/**
 * 知识库加载器
 */
@CoolController()
export class AdminKnowLoaderController extends BaseController {
  @Inject()
  knowLoaderService: KnowLoaderService;

  @Post('/file', { summary: '加载文件，支持多个文件' })
  async file(@Files() files) {
    const result = [];
    for (const file of files) {
      const docs = await this.knowLoaderService.loadFile(file.data);
      result.push(docs);
    }
    return this.ok(result);
  }

  @Post('/link', { summary: '加载链接' })
  async link(@Body('link') link: string) {
    return this.ok(await this.knowLoaderService.loadLink(link));
  }
}
