mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-28 16:22:45 +08:00
minio-token返回resource_type
This commit is contained in:
parent
9792366256
commit
c126e47823
@ -7,7 +7,7 @@ public class BackendConstant {
|
|||||||
|
|
||||||
public final static String[] UN_AUTH_URI_WHITELIST = {"/backend/v1/system/image-captcha", "/backend/v1/auth/login",};
|
public final static String[] UN_AUTH_URI_WHITELIST = {"/backend/v1/system/image-captcha", "/backend/v1/auth/login",};
|
||||||
|
|
||||||
public final static String[] RESOURCE_EXT_WHITELIST = {"IMAGE", "PDF", "VIDEO", "WORD", "PPT"};
|
public final static String[] RESOURCE_TYPE_WHITELIST = {"IMAGE", "PDF", "VIDEO", "WORD", "PPT"};
|
||||||
public final static HashMap<String, String> RESOURCE_EXT_2_CONTENT_TYPE = new HashMap<>() {{
|
public final static HashMap<String, String> RESOURCE_EXT_2_CONTENT_TYPE = new HashMap<>() {{
|
||||||
put("png", "image/png");
|
put("png", "image/png");
|
||||||
put("jpg", "image/jpg");
|
put("jpg", "image/jpg");
|
||||||
@ -20,6 +20,18 @@ public class BackendConstant {
|
|||||||
put("ppt", "application/vnd.ms-powerpoint");
|
put("ppt", "application/vnd.ms-powerpoint");
|
||||||
put("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation");
|
put("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation");
|
||||||
}};
|
}};
|
||||||
|
public final static HashMap<String, String> RESOURCE_EXT_2_TYPE = new HashMap<>() {{
|
||||||
|
put("png", "IMAGE");
|
||||||
|
put("jpg", "IMAGE");
|
||||||
|
put("jpeg", "IMAGE");
|
||||||
|
put("gif", "IMAGE");
|
||||||
|
put("pdf", "PDF");
|
||||||
|
put("mp4", "VIDEO");
|
||||||
|
put("doc", "WORD");
|
||||||
|
put("docx", "WORD");
|
||||||
|
put("ppt", "PPT");
|
||||||
|
put("pptx", "PPT");
|
||||||
|
}};
|
||||||
|
|
||||||
public final static String[] RESOURCE_DISK_WHITELIST = {"MINIO"};
|
public final static String[] RESOURCE_DISK_WHITELIST = {"MINIO"};
|
||||||
|
|
||||||
|
@ -48,14 +48,14 @@ public class ResourceCategoryController {
|
|||||||
@GetMapping("/create")
|
@GetMapping("/create")
|
||||||
public JsonResponse create() {
|
public JsonResponse create() {
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
data.put("types", BackendConstant.RESOURCE_EXT_WHITELIST);
|
data.put("types", BackendConstant.RESOURCE_TYPE_WHITELIST);
|
||||||
return JsonResponse.data(data);
|
return JsonResponse.data(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public JsonResponse store(@RequestBody @Validated ResourceCategoryRequest req) {
|
public JsonResponse store(@RequestBody @Validated ResourceCategoryRequest req) {
|
||||||
if (!Arrays.asList(BackendConstant.RESOURCE_EXT_WHITELIST).contains(req.getType())) {
|
if (!Arrays.asList(BackendConstant.RESOURCE_TYPE_WHITELIST).contains(req.getType())) {
|
||||||
return JsonResponse.error("资源类型不支持");
|
return JsonResponse.error("资源类型不支持");
|
||||||
}
|
}
|
||||||
resourceCategoryService.create(req.getType(), req.getSort(), req.getName());
|
resourceCategoryService.create(req.getType(), req.getSort(), req.getName());
|
||||||
@ -72,7 +72,7 @@ public class ResourceCategoryController {
|
|||||||
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public JsonResponse update(@PathVariable(name = "id") Integer id, @RequestBody @Validated ResourceCategoryRequest req) throws NotFoundException {
|
public JsonResponse update(@PathVariable(name = "id") Integer id, @RequestBody @Validated ResourceCategoryRequest req) throws NotFoundException {
|
||||||
if (!Arrays.asList(BackendConstant.RESOURCE_EXT_WHITELIST).contains(req.getType())) {
|
if (!Arrays.asList(BackendConstant.RESOURCE_TYPE_WHITELIST).contains(req.getType())) {
|
||||||
return JsonResponse.error("资源类型不支持");
|
return JsonResponse.error("资源类型不支持");
|
||||||
}
|
}
|
||||||
ResourceCategory category = resourceCategoryService.findOrFail(id);
|
ResourceCategory category = resourceCategoryService.findOrFail(id);
|
||||||
|
@ -6,10 +6,7 @@ import io.minio.PutObjectArgs;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import xyz.playedu.api.config.MinioConfig;
|
import xyz.playedu.api.config.MinioConfig;
|
||||||
import xyz.playedu.api.constant.BackendConstant;
|
import xyz.playedu.api.constant.BackendConstant;
|
||||||
@ -90,7 +87,7 @@ public class UploadController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/minio-token")
|
@GetMapping("/minio-token")
|
||||||
public JsonResponse minioToken(@RequestParam HashMap<String, Object> params) {
|
public JsonResponse minioToken(@RequestParam HashMap<String, Object> params) {
|
||||||
String extension = MapUtils.getString(params, "extension");
|
String extension = MapUtils.getString(params, "extension");
|
||||||
if (extension == null || extension.isEmpty()) {
|
if (extension == null || extension.isEmpty()) {
|
||||||
@ -100,12 +97,14 @@ public class UploadController {
|
|||||||
if (contentType == null) {
|
if (contentType == null) {
|
||||||
return JsonResponse.error("该格式不支持上传");
|
return JsonResponse.error("该格式不支持上传");
|
||||||
}
|
}
|
||||||
|
String resourceType = BackendConstant.RESOURCE_EXT_2_TYPE.get(extension.toLowerCase());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PostPolicy postPolicy = new PostPolicy(minioConfig.getBucket(), ZonedDateTime.now().plusDays(1));
|
PostPolicy postPolicy = new PostPolicy(minioConfig.getBucket(), ZonedDateTime.now().plusDays(1));
|
||||||
postPolicy.addStartsWithCondition("Content-Type", contentType);
|
postPolicy.addStartsWithCondition("Content-Type", contentType);
|
||||||
postPolicy.addEqualsCondition("key", HelperUtil.randomString(32));
|
postPolicy.addEqualsCondition("key", HelperUtil.randomString(32));
|
||||||
Map<String, String> data = minioClient.getPresignedPostFormData(postPolicy);
|
Map<String, String> data = minioClient.getPresignedPostFormData(postPolicy);
|
||||||
|
data.put("resource_type", resourceType);
|
||||||
return JsonResponse.data(data);
|
return JsonResponse.data(data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user