import cn.reghao.oss.sdk.model.OssProperties;
import cn.reghao.oss.storeapi.dto.ServerInfo;
import cn.reghao.oss.storeapi.rest.UploadFileRet;
import cn.reghao.oss.sdk.ObjectMultipartUploadService;
import cn.reghao.oss.sdk.OssStoreClient;
import cn.reghao.oss.sdk.OssConsoleClient;
import lombok.extern.slf4j.Slf4j;

import java.io.*;

/**
 * @author reghao
 * @date 2023-06-02 16:19:04
 */
@Slf4j
public class OssConsoleClientTest {
    static void multipartUpload() throws Exception {
        String storeEndpoint = "";
        ObjectMultipartUploadService multipartUploadService = new ObjectMultipartUploadService(storeEndpoint);
        String filePath = "";
        int channelId = 1;
        multipartUploadService.upload(new File(filePath), channelId);
        //multipartUploadService.create();
        //multipartUploadService.get();
    }

    public static void main(String[] args) throws Exception {
        String consoleUrl = "http://ossconsole.reghao.cn";
        String accessKeyId = "mWYMpbrL";
        String accessKeySecret = "uvuTJKKbRfaSxNPM38";
        OssProperties ossProperties = new OssProperties(consoleUrl, accessKeyId, accessKeySecret);
        OssConsoleClient ossConsoleClient = new OssConsoleClient(ossProperties);

        int channelId = 101;
        ServerInfo serverInfo = ossConsoleClient.getServerInfo(channelId);
        if (serverInfo == null) {
            log.info("获取 server_info 失败");
            return;
        }
        String ossUrl = serverInfo.getOssUrl();
        String token = serverInfo.getToken();

        OssStoreClient ossStoreClient = new OssStoreClient(ossUrl);
        String filePath = "/home/reghao/data/video/output.mp4";
        File file = new File(filePath);
        UploadFileRet uploadFileRet = ossStoreClient.postObjectWithJdkHttp(file, channelId, token);
        if (uploadFileRet == null) {
            log.info("文件上传失败");
        } else {
            log.info("{} -> {}", uploadFileRet.getUploadId(), uploadFileRet.getUrl());
        }

        /*String objectName = "video/playback/28d0fd95e224499c9f2cf1d98b4551a5.flv";
        ossStoreClient.getObject(objectName);*/

        /*String sha256sum = "1234567890";
        storeClient.headObject1(sha256sum);*/

        /*int scope = 1;
        String objectId = "dafafafa";
        int contentType = 1001;
        ossConsoleClient.setObjectScope(scope, objectId, contentType);*/
    }
}
