lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
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
package com.rongyichuang.judge.api;
 
import com.rongyichuang.judge.dto.response.CosCredentialsResponse;
import com.rongyichuang.judge.service.CosService;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.stereotype.Controller;
 
import java.util.Map;
import java.util.UUID;
 
@Controller
public class CosGraphqlApi {
 
    private final CosService cosService;
 
    public CosGraphqlApi(CosService cosService) {
        this.cosService = cosService;
    }
 
    @QueryMapping
    public CosCredentialsResponse getUploadCredentials() {
        // 生成随机文件名
        String fileName = UUID.randomUUID().toString() + ".jpg";
        Map<String, String> credentials = cosService.generateUploadCredentials(fileName);
        
        CosCredentialsResponse response = new CosCredentialsResponse();
        response.setBucket(credentials.get("bucket"));
        response.setRegion(credentials.get("region"));
        response.setKey(credentials.get("key"));
        response.setPresignedUrl(credentials.get("presignedUrl"));
        response.setExpiration(credentials.get("expiration"));
        
        return response;
    }
}