guoshilong
2023-10-12 f61c1902e30b0ab54e833960df7d2d79c8b62120
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.dji.sample.media.controller;
 
import com.dji.sample.common.model.ResponseResult;
import com.dji.sample.component.mqtt.model.MapKeyConst;
import com.dji.sample.media.model.FileUploadDTO;
import com.dji.sample.media.service.IMediaService;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
/**
 * @author sean
 * @version 0.2
 * @date 2021/12/7
 */
@Slf4j
@RestController
@RequestMapping("${url.media.prefix}${url.media.version}/workspaces")
public class MediaController {
 
    @Autowired
    private IMediaService mediaService;
 
    /**
     * Check if the file has been uploaded by the fingerprint.
     * 检查文件是否已通过指纹上传。
     * @param workspaceId
     * @param file
     * @return
     */
    @PostMapping("/{workspace_id}/fast-upload")
    public ResponseResult fastUpload(@PathVariable(name = "workspace_id") String workspaceId, @RequestBody FileUploadDTO file) {
 
        boolean isExist = mediaService.fastUpload(workspaceId, file.getFingerprint());
 
        return isExist ? ResponseResult.success() : ResponseResult.error(file.getFingerprint() + "不存在");
    }
 
    /**
     * When the file is uploaded to the storage server by pilot,
     * the basic information of the file is reported through this interface.
     * @param workspaceId
     * @param file
     * @return
     */
    @PostMapping("/{workspace_id}/upload-callback")
    public ResponseResult<String> uploadCallback(@PathVariable(name = "workspace_id") String workspaceId, @RequestBody FileUploadDTO file) {
        mediaService.saveMediaFile(workspaceId, file);
        return ResponseResult.success(file.getObjectKey());
 
    }
 
    /**
     * Query the files that already exist in this workspace based on the workspace id and the collection of tiny fingerprints.
     * @param workspaceId
     * @param tinyFingerprints  There is only one tiny_fingerprint parameter in the body.
     *                          But it is not recommended to use Map to receive the parameter.
     * @return
     */
    @PostMapping("/{workspace_id}/files/tiny-fingerprints")
    public ResponseResult<Map<String, List<String>>> uploadCallback(
                                @PathVariable(name = "workspace_id") String workspaceId,
                               @RequestBody Map<String, List<String>> tinyFingerprints) throws JsonProcessingException {
 
        List<String> existingList = mediaService.getExistTinyFingerprints(workspaceId, tinyFingerprints.get(MapKeyConst.TINY_FINGERPRINTS));
        return ResponseResult.success(new ConcurrentHashMap<>(Map.of(MapKeyConst.TINY_FINGERPRINTS, existingList)));
    }
 
}