package com.search.supersearch.demo.oss;


import com.aliyun.oss.model.OSSObjectSummary;
import com.search.supersearch.util.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/osstest")
@Slf4j
public class OssTestUpload {


    @GetMapping("/getAll")
    public void getAll() throws IOException {
        log.info("getAll- detail - start");
        List<OSSObjectSummary> summaries = AliOssUtil.getSummarysAll();
        for (OSSObjectSummary summary : summaries) {
            log.info("================================================================");
            log.info("getAll-summary-key = {}", summary.getKey());
            log.info("getAll-summary-size = {}", summary.getSize());
            log.info("getAll-summary-type = {}", summary.getType());
        }
    }


    private void oss(String fileUrl, String objectName) throws IOException {
        log.info("oss baseUrl = {}", fileUrl);
        log.info("oss objectName = {}", objectName);
        AliOssUtil.uploadByUrl(objectName, fileUrl);
    }

}
