package com.docus.server;

import cn.hutool.core.util.ZipUtil;
import cn.hutool.http.HttpRequest;

import com.google.common.collect.Lists;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.bind.annotation.PostMapping;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * 文件上传下载 API
 *
 * @author AutoGenerator
 * @since 2023-07-15
 */
@SpringBootTest
public class FileController {




    public static void test1() throws Exception {
        ZipUtil.unzip("/Users/linruifeng/Desktop/collector_packages/collector.zip", "/Users/linruifeng/Desktop/collector_packages");
//        ZipUtil.unGzip(new GZIPInputStream(new FileInputStream(new File("/Users/linruifeng/Desktop/collector_packages/index.tar.gz"))));
//        FileUtils.unTarGz("/Users/linruifeng/Desktop/collector_packages/", "/Users/linruifeng/Desktop/collector_packages/test");
    }

    @ApiOperation("test")
    @PostMapping("/test")
    public void test2() throws Exception {
        File file = new File("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174051\\麻醉.jpg");
        File file1 = new File("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174052\\麻醉.jpg");

        Map<String, Object> data = new HashMap<>();
        data.put("files", file);
        data.put("filetype", "jpg");

        ArrayList<File> files = Lists.newArrayList(file, file1);

        String body = HttpRequest.post("http://localhost:9115/file/upload")
            .form("files", files.toArray(new File[files.size()]))
            .form("pathKey", "{\n" +
                "  \"success\": true,\n" +
                "  \"datas\": [\n" +
                "    {\n" +
                "      \"index\": 0,\n" +
                "      \"file_type\": \"string\",\n" +
                "      \"angle\": \"string\",\n" +
                "      \"decline\": true,\n" +
                "      \"hand_shadow\": true,\n" +
                "      \"sort\": [\n" +
                "        \"string\"\n" +
                "      ],\n" +
                "      \"data\": [\n" +
                "        {\n" +
                "          \"boxes\": {\n" +
                "            \"left\": 0,\n" +
                "            \"right\": 0,\n" +
                "            \"top\": 0,\n" +
                "            \"bottom\": 0\n" +
                "          },\n" +
                "          \"text\": \"string\"\n" +
                "        }\n" +
                "      ]\n" +
                "    }\n" +
                "  ],\n" +
                "  \"time\": 0,\n" +
                "  \"message\": \"string\"\n" +
                "}")
            .contentType("multipart/form-data")
            .execute()
            .body();

        System.out.println(body);

    }
}
