handle((response, sink) -> {
- if (response.code != 0) {
- sink.error(new IllegalStateException("创建 token 异常," + response.message));
- return;
- }
- sink.next(response.data.get("token").toString());
- })
- .block();
- }
-
- // TODO @xin:是不是给个 API 连接,这样 type、content、files 都不用写注释太细了
- /**
- * 创建任务
- *
- * @param type 类型
- * 1.智能生成(主题、要求)
- * 2.上传文件生成
- * 3.上传思维导图生成
- * 4.通过word精准转ppt
- * 5.通过网页链接生成
- * 6.粘贴文本内容生成
- * 7.Markdown大纲生成
- * @param content 内容
- * type=1 用户输入主题或要求(不超过1000字符)
- * type=2、4 不传
- * type=3 幕布等分享链接
- * type=5 网页链接地址(http/https)
- * type=6 粘贴文本内容(不超过20000字符)
- * type=7 大纲内容(markdown)
- * @param files 文件列表
- * 文件列表(文件数不超过5个,总大小不超过50M):
- * type=1 上传参考文件(非必传,支持多个)
- * type=2 上传文件(支持多个)
- * type=3 上传思维导图(xmind/mm/md)(仅支持一个)
- * type=4 上传word文件(仅支持一个)
- * type=5、6、7 不传
- *
- * 支持格式:doc/docx/pdf/ppt/pptx/txt/md/xls/xlsx/csv/html/epub/mobi/xmind/mm
- * @return 任务ID
- */
- public ApiResponse createTask(String token, Integer type, String content, List files) {
- MultiValueMap formData = new LinkedMultiValueMap<>();
- formData.add("type", type);
- if (content != null) {
- formData.add("content", content);
- }
- if (files != null) {
- for (MultipartFile file : files) {
- formData.add("file", file.getResource());
- }
- }
- return this.webClient.post()
- .uri("/api/ppt/v2/createTask")
- .header("token", token)
- .contentType(MediaType.MULTIPART_FORM_DATA)
- .body(BodyInserters.fromMultipartData(formData))
- .retrieve()
- .onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(formData))
- .bodyToMono(ApiResponse.class)
- .block();
- }
-
- /**
- * 获取生成选项
- *
- * @param lang 语种
- * @return 生成选项
- */
- public Map getOptions(String lang) {
- String uri = "/api/ppt/v2/options";
- if (lang != null) {
- uri += "?lang=" + lang;
- }
- return this.webClient.get()
- .uri(uri)
- .retrieve()
- .onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(lang))
- .bodyToMono(new ParameterizedTypeReference() {
- })
- .