|
@@ -10,6 +10,7 @@ import com.ruoyi.common.utils.StringUtils;
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
import com.ruoyi.common.utils.file.FileUtils;
|
|
import com.ruoyi.common.utils.file.FileUtils;
|
|
import com.ruoyi.common.utils.file.ImageUtils;
|
|
import com.ruoyi.common.utils.file.ImageUtils;
|
|
|
|
+import com.ruoyi.common.utils.file.OssUtils;
|
|
import com.ruoyi.framework.config.ServerConfig;
|
|
import com.ruoyi.framework.config.ServerConfig;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -44,6 +45,8 @@ public class CommonController {
|
|
|
|
|
|
private static final String FILE_DELIMETER = ",";
|
|
private static final String FILE_DELIMETER = ",";
|
|
|
|
|
|
|
|
+ private static final String fileUrl = "http://file.iciyuanshidai.com";
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 通用下载请求
|
|
* 通用下载请求
|
|
*
|
|
*
|
|
@@ -70,60 +73,6 @@ public class CommonController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 通用上传请求(单个)
|
|
|
|
- */
|
|
|
|
- @PostMapping("/upload")
|
|
|
|
- public AjaxResult uploadFile(MultipartFile file) throws Exception {
|
|
|
|
- try {
|
|
|
|
- // 上传文件路径
|
|
|
|
- String filePath = RuoYiConfig.getUploadPath();
|
|
|
|
- String thumbnailPath = "";
|
|
|
|
- // 上传并返回新文件名称
|
|
|
|
- String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
|
- String url = serverConfig.getUrl() + fileName;
|
|
|
|
- String fileType = FileUtils.getFileType(file);
|
|
|
|
- if ("video".equalsIgnoreCase(fileType)) {
|
|
|
|
- thumbnailPath = fileName.replace("/profile", RuoYiConfig.getProfile());
|
|
|
|
- int dotIndex = thumbnailPath.lastIndexOf(".");
|
|
|
|
- if (dotIndex != -1) {
|
|
|
|
- thumbnailPath = thumbnailPath.substring(0, dotIndex) + ".jpg";
|
|
|
|
- } else {
|
|
|
|
- thumbnailPath = thumbnailPath + ".jpg"; // 如果没有后缀,直接加 .jpg
|
|
|
|
- }
|
|
|
|
- FileUtils.screenShots(fileName.replace("/profile", RuoYiConfig.getProfile()), thumbnailPath, "00:00:01");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ("image".equalsIgnoreCase(fileType)) {
|
|
|
|
- //获取用户名
|
|
|
|
- String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
|
|
|
|
- // 原始文件
|
|
|
|
- if (fileName.contains("/profile/upload")) {
|
|
|
|
- fileName = fileName.replace("/profile/upload", "");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- File sourceFile = new File(filePath + fileName);
|
|
|
|
- //图片添加水印
|
|
|
|
- String watermarkFileName = "watermark_" + fileName;
|
|
|
|
- File destFile = new File(filePath + fileName);
|
|
|
|
- // 加水印
|
|
|
|
- ImageUtils.addWatermark(sourceFile, destFile, "@" + nickName, "次元时代-ACG爱好者社区");
|
|
|
|
- fileName = watermarkFileName;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- AjaxResult ajax = AjaxResult.success();
|
|
|
|
- ajax.put("url", url);
|
|
|
|
- ajax.put("fileName", fileName);
|
|
|
|
- ajax.put("newFileName", FileUtils.getName(fileName));
|
|
|
|
- ajax.put("originalFilename", file.getOriginalFilename());
|
|
|
|
- ajax.put("fileType", fileType);
|
|
|
|
- ajax.put("thumbnailPath", thumbnailPath);
|
|
|
|
- return ajax;
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- return AjaxResult.error(e.getMessage());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// /**
|
|
// /**
|
|
// * 通用上传请求(单个)
|
|
// * 通用上传请求(单个)
|
|
// */
|
|
// */
|
|
@@ -134,12 +83,11 @@ public class CommonController {
|
|
// String filePath = RuoYiConfig.getUploadPath();
|
|
// String filePath = RuoYiConfig.getUploadPath();
|
|
// String thumbnailPath = "";
|
|
// String thumbnailPath = "";
|
|
// // 上传并返回新文件名称
|
|
// // 上传并返回新文件名称
|
|
-// String fileName = OssUtils.uploadMultipartFile(file);
|
|
|
|
-// System.out.println(fileName);
|
|
|
|
-// String url = OssUtils.getOssFilePath(fileName);
|
|
|
|
|
|
+// String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
|
+// String url = serverConfig.getUrl() + fileName;
|
|
// String fileType = FileUtils.getFileType(file);
|
|
// String fileType = FileUtils.getFileType(file);
|
|
// if ("video".equalsIgnoreCase(fileType)) {
|
|
// if ("video".equalsIgnoreCase(fileType)) {
|
|
-// thumbnailPath = fileName;
|
|
|
|
|
|
+// thumbnailPath = fileName.replace("/profile", RuoYiConfig.getProfile());
|
|
// int dotIndex = thumbnailPath.lastIndexOf(".");
|
|
// int dotIndex = thumbnailPath.lastIndexOf(".");
|
|
// if (dotIndex != -1) {
|
|
// if (dotIndex != -1) {
|
|
// thumbnailPath = thumbnailPath.substring(0, dotIndex) + ".jpg";
|
|
// thumbnailPath = thumbnailPath.substring(0, dotIndex) + ".jpg";
|
|
@@ -148,6 +96,24 @@ public class CommonController {
|
|
// }
|
|
// }
|
|
// FileUtils.screenShots(fileName.replace("/profile", RuoYiConfig.getProfile()), thumbnailPath, "00:00:01");
|
|
// FileUtils.screenShots(fileName.replace("/profile", RuoYiConfig.getProfile()), thumbnailPath, "00:00:01");
|
|
// }
|
|
// }
|
|
|
|
+//
|
|
|
|
+// if ("image".equalsIgnoreCase(fileType)) {
|
|
|
|
+// //获取用户名
|
|
|
|
+// String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
|
|
|
|
+// // 原始文件
|
|
|
|
+// if (fileName.contains("/profile/upload")) {
|
|
|
|
+// fileName = fileName.replace("/profile/upload", "");
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// File sourceFile = new File(filePath + fileName);
|
|
|
|
+// //图片添加水印
|
|
|
|
+// String watermarkFileName = "watermark_" + fileName;
|
|
|
|
+// File destFile = new File(filePath + fileName);
|
|
|
|
+// // 加水印
|
|
|
|
+// ImageUtils.addWatermark(sourceFile, destFile, "@" + nickName, "次元时代-ACG爱好者社区");
|
|
|
|
+// fileName = watermarkFileName;
|
|
|
|
+// }
|
|
|
|
+//
|
|
// AjaxResult ajax = AjaxResult.success();
|
|
// AjaxResult ajax = AjaxResult.success();
|
|
// ajax.put("url", url);
|
|
// ajax.put("url", url);
|
|
// ajax.put("fileName", fileName);
|
|
// ajax.put("fileName", fileName);
|
|
@@ -161,6 +127,72 @@ public class CommonController {
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 通用上传请求(单个) OSS
|
|
|
|
+ */
|
|
|
|
+ @PostMapping("/upload")
|
|
|
|
+ public AjaxResult uploadFile(MultipartFile file) throws Exception {
|
|
|
|
+ try {
|
|
|
|
+ // 上传文件路径
|
|
|
|
+ String fileName = OssUtils.uploadMultipartFile(file);
|
|
|
|
+ System.out.println(fileName);
|
|
|
|
+ String fileNameResult = fileName.replace("https://cysd.oss-cn-shanghai.aliyuncs.com", fileUrl);
|
|
|
|
+ String thumbnailPath = "";
|
|
|
|
+ String fileType = FileUtils.getFileType(file);
|
|
|
|
+ if ("video".equalsIgnoreCase(fileType)) {
|
|
|
|
+ String tempThumbnailFile = System.getProperty("java.io.tmpdir") + File.separator + "thumbnail.jpg";
|
|
|
|
+
|
|
|
|
+ boolean screenshotSuccess = FileUtils.screenShots(fileNameResult, tempThumbnailFile, "00:00:01");
|
|
|
|
+ if (!screenshotSuccess) {
|
|
|
|
+ throw new RuntimeException("生成视频缩略图失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 上传缩略图到OSS
|
|
|
|
+ thumbnailPath = OssUtils.uploadFile(tempThumbnailFile);
|
|
|
|
+
|
|
|
|
+ // 删除临时缩略图文件
|
|
|
|
+ new File(tempThumbnailFile).delete();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ("image".equalsIgnoreCase(fileType)) {
|
|
|
|
+ //获取用户名
|
|
|
|
+ String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
|
|
|
|
+ // 下载源文件到本地临时目录
|
|
|
|
+ String tempSourceFile = System.getProperty("java.io.tmpdir") + File.separator + "source_" + FileUtils.getName(fileName);
|
|
|
|
+ OssUtils.downloadFile(fileName, tempSourceFile);
|
|
|
|
+
|
|
|
|
+ // 本地临时水印文件路径
|
|
|
|
+ String tempWatermarkFile = System.getProperty("java.io.tmpdir") + File.separator + "watermark_" + FileUtils.getName(fileName);
|
|
|
|
+ // 添加水印
|
|
|
|
+ ImageUtils.addWatermark(
|
|
|
|
+ new File(tempSourceFile),
|
|
|
|
+ new File(tempWatermarkFile),
|
|
|
|
+ "@" + nickName,
|
|
|
|
+ "次元时代-ACG爱好者社区"
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // 上传加水印的文件到OSS
|
|
|
|
+ fileName = OssUtils.uploadFile(tempWatermarkFile);
|
|
|
|
+
|
|
|
|
+ // 删除临时文件
|
|
|
|
+ new File(tempSourceFile).delete();
|
|
|
|
+ new File(tempWatermarkFile).delete();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String url = fileNameResult;
|
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
|
+ ajax.put("url", url);
|
|
|
|
+ ajax.put("fileName", fileNameResult);
|
|
|
|
+ ajax.put("newFileName", FileUtils.getName(fileNameResult));
|
|
|
|
+ ajax.put("originalFilename", file.getOriginalFilename());
|
|
|
|
+ ajax.put("fileType", fileType);
|
|
|
|
+ ajax.put("thumbnailPath", thumbnailPath.replace("https://cysd.oss-cn-shanghai.aliyuncs.com", fileUrl));
|
|
|
|
+ return ajax;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return AjaxResult.error(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 通用上传请求(多个)
|
|
* 通用上传请求(多个)
|
|
*/
|
|
*/
|