支持利用 逗号分隔 设置多个 url 附件

pull/47/head
sky.huang 1 year ago
parent 5f12b96c19
commit 107db5548f

@ -1,6 +1,7 @@
package com.java3y.austin.handler.handler.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
@ -23,7 +24,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.File;
import java.util.Objects;
import java.util.List;
/**
*
@ -56,9 +57,9 @@ public class EmailHandler extends BaseHandler implements Handler {
EmailContentModel emailContentModel = (EmailContentModel) taskInfo.getContentModel();
MailAccount account = getAccountConfig(taskInfo.getSendAccount());
try {
File file = StrUtil.isNotBlank(emailContentModel.getUrl()) ? AustinFileUtils.getRemoteUrl2File(dataPath, emailContentModel.getUrl()) : null;
String result = Objects.isNull(file) ? MailUtil.send(account, taskInfo.getReceiver(), emailContentModel.getTitle(), emailContentModel.getContent(), true) :
MailUtil.send(account, taskInfo.getReceiver(), emailContentModel.getTitle(), emailContentModel.getContent(), true, file);
List<File> files = StrUtil.isNotBlank(emailContentModel.getUrl()) ? AustinFileUtils.getRemoteUrl2File(dataPath, StrUtil.split(emailContentModel.getUrl(), StrUtil.COMMA)) : null;
String result = CollUtil.isEmpty(files) ? MailUtil.send(account, taskInfo.getReceiver(), emailContentModel.getTitle(), emailContentModel.getContent(), true) :
MailUtil.send(account, taskInfo.getReceiver(), emailContentModel.getTitle(), emailContentModel.getContent(), true, files.toArray(new File[files.size()]));
} catch (Exception e) {
log.error("EmailHandler#handler fail!{},params:{}", Throwables.getStackTraceAsString(e), taskInfo);
return false;

@ -7,6 +7,9 @@ import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @author 3y
@ -37,4 +40,22 @@ public class AustinFileUtils {
return null;
}
/**
* File
*
* @param path
* @param remoteUrls cdn/oss访
* @return
*/
public static List<File> getRemoteUrl2File(String path, Collection<String> remoteUrls) {
List<File> files = new ArrayList<>();
remoteUrls.forEach(remoteUrl -> {
File file = getRemoteUrl2File(path, remoteUrl);
if (file != null) {
files.add(file);
}
});
return files;
}
}

Loading…
Cancel
Save