| | |
| | | */ |
| | | package org.springblade.modules.resource.endpoint; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.JSONPObject; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import org.springblade.common.utils.ImageUtils; |
| | | import org.springblade.common.utils.WeiXinSecurityUtil; |
| | | import org.springblade.core.launch.constant.AppConstant; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.oss.model.OssFile; |
| | |
| | | import org.springblade.modules.resource.service.IAttachService; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.BufferedReader; |
| | | import java.io.DataOutputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStream; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | |
| | | /** |
| | | * 对象存储端点 |
| | |
| | | // 修改link |
| | | changeLink(bladeFile); |
| | | // 返回 |
| | | return R.data(bladeFile); |
| | | return R.data(200,bladeFile,""); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param file 文件 |
| | | * @param prefixPath 文件 |
| | | * @param isCheck 是否校验 |
| | | * @return ObjectStat |
| | | */ |
| | | @SneakyThrows |
| | | @PostMapping("/put-file-by-prefix-path") |
| | | public R<BladeFile> putFileByPrefixPath(@RequestParam MultipartFile file,@RequestParam(required = false) String prefixPath) { |
| | | public R<BladeFile> putFileByPrefixPath(@RequestParam MultipartFile file, |
| | | @RequestParam(required = false) String prefixPath, |
| | | @RequestParam(required = false) Integer isCheck) { |
| | | // 不传默认不检验 |
| | | if(null!=isCheck){ |
| | | String checkResult = WeiXinSecurityUtil.checkImg(file); |
| | | JSONObject jsonObject = JSONObject.parseObject(checkResult); |
| | | Integer errorCode = Integer.parseInt(jsonObject.getString("errcode")); |
| | | if (errorCode!=0){ |
| | | return R.data(201,null,"图片存在敏感内容,请更换其他图片!"); |
| | | } |
| | | } |
| | | BladeFile bladeFile = ossBuilder.templateByPrefixPath(prefixPath).putFile(file.getOriginalFilename(), file.getInputStream()); |
| | | // 修改link |
| | | changeLink(bladeFile); |
| | | return R.data(bladeFile); |
| | | return R.data(200,bladeFile,""); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param file 文件 |
| | | * @param prefixPath 文件 |
| | | * @param isCheck 是否校验 |
| | | * @return ObjectStat |
| | | */ |
| | | @SneakyThrows |
| | | @PostMapping("/put-file-attach-by-prefix-path") |
| | | public R<BladeFile> putFileAttachByPrefixPath(@RequestParam MultipartFile file,@RequestParam(required = false) String prefixPath) { |
| | | public R<BladeFile> putFileAttachByPrefixPath(@RequestParam MultipartFile file, |
| | | @RequestParam(required = false) String prefixPath, |
| | | @RequestParam(required = false) Integer isCheck) { |
| | | // 不传默认不检验 |
| | | if(null!=isCheck){ |
| | | String checkResult = WeiXinSecurityUtil.checkImg(file); |
| | | JSONObject jsonObject = JSONObject.parseObject(checkResult); |
| | | Integer errorCode = Integer.parseInt(jsonObject.getString("errcode")); |
| | | if (errorCode!=0){ |
| | | return R.data(201,null,"图片存在敏感内容,请更换其他图片!"); |
| | | } |
| | | } |
| | | String fileName = file.getOriginalFilename(); |
| | | BladeFile bladeFile = ossBuilder.templateByPrefixPath(prefixPath).putFile(file.getOriginalFilename(), file.getInputStream()); |
| | | Long attachId = buildAttach(fileName, file.getSize(), bladeFile); |
| | |
| | | bladeFile.setAttachId(attachId); |
| | | // 修改link |
| | | changeLink(bladeFile); |
| | | return R.data(bladeFile); |
| | | return R.data(200,bladeFile,""); |
| | | } |
| | | |
| | | /** |
| | |
| | | return R.success("操作成功"); |
| | | } |
| | | |
| | | |
| | | } |