package com.fdkankan.fyun.oss.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.fdkankan.fyun.config.FYunFileConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnProperty(name = "fyun.type", havingValue = "oss")
public class OssConfig {

    @Autowired
    private FYunFileConfig fYunFileConfig;

    /**
     * new OSSClient操作完成后，请通过shutdown进行关闭，保证new OSSClient和ossClient.shutdown成对使用。
     * @return
     */
    @Bean
    public OSS ossClient(){
        return new OSSClientBuilder().build(fYunFileConfig.getEndPoint(), fYunFileConfig.getKey(), fYunFileConfig.getSecret());
    }
}
