Browse Source

Disable the media module by default

v1.1.0
sean.zhou 3 years ago
parent
commit
7d0facde23
  1. 3
      src/main/java/com/dji/sample/component/oss/model/AliyunOSSConfiguration.java
  2. 3
      src/main/java/com/dji/sample/component/oss/model/MinIOConfiguration.java
  3. 15
      src/main/java/com/dji/sample/component/oss/service/impl/AliyunOssServiceImpl.java
  4. 2
      src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java
  5. 8
      src/main/java/com/dji/sample/storage/controller/StorageController.java
  6. 2
      src/main/java/com/dji/sample/wayline/controller/WaylineFileController.java
  7. 7
      src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java
  8. 2
      src/main/resources/application.yml

3
src/main/java/com/dji/sample/component/oss/model/AliyunOSSConfiguration.java

@ -99,6 +99,9 @@ public class AliyunOSSConfiguration { @@ -99,6 +99,9 @@ public class AliyunOSSConfiguration {
@Bean
@Lazy
public OSS ossClient() {
if (!enable) {
return null;
}
return new OSSClientBuilder().build(endpoint, accessKey, secretKey);
}
}

3
src/main/java/com/dji/sample/component/oss/model/MinIOConfiguration.java

@ -82,6 +82,9 @@ public class MinIOConfiguration { @@ -82,6 +82,9 @@ public class MinIOConfiguration {
@Bean
@Lazy
public MinioClient minioClient() {
if (!enable) {
return null;
}
MinioClient.Builder builder = MinioClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey);

15
src/main/java/com/dji/sample/component/oss/service/impl/AliyunOssServiceImpl.java

@ -27,7 +27,7 @@ import java.util.Date; @@ -27,7 +27,7 @@ import java.util.Date;
@Slf4j
public class AliyunOssServiceImpl implements IOssService {
@Autowired
@Autowired(required = false)
private OSS ossClient;
@Override
@ -58,11 +58,16 @@ public class AliyunOssServiceImpl implements IOssService { @@ -58,11 +58,16 @@ public class AliyunOssServiceImpl implements IOssService {
if (!StringUtils.hasText(bucket) || !StringUtils.hasText(objectKey)) {
return null;
}
// First check if the object can be fetched.
ossClient.getObject(bucket, objectKey);
try {
// First check if the object can be fetched.
ossClient.getObject(bucket, objectKey);
return ossClient.generatePresignedUrl(bucket, objectKey,
new Date(System.currentTimeMillis() + AliyunOSSConfiguration.expire * 1000));
return ossClient.generatePresignedUrl(bucket, objectKey,
new Date(System.currentTimeMillis() + AliyunOSSConfiguration.expire * 1000));
} catch (NullPointerException e) {
e.printStackTrace();
}
return null;
}
}

2
src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java

@ -26,7 +26,7 @@ import java.security.NoSuchAlgorithmException; @@ -26,7 +26,7 @@ import java.security.NoSuchAlgorithmException;
@Slf4j
public class MinIOServiceImpl implements IOssService {
@Autowired
@Autowired(required = false)
private MinioClient client;
@Override

8
src/main/java/com/dji/sample/storage/controller/StorageController.java

@ -7,6 +7,7 @@ import com.dji.sample.media.model.StsCredentialsDTO; @@ -7,6 +7,7 @@ import com.dji.sample.media.model.StsCredentialsDTO;
import com.dji.sample.storage.service.IStorageService;
import com.dji.sample.storage.service.impl.AliyunStorageServiceImpl;
import com.dji.sample.storage.service.impl.MinIOStorageServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@ -20,13 +21,14 @@ import org.springframework.web.bind.annotation.RestController; @@ -20,13 +21,14 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("${url.storage.prefix}${url.storage.version}/workspaces/")
@Slf4j
public class StorageController {
private IStorageService storageService;
@Autowired
private void setOssService(@Autowired AliyunStorageServiceImpl aliyunStorageService,
@Autowired MinIOStorageServiceImpl minIOStorageService) {
private void setOssService(@Autowired(required = false) AliyunStorageServiceImpl aliyunStorageService,
@Autowired(required = false) MinIOStorageServiceImpl minIOStorageService) {
if (AliyunOSSConfiguration.enable) {
this.storageService = aliyunStorageService;
return;
@ -35,7 +37,7 @@ public class StorageController { @@ -35,7 +37,7 @@ public class StorageController {
this.storageService = minIOStorageService;
return;
}
throw new NullPointerException("storageService is null.");
log.error("storageService is null.");
}
/**
* Get temporary credentials for uploading the media and wayline in DJI Pilot.

2
src/main/java/com/dji/sample/wayline/controller/WaylineFileController.java

@ -75,7 +75,7 @@ public class WaylineFileController { @@ -75,7 +75,7 @@ public class WaylineFileController {
try {
response.sendRedirect(url.toString());
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
}

7
src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java

@ -15,6 +15,7 @@ import com.dji.sample.wayline.model.WaylineFileDTO; @@ -15,6 +15,7 @@ import com.dji.sample.wayline.model.WaylineFileDTO;
import com.dji.sample.wayline.model.WaylineFileEntity;
import com.dji.sample.wayline.model.WaylineQueryParam;
import com.dji.sample.wayline.service.IWaylineFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -33,6 +34,7 @@ import java.util.stream.Collectors; @@ -33,6 +34,7 @@ import java.util.stream.Collectors;
*/
@Service
@Transactional
@Slf4j
public class WaylineFileServiceImpl implements IWaylineFileService {
@Autowired
@ -41,7 +43,8 @@ public class WaylineFileServiceImpl implements IWaylineFileService { @@ -41,7 +43,8 @@ public class WaylineFileServiceImpl implements IWaylineFileService {
private IOssService ossService;
@Autowired
private void setOssService(@Autowired AliyunOssServiceImpl aliyunOssService, @Autowired MinIOServiceImpl minIOService) {
private void setOssService(@Autowired(required = false) AliyunOssServiceImpl aliyunOssService,
@Autowired(required = false) MinIOServiceImpl minIOService) {
if (AliyunOSSConfiguration.enable) {
this.ossService = aliyunOssService;
return;
@ -50,7 +53,7 @@ public class WaylineFileServiceImpl implements IWaylineFileService { @@ -50,7 +53,7 @@ public class WaylineFileServiceImpl implements IWaylineFileService {
this.ossService = minIOService;
return;
}
throw new NullPointerException("ossService is null.");
log.error("ossService is null.");
}
@Override

2
src/main/resources/application.yml

@ -58,7 +58,7 @@ url: @@ -58,7 +58,7 @@ url:
# Tutorial: https://help.aliyun.com/document_detail/100624.htm?spm=a2c4g.11186623.0.0.74075e34eIhK7T#concept-xzh-nzk-2gb
aliyun:
oss:
enable: true
enable: false
endpoint: Please enter your endpoint. # Example: https://oss-cn-shenzhen.aliyuncs.com
access-key: Please enter your access key.
secret-key: Please enter your secret key.

Loading…
Cancel
Save