rain
2024-06-14 8d9a2d656e4ae007590c622e5f7c228adacdca49
src/main/java/com/dji/sample/component/oss/service/impl/OssServiceContext.java
@@ -6,7 +6,9 @@
import com.dji.sample.media.model.CredentialsDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
@@ -21,16 +23,13 @@
    private IOssService ossService;
    private OssConfiguration configuration;
    @Autowired
    public OssServiceContext(List<IOssService> ossServices, OssConfiguration configuration) {
        this.configuration = configuration;
        if (!configuration.isEnable()) {
        if (!OssConfiguration.enable) {
            return;
        }
        this.ossService = ossServices.stream()
                .filter(ossService -> ossService.getOssType().equals(configuration.getProvider()))
                .filter(ossService -> ossService.getOssType().equals(OssConfiguration.provider))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Oss provider is illegal. Optional: " +
                        Arrays.toString(Arrays.stream(OssTypeEnum.values()).map(OssTypeEnum::getType).toArray())));
@@ -45,6 +44,9 @@
    }
    public URL getObjectUrl(String bucket, String objectKey) {
        if (!StringUtils.hasText(bucket) || !StringUtils.hasText(objectKey)) {
            throw new IllegalArgumentException();
        }
        return this.ossService.getObjectUrl(bucket, objectKey);
    }
@@ -52,7 +54,15 @@
        return this.ossService.deleteObject(bucket, objectKey);
    }
    public byte[] getObject(String bucket, String objectKey) {
    public InputStream getObject(String bucket, String objectKey) {
        return this.ossService.getObject(bucket, objectKey);
    }
    public void putObject(String bucket, String objectKey, InputStream stream) {
        this.ossService.putObject(bucket, objectKey, stream);
    }
    void createClient() {
        this.ossService.createClient();
    }
}