Xiajijian
2025-11-13 e597d3460451e164d9caa7127b7aa4098db1ad29
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
package com.ard.web.controller.sample.media;
 
import com.ard.sample.common.model.ResponseResult;
import com.ard.sample.component.mqtt.model.MapKeyConst;
import com.ard.sample.media.model.FileUploadDTO;
import com.ard.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("/dock/media/workspaces")
public class MediaController {
 
    @Autowired
    private IMediaService mediaService;
 
    /**
     * Check if the file has been uploaded by the fingerprint.
     * @param file
     * @return
     */
    @PostMapping("/fast-upload")
    public ResponseResult fastUpload( @RequestBody FileUploadDTO file) {
 
        boolean isExist = mediaService.fastUpload(file.getFingerprint());
 
        return isExist ? ResponseResult.success() : ResponseResult.error(file.getFingerprint() + "don't exist.");
    }
 
    /**
     * When the file is uploaded to the storage server by pilot,
     * the basic information of the file is reported through this interface.
     * @param file
     * @return
     */
    @PostMapping("/upload-callback")
    public ResponseResult<String> uploadCallback(@RequestBody FileUploadDTO file) {
        mediaService.saveMediaFile(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 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("/files/tiny-fingerprints")
    public ResponseResult<Map<String, List<String>>> uploadCallback(
                               @RequestBody Map<String, List<String>> tinyFingerprints){
 
        List<String> existingList = mediaService.getExistTinyFingerprints(tinyFingerprints.get(MapKeyConst.TINY_FINGERPRINTS));
        return ResponseResult.success(new ConcurrentHashMap<>(Map.of(MapKeyConst.TINY_FINGERPRINTS, existingList)));
    }
 
}