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;
|
}
|
}
|