package com.docus.server;

import cn.hutool.core.util.ZipUtil;
import com.docus.server.common.download.downLoader.HttpDownloader;
import com.docus.server.common.utils.StartUpExeUtils;
import org.springframework.boot.test.context.SpringBootTest;

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

    public static void test() throws Exception {
        /**
         * 1、接收调度器下载采集器包命令
         * 2、下载保存到指定部署路径
         * 3、启动采集器
         */

        HttpDownloader httpDownloader = new HttpDownloader(null);
        String url = "http://192.168.16.110:9113/sch/file/download?filePath=collector_packages/20230718/91d930e6-0490-44e5-9756-caee3251d645/navicat.zip";
        String fileName = "collector.zip";
        String savePath = "H:\\docus\\1"; //部署路径
        String procName = "navicat.exe"; //进程名称

        httpDownloader.downLoadFromUrl(url, fileName, savePath);

        ZipUtil.unzip(savePath + "\\" + fileName, savePath + "\\collector");

        StartUpExeUtils.startUpExe(savePath + "\\collector\\" + procName, procName);
    }

    public static void main(String[] args) throws Exception {
        test();
    }

    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");
    }
}
