|
@@ -1,137 +1,137 @@
|
|
|
-package cn.com.qmth.examcloud.exchange.inner.api.controller;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
-import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
|
|
|
-import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
-import cn.com.qmth.examcloud.commons.util.AES;
|
|
|
-import cn.com.qmth.examcloud.commons.util.MD5;
|
|
|
-import cn.com.qmth.examcloud.commons.util.UUID;
|
|
|
-import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
|
|
|
-import cn.com.qmth.examcloud.web.config.SystemProperties;
|
|
|
-import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
|
|
|
-import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
|
|
|
-import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
-import cn.com.qmth.examcloud.web.upyun.UpyunService;
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.poi.util.IOUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import javax.servlet.ServletInputStream;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
-/**
|
|
|
- * Upyun服务
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @date 2018年11月21日
|
|
|
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
- */
|
|
|
-@RestController
|
|
|
-@RequestMapping("${$rmp.ctr.exchange.inner}/upyun")
|
|
|
-public class UpyunController extends ControllerSupport {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- SystemProperties systemConfig;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- UpyunService upyunService;
|
|
|
-
|
|
|
- // 保存照片
|
|
|
- @PutMapping("put/{siteId}/{fileSuffix}")
|
|
|
- public String putFile(@PathVariable String siteId, @PathVariable String fileSuffix,
|
|
|
- @RequestParam(required = false) String md5, HttpServletRequest req) {
|
|
|
-
|
|
|
- String contentLength = req.getHeader("Content-Length");
|
|
|
- if (StringUtils.isNotBlank(contentLength)) {
|
|
|
- long contentLengthLong = Long.parseLong(contentLength);
|
|
|
- if (contentLengthLong < 10) {
|
|
|
- throw new StatusException("600108", "empty IO stream");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isNotBlank(md5)) {
|
|
|
- if (MD5.encrypt16("").equalsIgnoreCase(md5)) {
|
|
|
- throw new StatusException("600109", "empty IO stream");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- User accessUser = getAccessUser();
|
|
|
-
|
|
|
- if (!fileSuffix.matches("\\w+")) {
|
|
|
- throw new StatusException("600100", "fileSuffix is wrong");
|
|
|
- }
|
|
|
-
|
|
|
- fileSuffix = "." + fileSuffix;
|
|
|
-
|
|
|
- ServletInputStream in = null;
|
|
|
-
|
|
|
- if (StringUtils.isNotBlank(md5)) {
|
|
|
-
|
|
|
- try {
|
|
|
- in = req.getInputStream();
|
|
|
-
|
|
|
- //通用存储
|
|
|
- FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
- env.setRootOrgId(String.valueOf(accessUser.getRootOrgId()));
|
|
|
- env.setUserId(String.valueOf(accessUser.getUserId()));
|
|
|
- env.setFileSuffix(fileSuffix);
|
|
|
- YunPathInfo pi = FileStorageUtil.saveFile(siteId, env, in, md5);
|
|
|
- String url = pi.getUrl();
|
|
|
-
|
|
|
- url = new AES().encrypt(url);
|
|
|
- return url;
|
|
|
- } catch (IOException e) {
|
|
|
- throw new ExamCloudRuntimeException(e);
|
|
|
- } finally {
|
|
|
- IOUtils.closeQuietly(in);
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- try {
|
|
|
- FileUtils.forceMkdir(new File(systemConfig.getTempDataDir()));
|
|
|
- } catch (IOException e1) {
|
|
|
- LOGGER.error("fail to make dir. path=" + systemConfig.getTempDataDir());
|
|
|
- }
|
|
|
-
|
|
|
- String filePath = systemConfig.getTempDataDir() + File.separator + UUID.randomUUID()
|
|
|
- + fileSuffix;
|
|
|
- File file = new File(filePath);
|
|
|
-
|
|
|
- FileOutputStream out = null;
|
|
|
- try {
|
|
|
- in = req.getInputStream();
|
|
|
- out = new FileOutputStream(file);
|
|
|
- IOUtils.copy(in, out);
|
|
|
-
|
|
|
- //通用存储
|
|
|
- FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
- env.setRootOrgId(String.valueOf(accessUser.getRootOrgId()));
|
|
|
- env.setUserId(String.valueOf(accessUser.getUserId()));
|
|
|
- env.setFileSuffix(fileSuffix);
|
|
|
- YunPathInfo pi = FileStorageUtil.saveFile(siteId, env, file, true);
|
|
|
- String url = pi.getUrl();
|
|
|
- url = new AES().encrypt(url);
|
|
|
- return url;
|
|
|
- } catch (IOException e) {
|
|
|
- throw new ExamCloudRuntimeException(e);
|
|
|
- } finally {
|
|
|
- IOUtils.closeQuietly(in);
|
|
|
- IOUtils.closeQuietly(out);
|
|
|
- try {
|
|
|
- FileUtils.forceDelete(file);
|
|
|
- } catch (IOException e) {
|
|
|
- LOGGER.error("fail to delete file. path=" + filePath);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+// package cn.com.qmth.examcloud.exchange.inner.api.controller;
|
|
|
+//
|
|
|
+// import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
+// import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
|
|
|
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+// import cn.com.qmth.examcloud.commons.util.AES;
|
|
|
+// import cn.com.qmth.examcloud.commons.util.MD5;
|
|
|
+// import cn.com.qmth.examcloud.commons.util.UUID;
|
|
|
+// import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
|
|
|
+// import cn.com.qmth.examcloud.web.config.SystemProperties;
|
|
|
+// import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
|
|
|
+// import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
|
|
|
+// import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
+// import cn.com.qmth.examcloud.web.upyun.UpyunService;
|
|
|
+// import org.apache.commons.io.FileUtils;
|
|
|
+// import org.apache.commons.lang3.StringUtils;
|
|
|
+// import org.apache.poi.util.IOUtils;
|
|
|
+// import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+// import org.springframework.web.bind.annotation.*;
|
|
|
+//
|
|
|
+// import javax.servlet.ServletInputStream;
|
|
|
+// import javax.servlet.http.HttpServletRequest;
|
|
|
+// import java.io.File;
|
|
|
+// import java.io.FileOutputStream;
|
|
|
+// import java.io.IOException;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * Upyun服务
|
|
|
+// *
|
|
|
+// * @author WANGWEI
|
|
|
+// * @date 2018年11月21日
|
|
|
+// * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+// */
|
|
|
+// @RestController
|
|
|
+// @RequestMapping("${$rmp.ctr.exchange.inner}/upyun")
|
|
|
+// public class UpyunController extends ControllerSupport {
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// SystemProperties systemConfig;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// UpyunService upyunService;
|
|
|
+//
|
|
|
+// // 保存照片
|
|
|
+// @PutMapping("put/{siteId}/{fileSuffix}")
|
|
|
+// public String putFile(@PathVariable String siteId, @PathVariable String fileSuffix,
|
|
|
+// @RequestParam(required = false) String md5, HttpServletRequest req) {
|
|
|
+//
|
|
|
+// String contentLength = req.getHeader("Content-Length");
|
|
|
+// if (StringUtils.isNotBlank(contentLength)) {
|
|
|
+// long contentLengthLong = Long.parseLong(contentLength);
|
|
|
+// if (contentLengthLong < 10) {
|
|
|
+// throw new StatusException("600108", "empty IO stream");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (StringUtils.isNotBlank(md5)) {
|
|
|
+// if (MD5.encrypt16("").equalsIgnoreCase(md5)) {
|
|
|
+// throw new StatusException("600109", "empty IO stream");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// User accessUser = getAccessUser();
|
|
|
+//
|
|
|
+// if (!fileSuffix.matches("\\w+")) {
|
|
|
+// throw new StatusException("600100", "fileSuffix is wrong");
|
|
|
+// }
|
|
|
+//
|
|
|
+// fileSuffix = "." + fileSuffix;
|
|
|
+//
|
|
|
+// ServletInputStream in = null;
|
|
|
+//
|
|
|
+// if (StringUtils.isNotBlank(md5)) {
|
|
|
+//
|
|
|
+// try {
|
|
|
+// in = req.getInputStream();
|
|
|
+//
|
|
|
+// //通用存储
|
|
|
+// FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
+// env.setRootOrgId(String.valueOf(accessUser.getRootOrgId()));
|
|
|
+// env.setUserId(String.valueOf(accessUser.getUserId()));
|
|
|
+// env.setFileSuffix(fileSuffix);
|
|
|
+// YunPathInfo pi = FileStorageUtil.saveFile(siteId, env, in, md5);
|
|
|
+// String url = pi.getUrl();
|
|
|
+//
|
|
|
+// url = new AES().encrypt(url);
|
|
|
+// return url;
|
|
|
+// } catch (IOException e) {
|
|
|
+// throw new ExamCloudRuntimeException(e);
|
|
|
+// } finally {
|
|
|
+// IOUtils.closeQuietly(in);
|
|
|
+// }
|
|
|
+//
|
|
|
+// } else {
|
|
|
+//
|
|
|
+// try {
|
|
|
+// FileUtils.forceMkdir(new File(systemConfig.getTempDataDir()));
|
|
|
+// } catch (IOException e1) {
|
|
|
+// LOGGER.error("fail to make dir. path=" + systemConfig.getTempDataDir());
|
|
|
+// }
|
|
|
+//
|
|
|
+// String filePath = systemConfig.getTempDataDir() + File.separator + UUID.randomUUID()
|
|
|
+// + fileSuffix;
|
|
|
+// File file = new File(filePath);
|
|
|
+//
|
|
|
+// FileOutputStream out = null;
|
|
|
+// try {
|
|
|
+// in = req.getInputStream();
|
|
|
+// out = new FileOutputStream(file);
|
|
|
+// IOUtils.copy(in, out);
|
|
|
+//
|
|
|
+// //通用存储
|
|
|
+// FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
+// env.setRootOrgId(String.valueOf(accessUser.getRootOrgId()));
|
|
|
+// env.setUserId(String.valueOf(accessUser.getUserId()));
|
|
|
+// env.setFileSuffix(fileSuffix);
|
|
|
+// YunPathInfo pi = FileStorageUtil.saveFile(siteId, env, file, true);
|
|
|
+// String url = pi.getUrl();
|
|
|
+// url = new AES().encrypt(url);
|
|
|
+// return url;
|
|
|
+// } catch (IOException e) {
|
|
|
+// throw new ExamCloudRuntimeException(e);
|
|
|
+// } finally {
|
|
|
+// IOUtils.closeQuietly(in);
|
|
|
+// IOUtils.closeQuietly(out);
|
|
|
+// try {
|
|
|
+// FileUtils.forceDelete(file);
|
|
|
+// } catch (IOException e) {
|
|
|
+// LOGGER.error("fail to delete file. path=" + filePath);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|