sean.zhou
2022-03-28 7d0facde2378bf5e3709306ed0dfbd9f59967d48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.dji.sample.storage.controller;
 
import com.dji.sample.common.model.ResponseResult;
import com.dji.sample.component.oss.model.AliyunOSSConfiguration;
import com.dji.sample.component.oss.model.MinIOConfiguration;
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;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * @author sean
 * @version 0.3
 * @date 2021/12/29
 */
@RestController
@RequestMapping("${url.storage.prefix}${url.storage.version}/workspaces/")
@Slf4j
public class StorageController {
 
    private IStorageService storageService;
 
    @Autowired
    private void setOssService(@Autowired(required = false) AliyunStorageServiceImpl aliyunStorageService,
                              @Autowired(required = false) MinIOStorageServiceImpl minIOStorageService) {
        if (AliyunOSSConfiguration.enable) {
            this.storageService = aliyunStorageService;
            return;
        }
        if (MinIOConfiguration.enable) {
            this.storageService = minIOStorageService;
            return;
        }
        log.error("storageService is null.");
    }
    /**
     * Get temporary credentials for uploading the media and wayline in DJI Pilot.
     * @param workspaceId
     * @return
     */
    @PostMapping("/{workspace_id}/sts")
    public ResponseResult<StsCredentialsDTO> getSTSCredentials(@PathVariable(name = "workspace_id") String workspaceId) {
 
        StsCredentialsDTO stsCredentials = storageService.getSTSCredentials();
        return ResponseResult.success(stsCredentials);
    }
}