mirror of https://github.com/halo-dev/halo
Attempt to resolve issue: #110
parent
e4a47147b3
commit
783162ffc9
|
@ -2,9 +2,9 @@ package cc.ryanc.halo.service.impl;
|
||||||
|
|
||||||
import cc.ryanc.halo.logging.Logger;
|
import cc.ryanc.halo.logging.Logger;
|
||||||
import cc.ryanc.halo.model.domain.Attachment;
|
import cc.ryanc.halo.model.domain.Attachment;
|
||||||
import cc.ryanc.halo.model.support.QiNiuPutSet;
|
|
||||||
import cc.ryanc.halo.model.enums.AttachLocationEnum;
|
import cc.ryanc.halo.model.enums.AttachLocationEnum;
|
||||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||||
|
import cc.ryanc.halo.model.support.QiNiuPutSet;
|
||||||
import cc.ryanc.halo.repository.AttachmentRepository;
|
import cc.ryanc.halo.repository.AttachmentRepository;
|
||||||
import cc.ryanc.halo.service.AttachmentService;
|
import cc.ryanc.halo.service.AttachmentService;
|
||||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||||
|
@ -260,8 +260,8 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Long>
|
||||||
public Map<String, String> attachQiNiuUpload(MultipartFile file, HttpServletRequest request) {
|
public Map<String, String> attachQiNiuUpload(MultipartFile file, HttpServletRequest request) {
|
||||||
final Map<String, String> resultMap = new HashMap<>(7);
|
final Map<String, String> resultMap = new HashMap<>(7);
|
||||||
try {
|
try {
|
||||||
// TODO Dynamically set this zone of qiniuyun (七牛云上传附件失败 #110)
|
// TODO Wait for testing (七牛云上传附件失败 #110)
|
||||||
final Configuration cfg = new Configuration(Zone.zone0());
|
final Configuration cfg = new Configuration(HaloUtils.getDefaultQiniuZone());
|
||||||
final String key = Md5Util.getMD5Checksum(file);
|
final String key = Md5Util.getMD5Checksum(file);
|
||||||
final String accessKey = OPTIONS.get("qiniu_access_key");
|
final String accessKey = OPTIONS.get("qiniu_access_key");
|
||||||
final String secretKey = OPTIONS.get("qiniu_secret_key");
|
final String secretKey = OPTIONS.get("qiniu_secret_key");
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package cc.ryanc.halo.utils;
|
package cc.ryanc.halo.utils;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.support.BackupDto;
|
|
||||||
import cc.ryanc.halo.model.support.Theme;
|
|
||||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||||
import cc.ryanc.halo.model.enums.CommonParamsEnum;
|
import cc.ryanc.halo.model.enums.CommonParamsEnum;
|
||||||
|
import cc.ryanc.halo.model.support.BackupDto;
|
||||||
|
import cc.ryanc.halo.model.support.Theme;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.text.StrBuilder;
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.qiniu.common.Zone;
|
||||||
import io.github.biezhi.ome.OhMyEmail;
|
import io.github.biezhi.ome.OhMyEmail;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
|
|
||||||
|
@ -53,6 +55,40 @@ public class HaloUtils {
|
||||||
return DEFAULT_PAGE_SIZE;
|
return DEFAULT_PAGE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets default qiniuyun zone.
|
||||||
|
*
|
||||||
|
* @return qiniuyun zone
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public static Zone getDefaultQiniuZone() {
|
||||||
|
Zone zone;
|
||||||
|
// Get zone from setting
|
||||||
|
String qiniuZone = OPTIONS.get("qiniu_zone");
|
||||||
|
switch (qiniuZone) {
|
||||||
|
case "z0":
|
||||||
|
zone = Zone.zone0();
|
||||||
|
break;
|
||||||
|
case "z1":
|
||||||
|
zone = Zone.zone1();
|
||||||
|
break;
|
||||||
|
case "z2":
|
||||||
|
zone = Zone.zone2();
|
||||||
|
break;
|
||||||
|
case "na0":
|
||||||
|
zone = Zone.zoneNa0();
|
||||||
|
break;
|
||||||
|
case "as0":
|
||||||
|
zone = Zone.zoneAs0();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Default is detecting zone automatically
|
||||||
|
zone = Zone.autoZone();
|
||||||
|
}
|
||||||
|
|
||||||
|
return zone;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取备份文件信息
|
* 获取备份文件信息
|
||||||
*
|
*
|
||||||
|
@ -298,7 +334,7 @@ public class HaloUtils {
|
||||||
Assert.hasText(smtpHost, "SMTP host config must not be blank");
|
Assert.hasText(smtpHost, "SMTP host config must not be blank");
|
||||||
Assert.hasText(userName, "Email username must not be blank");
|
Assert.hasText(userName, "Email username must not be blank");
|
||||||
Assert.hasText(password, "Email password must not be blank");
|
Assert.hasText(password, "Email password must not be blank");
|
||||||
|
|
||||||
final Properties properties = OhMyEmail.defaultConfig(false);
|
final Properties properties = OhMyEmail.defaultConfig(false);
|
||||||
properties.setProperty("mail.smtp.host", smtpHost);
|
properties.setProperty("mail.smtp.host", smtpHost);
|
||||||
OhMyEmail.config(properties, userName, password);
|
OhMyEmail.config(properties, userName, password);
|
||||||
|
|
Loading…
Reference in New Issue