初始化前端目录
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
package com.mini.capi.sys.Api;
|
||||
|
||||
import com.mini.capi.biz.service.MailReceivedService;
|
||||
import com.mini.capi.biz.service.MailSentService;
|
||||
import com.mini.capi.config.TokenBean;
|
||||
import com.mini.capi.model.ApiResult;
|
||||
import com.mini.capi.sys.service.DbService;
|
||||
import com.mini.capi.sys.service.DockerService;
|
||||
import com.mini.capi.sys.service.HostService;
|
||||
import com.mini.capi.utils.FileUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
@RestController
|
||||
@@ -28,6 +35,38 @@ public class apiController {
|
||||
private DockerService dockerService;
|
||||
|
||||
|
||||
@Resource
|
||||
private MailReceivedService mailReceiveService;
|
||||
|
||||
@Resource
|
||||
private MailSentService mailSendService;
|
||||
|
||||
|
||||
@GetMapping("/mailReceive")
|
||||
public ApiResult<?> mailReceive(String token) {
|
||||
if (tokenBean.isValidToken(token)) {
|
||||
return ApiResult.error(401, "无效的访问令牌");
|
||||
}
|
||||
mailReceiveService.receiveUnreadMail();
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/mailSend")
|
||||
public ApiResult<?> mailSend(String token, String to, String cc, String subject, String content, String filePath) {
|
||||
if (tokenBean.isValidToken(token)) {
|
||||
return ApiResult.error(401, "无效的访问令牌");
|
||||
}
|
||||
String[] toAddresses = to.split(",");
|
||||
// 解析抄送(可选,空则为null)
|
||||
String[] ccAddresses = cc != null && !cc.trim().isEmpty() ? cc.split(",") : null;
|
||||
MultipartFile[] files = FileUtils.getMultipartFiles(filePath);
|
||||
// 调用发送服务
|
||||
mailSendService.sendMail(toAddresses, ccAddresses, subject, content, files);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取容器列表
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.mini.capi.sys.controller;
|
||||
|
||||
import com.mini.capi.biz.service.MailReceivedService;
|
||||
import com.mini.capi.biz.service.MailSentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -17,10 +17,10 @@ import java.util.Map;
|
||||
@RequestMapping("/api/mail")
|
||||
public class MailController {
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private MailReceivedService mailReceiveService;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private MailSentService mailSendService;
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mini.capi.utils;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
@@ -75,4 +76,80 @@ public class FileUtils {
|
||||
throw new RuntimeException("获取文件大小失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static MultipartFile[] getMultipartFiles(String filePath) {
|
||||
// 1. 校验路径合法性
|
||||
if (filePath == null || filePath.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("文件路径不能为空");
|
||||
}
|
||||
File dir = new File(filePath);
|
||||
if (!dir.exists()) {
|
||||
throw new IllegalArgumentException("目录不存在:" + filePath);
|
||||
}
|
||||
if (!dir.isDirectory()) {
|
||||
throw new IllegalArgumentException("路径不是目录:" + filePath);
|
||||
}
|
||||
|
||||
// 2. 筛选目录下的所有文件(排除子目录)
|
||||
File[] localFiles = dir.listFiles(File::isFile);
|
||||
if (localFiles == null || localFiles.length == 0) {
|
||||
return new MultipartFile[0];
|
||||
}
|
||||
|
||||
// 3. 包装本地File为MultipartFile并组装数组
|
||||
MultipartFile[] result = new MultipartFile[localFiles.length];
|
||||
for (int i = 0; i < localFiles.length; i++) {
|
||||
File file = localFiles[i];
|
||||
result[i] = new MultipartFile() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return file.getName(); // 文件名(与原始文件名一致,满足基础场景)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOriginalFilename() {
|
||||
return file.getName(); // 原始文件名(本地文件即自身文件名)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
// 推断文件MIME类型,失败时返回默认二进制类型
|
||||
try {
|
||||
return Files.probeContentType(file.toPath());
|
||||
} catch (IOException e) {
|
||||
return "application/octet-stream";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return file.length() == 0; // 空文件判断(大小为0)
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return file.length(); // 文件大小(字节)
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() throws IOException {
|
||||
return Files.readAllBytes(file.toPath()); // 读取文件字节数组
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return Files.newInputStream(file.toPath()); // 获取文件输入流
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferTo(File dest) throws IOException, IllegalStateException {
|
||||
Files.copy(file.toPath(), dest.toPath()); // 复制文件到目标路径
|
||||
}
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,7 +1,16 @@
|
||||
package com.mini.capi.utils;
|
||||
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.file.Files;
|
||||
|
||||
|
||||
public class vF {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user