133334444
This commit is contained in:
parent
8ea42a3cf8
commit
ee6cec9d7f
@ -0,0 +1,26 @@
|
||||
package net.lab1024.sa.admin.module.business.file.constant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.lab1024.sa.base.common.enumeration.BaseEnum;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum OSSFileTypeEnum implements BaseEnum {
|
||||
PUBLIC(1, "public"),
|
||||
SIGN(2, "sign"),
|
||||
;
|
||||
|
||||
public static OSSFileTypeEnum getByVal(int val){
|
||||
OSSFileTypeEnum[] values = OSSFileTypeEnum.values();
|
||||
for(OSSFileTypeEnum type:values){
|
||||
if(val == type.getValue()){
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private final Integer value;
|
||||
|
||||
private final String desc;
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
package net.lab1024.sa.admin.module.business.file.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.common.utils.BinaryUtil;
|
||||
import com.aliyun.oss.model.MatchMode;
|
||||
import com.aliyun.oss.model.PolicyConditions;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import net.lab1024.sa.admin.config.OssConfig;
|
||||
import net.lab1024.sa.admin.constant.AdminSwaggerTagConst;
|
||||
import net.lab1024.sa.admin.module.business.file.constant.OSSFileTypeEnum;
|
||||
import net.lab1024.sa.admin.module.business.file.domain.vo.OSSPolicyVO;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import net.lab1024.sa.base.common.util.SmartRequestUtil;
|
||||
import net.lab1024.sa.base.constant.SwaggerTagConst;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
@RestController
|
||||
@Tag(name = SwaggerTagConst.Support.FILE)
|
||||
public class OSSFileController {
|
||||
|
||||
@Resource
|
||||
private OssConfig ossConfig;
|
||||
|
||||
@Operation(summary = "获取上传文件 Policy, notes=\"type==1 普通;type==2 签名图片\"")
|
||||
@GetMapping("/file/getOSSPolicy/{type}")
|
||||
@SaCheckPermission("ossFile:add")
|
||||
public ResponseDTO<OSSPolicyVO> getOSSPolicy(@PathVariable int type){
|
||||
OSSFileTypeEnum ossFileType = OSSFileTypeEnum.getByVal(type);
|
||||
Long requestUserId = SmartRequestUtil.getRequestUserId();
|
||||
String dir = ossFileType.getDesc() + File.separator + "images/";
|
||||
// String dir = ossFileType.getDesc() + File.separator + requestUserId + File.separator;
|
||||
// callbackUrl为 上传回调服务器的URL,请将下面的IP和Port配置为您自己的真实信息。
|
||||
OSSClient client = new OSSClient(ossConfig.getEndpoint(), ossConfig.getAccessKey(), ossConfig.getAccessKeySecret());
|
||||
try {
|
||||
long expireTime = 30;
|
||||
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
|
||||
Date expiration = new Date(expireEndTime);
|
||||
PolicyConditions policyConds = new PolicyConditions();
|
||||
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 10*1024*1024);// 最大 10 M
|
||||
policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, ossFileType.getDesc());
|
||||
|
||||
String postPolicy = client.generatePostPolicy(expiration, policyConds);
|
||||
byte[] binaryData = postPolicy.getBytes("utf-8");
|
||||
String encodedPolicy = BinaryUtil.toBase64String(binaryData);
|
||||
String postSignature = client.calculatePostSignature(postPolicy);
|
||||
|
||||
|
||||
OSSPolicyVO policyVO = new OSSPolicyVO(ossConfig.getAccessKey(), encodedPolicy, postSignature, dir, ossConfig.getCustomDomainName(), String.valueOf(expireEndTime / 1000));
|
||||
return ResponseDTO.ok(policyVO);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseDTO.userErrorParam();
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取上传文件 Policy, notes=\"type==1 普通;type==2 签名图片\"")
|
||||
@GetMapping("/file/getOSSPolicy/admin/{type}")
|
||||
@SaCheckPermission("ossFile:addAdmin")
|
||||
|
||||
public ResponseDTO<OSSPolicyVO> getOSSPolicyAdmin(@PathVariable int type){
|
||||
OSSFileTypeEnum ossFileType = OSSFileTypeEnum.getByVal(type);
|
||||
Long requestUserId = SmartRequestUtil.getRequestUserId();
|
||||
String dir = ossFileType.getDesc() + File.separator + "images/";
|
||||
// String dir = ossFileType.getDesc() + File.separator + requestUserId + File.separator;
|
||||
// callbackUrl为 上传回调服务器的URL,请将下面的IP和Port配置为您自己的真实信息。
|
||||
OSSClient client = new OSSClient(ossConfig.getEndpoint(), ossConfig.getAccessKey(), ossConfig.getAccessKeySecret());
|
||||
try {
|
||||
long expireTime = 30;
|
||||
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
|
||||
Date expiration = new Date(expireEndTime);
|
||||
PolicyConditions policyConds = new PolicyConditions();
|
||||
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 10*1024*1024);// 最大 10 M
|
||||
policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, ossFileType.getDesc());
|
||||
|
||||
String postPolicy = client.generatePostPolicy(expiration, policyConds);
|
||||
byte[] binaryData = postPolicy.getBytes("utf-8");
|
||||
String encodedPolicy = BinaryUtil.toBase64String(binaryData);
|
||||
String postSignature = client.calculatePostSignature(postPolicy);
|
||||
|
||||
|
||||
OSSPolicyVO policyVO = new OSSPolicyVO(ossConfig.getAccessKey(), encodedPolicy, postSignature, dir, ossConfig.getCustomDomainName(), String.valueOf(expireEndTime / 1000));
|
||||
return ResponseDTO.ok(policyVO);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseDTO.userErrorParam();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package net.lab1024.sa.admin.module.business.file.domain.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class OSSPolicyVO {
|
||||
|
||||
@Schema(description = "OSS accessid")
|
||||
private String accessid;
|
||||
|
||||
@Schema(description = "OSS policy")
|
||||
private String policy;
|
||||
|
||||
@Schema(description = "OSS 签名")
|
||||
private String signature;
|
||||
|
||||
@Schema(description = "OSS 上传路径")
|
||||
private String dir;
|
||||
|
||||
@Schema(description = "OSS host")
|
||||
private String host;
|
||||
|
||||
@Schema(description = "OSS 过期时间")
|
||||
private String expire;
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
package net.lab1024.sa.admin.module.system.support;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import net.lab1024.sa.base.common.controller.SupportBaseController;
|
||||
|
||||
import net.lab1024.sa.base.constant.SwaggerTagConst;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* UEditor配置接口
|
||||
*
|
||||
* @Author 1024创新实验室: 罗伊
|
||||
* @Date 2024年12月19日
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
@RestController
|
||||
@Tag(name = SwaggerTagConst.Support.FILE)
|
||||
public class AdminUEditorController extends SupportBaseController {
|
||||
|
||||
@Operation(summary = "获取UEditor配置 @author 1024创新实验室")
|
||||
@GetMapping("/ueditor/config")
|
||||
public Map<String, Object> getUEditorConfig() {
|
||||
// UEditor期望的配置格式:直接的配置对象,支持JSONP
|
||||
Map<String, Object> config = new HashMap<>();
|
||||
|
||||
// 图片上传配置
|
||||
config.put("imageActionName", "uploadimage");
|
||||
config.put("imageFieldName", "file");
|
||||
config.put("imageMaxSize", 8388608);
|
||||
config.put("imageAllowFiles", new String[]{".jpg", ".png", ".jpeg"});
|
||||
config.put("imageCompressEnable", false);
|
||||
config.put("imageCompressBorder", 5000);
|
||||
config.put("imageInsertAlign", "none");
|
||||
config.put("imageUrlPrefix", "");
|
||||
|
||||
// 涂鸦配置
|
||||
config.put("scrawlActionName", "uploadscrawl");
|
||||
config.put("scrawlFieldName", "file");
|
||||
config.put("scrawlMaxSize", 10485760);
|
||||
config.put("scrawlUrlPrefix", "");
|
||||
config.put("scrawlInsertAlign", "none");
|
||||
|
||||
// 截图配置
|
||||
config.put("snapscreenActionName", "uploadimage");
|
||||
config.put("snapscreenUrlPrefix", "");
|
||||
config.put("snapscreenInsertAlign", "none");
|
||||
|
||||
// 图片抓取配置
|
||||
config.put("catcherActionName", "catchimage");
|
||||
config.put("catcherFieldName", "source");
|
||||
config.put("catcherLocalDomain", new String[]{"127.0.0.1", "localhost"});
|
||||
config.put("catcherUrlPrefix", "");
|
||||
config.put("catcherMaxSize", 10485760);
|
||||
config.put("catcherAllowFiles", new String[]{".jpg", ".png", ".jpeg"});
|
||||
|
||||
// 视频上传配置
|
||||
config.put("videoActionName", "uploadvideo");
|
||||
config.put("videoFieldName", "file");
|
||||
config.put("videoUrlPrefix", "");
|
||||
config.put("videoMaxSize", 104857600);
|
||||
config.put("videoAllowFiles", new String[]{".mp4"});
|
||||
|
||||
// 文件上传配置
|
||||
config.put("fileActionName", "uploadfile");
|
||||
config.put("fileFieldName", "file");
|
||||
config.put("fileUrlPrefix", "");
|
||||
config.put("fileMaxSize", 104857600);
|
||||
config.put("fileAllowFiles", new String[]{".zip", ".pdf", ".doc"});
|
||||
|
||||
// 图片管理配置
|
||||
config.put("imageManagerActionName", "listimage");
|
||||
config.put("imageManagerListSize", 20);
|
||||
config.put("imageManagerUrlPrefix", "");
|
||||
config.put("imageManagerInsertAlign", "none");
|
||||
config.put("imageManagerAllowFiles", new String[]{".jpg", ".png", ".jpeg"});
|
||||
|
||||
// 文件管理配置
|
||||
config.put("fileManagerActionName", "listfile");
|
||||
config.put("fileManagerUrlPrefix", "");
|
||||
config.put("fileManagerListSize", 20);
|
||||
config.put("fileManagerAllowFiles", new String[]{".zip", ".pdf", ".doc"});
|
||||
|
||||
// 公式配置
|
||||
Map<String, String> formulaConfig = new HashMap<>();
|
||||
formulaConfig.put("imageUrlTemplate", "https://r.latexeasy.com/image.svg?{}");
|
||||
config.put("formulaConfig", formulaConfig);
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
71
sa-admin/src/main/resources/static/ueditor-config.json
Normal file
71
sa-admin/src/main/resources/static/ueditor-config.json
Normal file
@ -0,0 +1,71 @@
|
||||
{
|
||||
"imageActionName": "image",
|
||||
"imageFieldName": "file",
|
||||
"imageMaxSize": 8388608,
|
||||
"imageAllowFiles": [
|
||||
".jpg",
|
||||
".png",
|
||||
".jpeg"
|
||||
],
|
||||
"imageCompressEnable": false,
|
||||
"imageCompressBorder": 5000,
|
||||
"imageInsertAlign": "none",
|
||||
"imageUrlPrefix": "",
|
||||
"scrawlActionName": "crawl",
|
||||
"scrawlFieldName": "file",
|
||||
"scrawlMaxSize": 10485760,
|
||||
"scrawlUrlPrefix": "",
|
||||
"scrawlInsertAlign": "none",
|
||||
"snapscreenActionName": "snap",
|
||||
"snapscreenUrlPrefix": "",
|
||||
"snapscreenInsertAlign": "none",
|
||||
"catcherActionName": "catch",
|
||||
"catcherFieldName": "source",
|
||||
"catcherLocalDomain": [
|
||||
"127.0.0.1",
|
||||
"localhost"
|
||||
],
|
||||
"catcherUrlPrefix": "",
|
||||
"catcherMaxSize": 10485760,
|
||||
"catcherAllowFiles": [
|
||||
".jpg",
|
||||
".png",
|
||||
".jpeg"
|
||||
],
|
||||
"videoActionName": "video",
|
||||
"videoFieldName": "file",
|
||||
"videoUrlPrefix": "",
|
||||
"videoMaxSize": 104857600,
|
||||
"videoAllowFiles": [
|
||||
".mp4"
|
||||
],
|
||||
"fileActionName": "file",
|
||||
"fileFieldName": "file",
|
||||
"fileUrlPrefix": "",
|
||||
"fileMaxSize": 104857600,
|
||||
"fileAllowFiles": [
|
||||
".zip",
|
||||
".pdf",
|
||||
".doc"
|
||||
],
|
||||
"imageManagerActionName": "listImage",
|
||||
"imageManagerListSize": 20,
|
||||
"imageManagerUrlPrefix": "",
|
||||
"imageManagerInsertAlign": "none",
|
||||
"imageManagerAllowFiles": [
|
||||
".jpg",
|
||||
".png",
|
||||
".jpeg"
|
||||
],
|
||||
"fileManagerActionName": "listFile",
|
||||
"fileManagerUrlPrefix": "",
|
||||
"fileManagerListSize": 20,
|
||||
"fileManagerAllowFiles": [
|
||||
".zip",
|
||||
".pdf",
|
||||
".doc"
|
||||
],
|
||||
"formulaConfig": {
|
||||
"imageUrlTemplate": "https://r.latexeasy.com/image.svg?{}"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user