无人机项目后端代码
sean.zhou
2022-12-12 2d8ded3e77b22e44985265ca4063102662e452c1
src/main/java/com/dji/sample/component/oss/service/impl/OssServiceContext.java
@@ -6,6 +6,7 @@
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;
@@ -22,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())));
@@ -46,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);
    }
@@ -60,4 +61,8 @@
    public void putObject(String bucket, String objectKey, InputStream stream) {
        this.ossService.putObject(bucket, objectKey, stream);
    }
    void createClient() {
        this.ossService.createClient();
    }
}