feat(controller): 添加 Spider3 控制器
This commit is contained in:
parent
83fabb1383
commit
3544c44293
@ -0,0 +1,65 @@
|
||||
package com.zsc.edu.dify.modules.dify.controller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.zsc.edu.dify.modules.dify.dto.SpiderDto;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/spider3")
|
||||
public class Spider3Controller {
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Value("${quanguo.url}")
|
||||
private String SPIDER_URL;
|
||||
|
||||
@Value("${quanguo.api-key}")
|
||||
private String API_KEY;
|
||||
|
||||
@PostMapping("/run")
|
||||
public JSONObject run(@RequestBody SpiderDto dto) throws JsonProcessingException {
|
||||
dto.setLlm_api_key(API_KEY);
|
||||
String body = objectMapper.writeValueAsString(dto);
|
||||
return WebClient.create(SPIDER_URL).post().uri("/start_crawl")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(body)
|
||||
.retrieve()
|
||||
.bodyToMono(JSONObject.class)
|
||||
.block();
|
||||
}
|
||||
|
||||
@PostMapping("/status")
|
||||
public JSONObject status() {
|
||||
return WebClient.create(SPIDER_URL).post().uri("/crawl_status")
|
||||
.retrieve()
|
||||
.bodyToMono(JSONObject.class)
|
||||
.block();
|
||||
}
|
||||
|
||||
@PostMapping("/logs")
|
||||
public JSONObject logs() {
|
||||
return WebClient.create(SPIDER_URL).post().uri("/logs")
|
||||
.retrieve()
|
||||
.bodyToMono(JSONObject.class)
|
||||
.block();
|
||||
}
|
||||
|
||||
@PostMapping("/stop")
|
||||
public JSONObject stop() {
|
||||
return WebClient.create(SPIDER_URL).post().uri("/stop_crawl")
|
||||
.retrieve()
|
||||
.bodyToMono(JSONObject.class)
|
||||
.block();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user