diff --git a/src/main/java/run/halo/app/controller/admin/api/RecoveryController.java b/src/main/java/run/halo/app/controller/admin/api/RecoveryController.java
index 228f8fd61..a9bd90e16 100644
--- a/src/main/java/run/halo/app/controller/admin/api/RecoveryController.java
+++ b/src/main/java/run/halo/app/controller/admin/api/RecoveryController.java
@@ -40,7 +40,7 @@ public class RecoveryController {
@ApiParam("This file content type should be json")
@RequestPart("file") MultipartFile file) {
if (optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false)) {
- throw new BadRequestException("You cannot migrate after blog installing");
+ throw new BadRequestException("不能在博客初始化完成之后迁移数据");
}
recoveryService.migrateFromV0_4_3(file);
diff --git a/src/main/java/run/halo/app/handler/file/AliYunFileHandler.java b/src/main/java/run/halo/app/handler/file/AliYunFileHandler.java
index 4649b0ac6..493a77958 100644
--- a/src/main/java/run/halo/app/handler/file/AliYunFileHandler.java
+++ b/src/main/java/run/halo/app/handler/file/AliYunFileHandler.java
@@ -114,7 +114,7 @@ public class AliYunFileHandler implements FileHandler {
try {
ossClient.deleteObject(new DeleteObjectsRequest(ossBucketName).withKey(key));
} catch (Exception e) {
- throw new FileOperationException("Failed to delete file " + key + " from AliYun", e);
+ throw new FileOperationException("附件 " + key + " 从阿里云删除失败", e);
} finally {
ossClient.shutdown();
}
diff --git a/src/main/java/run/halo/app/handler/file/LocalFileHandler.java b/src/main/java/run/halo/app/handler/file/LocalFileHandler.java
index d81454e0a..6180e8967 100644
--- a/src/main/java/run/halo/app/handler/file/LocalFileHandler.java
+++ b/src/main/java/run/halo/app/handler/file/LocalFileHandler.java
@@ -177,7 +177,7 @@ public class LocalFileHandler implements FileHandler {
try {
Files.delete(path);
} catch (IOException e) {
- throw new FileOperationException("Failed to delete " + key + " file", e);
+ throw new FileOperationException("附件 " + key + " 删除失败", e);
}
// Delete thumb if necessary
@@ -197,7 +197,7 @@ public class LocalFileHandler implements FileHandler {
log.warn("Thumbnail: [{}] way not exist", thumbnailPath.toString());
}
} catch (IOException e) {
- throw new FileOperationException("Failed to delete " + thumbnailName + " thumbnail", e);
+ throw new FileOperationException("附件缩略图 " + thumbnailName + " 删除失败", e);
}
}
diff --git a/src/main/java/run/halo/app/handler/file/SmmsFileHandler.java b/src/main/java/run/halo/app/handler/file/SmmsFileHandler.java
index 526abcb09..51e895cf9 100644
--- a/src/main/java/run/halo/app/handler/file/SmmsFileHandler.java
+++ b/src/main/java/run/halo/app/handler/file/SmmsFileHandler.java
@@ -50,7 +50,7 @@ public class SmmsFileHandler implements FileHandler {
if (!FileHandler.isImageType(file.getContentType())) {
log.error("Invalid extension: [{}]", file.getContentType());
- throw new FileOperationException("Invalid extension for file " + file.getOriginalFilename() + ". Only \"jpeg, jpg, png, gif, bmp\" files are supported");
+ throw new FileOperationException("不支持的文件类型,仅支持 \"jpeg, jpg, png, gif, bmp\" 格式的图片");
}
HttpHeaders headers = new HttpHeaders();
@@ -79,7 +79,7 @@ public class SmmsFileHandler implements FileHandler {
// Check status
if (mapResponseEntity.getStatusCode().isError()) {
log.error("Server response detail: [{}]", mapResponseEntity.toString());
- throw new FileOperationException("Smms server response error. status: " + mapResponseEntity.getStatusCodeValue());
+ throw new FileOperationException("SM.MS 服务状态异常,状态码: " + mapResponseEntity.getStatusCodeValue());
}
// Get smms response
@@ -88,7 +88,7 @@ public class SmmsFileHandler implements FileHandler {
// Check error
if (!isResponseSuccessfully(smmsResponse)) {
log.error("Smms response detail: [{}]", smmsResponse);
- throw new FileOperationException(smmsResponse == null ? "Smms response is null" : smmsResponse.getMsg()).setErrorData(smmsResponse);
+ throw new FileOperationException(smmsResponse == null ? "SM.MS 服务返回内容为空" : smmsResponse.getMsg()).setErrorData(smmsResponse);
}
// Get response data
@@ -128,7 +128,7 @@ public class SmmsFileHandler implements FileHandler {
if (responseEntity.getStatusCode().isError()) {
log.debug("Smms server response error: [{}]", responseEntity.toString());
- throw new FileOperationException("Smms server response error");
+ throw new FileOperationException("SM.MS 服务状态异常");
}
log.debug("Smms response detail: [{}]", responseEntity.getBody());
@@ -155,7 +155,7 @@ public class SmmsFileHandler implements FileHandler {
@Data
@ToString
@NoArgsConstructor
- static class SmmsResponse {
+ private static class SmmsResponse {
private String code;
@@ -168,7 +168,7 @@ public class SmmsFileHandler implements FileHandler {
@Data
@ToString(callSuper = true)
@NoArgsConstructor
- static class SmmsResponseData {
+ private static class SmmsResponseData {
private String filename;
diff --git a/src/main/java/run/halo/app/handler/file/UpYunFileHandler.java b/src/main/java/run/halo/app/handler/file/UpYunFileHandler.java
index 097f706e2..9445d497d 100644
--- a/src/main/java/run/halo/app/handler/file/UpYunFileHandler.java
+++ b/src/main/java/run/halo/app/handler/file/UpYunFileHandler.java
@@ -67,7 +67,7 @@ public class UpYunFileHandler implements FileHandler {
// Write file
boolean uploadSuccess = upYun.writeFile(upFilePath, file.getInputStream(), true, null);
if (!uploadSuccess) {
- throw new FileOperationException("Failed to upload file " + file.getOriginalFilename() + " to UpYun " + upFilePath);
+ throw new FileOperationException("上传附件 " + file.getOriginalFilename() + " 到又拍云失败" + upFilePath);
}
String filePath = StringUtils.removeEnd(ossDomain, "/") + upFilePath;
@@ -118,7 +118,7 @@ public class UpYunFileHandler implements FileHandler {
log.warn("Failed to delete file " + filePath + " from UpYun");
}
} catch (Exception e) {
- throw new FileOperationException("Failed to delete file " + key + " from UpYun", e);
+ throw new FileOperationException("附件从又拍云删除失败", e);
}
}
diff --git a/src/main/java/run/halo/app/service/impl/LinkServiceImpl.java b/src/main/java/run/halo/app/service/impl/LinkServiceImpl.java
index 9b1bf2e69..4ed7c2daa 100644
--- a/src/main/java/run/halo/app/service/impl/LinkServiceImpl.java
+++ b/src/main/java/run/halo/app/service/impl/LinkServiceImpl.java
@@ -86,7 +86,7 @@ public class LinkServiceImpl extends AbstractCrudService implemen
boolean exist = existByName(linkParam.getName());
if (exist) {
- throw new AlreadyExistsException("Link name " + linkParam.getName() + " has already existed").setErrorData(linkParam.getName());
+ throw new AlreadyExistsException("友情链接 " + linkParam.getName() + " 已存在").setErrorData(linkParam.getName());
}
return create(linkParam.convertTo());
diff --git a/src/main/java/run/halo/app/service/impl/RecoveryServiceImpl.java b/src/main/java/run/halo/app/service/impl/RecoveryServiceImpl.java
index 6e4aaed99..a83c2ebc0 100644
--- a/src/main/java/run/halo/app/service/impl/RecoveryServiceImpl.java
+++ b/src/main/java/run/halo/app/service/impl/RecoveryServiceImpl.java
@@ -128,7 +128,7 @@ public class RecoveryServiceImpl implements RecoveryService {
log.debug("Migrated posts: [{}]", posts);
}
} catch (IOException e) {
- throw new ServiceException("Failed to read multipart file " + file.getOriginalFilename(), e);
+ throw new ServiceException("备份文件 " + file.getOriginalFilename() + " 读取失败", e);
}
}
diff --git a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java
index 7fb995568..442dfaef2 100644
--- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java
+++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java
@@ -248,7 +248,7 @@ public class ThemeServiceImpl implements ThemeService {
if (themeId.equals(getActivatedThemeId())) {
// Prevent to delete the activated theme
- throw new BadRequestException("You can't delete the activated theme").setErrorData(themeId);
+ throw new BadRequestException("不能删除正在使用的主题").setErrorData(themeId);
}
try {
@@ -258,7 +258,7 @@ public class ThemeServiceImpl implements ThemeService {
// Delete theme cache
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
} catch (Exception e) {
- throw new ServiceException("Failed to delete theme folder", e).setErrorData(themeId);
+ throw new ServiceException("主题删除失败", e).setErrorData(themeId);
}
}
@@ -295,7 +295,7 @@ public class ThemeServiceImpl implements ThemeService {
return Collections.emptyList();
} catch (IOException e) {
- throw new ServiceException("Failed to read options file", e);
+ throw new ServiceException("读取主题配置文件失败", e);
}
}
@@ -456,7 +456,7 @@ public class ThemeServiceImpl implements ThemeService {
return add(themeTmpPath);
} catch (IOException | GitAPIException e) {
- throw new ServiceException("Failed to fetch theme from remote " + uri, e);
+ throw new ServiceException("主题拉取失败 " + uri, e);
} finally {
FileUtils.deleteFolderQuietly(tmpPath);
}
@@ -587,7 +587,7 @@ public class ThemeServiceImpl implements ThemeService {
log.debug("Download response: [{}]", downloadResponse.getStatusCode());
if (downloadResponse.getStatusCode().isError() || downloadResponse.getBody() == null) {
- throw new ServiceException("Failed to download " + zipUrl + ", status: " + downloadResponse.getStatusCode());
+ throw new ServiceException("下载失败 " + zipUrl + ", 状态码: " + downloadResponse.getStatusCode());
}
log.debug("Downloaded [{}]", zipUrl);
diff --git a/src/main/java/run/halo/app/service/impl/ThemeSettingServiceImpl.java b/src/main/java/run/halo/app/service/impl/ThemeSettingServiceImpl.java
index 7aa6cd8e2..b9f5cd0b5 100644
--- a/src/main/java/run/halo/app/service/impl/ThemeSettingServiceImpl.java
+++ b/src/main/java/run/halo/app/service/impl/ThemeSettingServiceImpl.java
@@ -105,7 +105,7 @@ public class ThemeSettingServiceImpl extends AbstractCrudService implemen
if (user.getExpireTime() != null && user.getExpireTime().after(now)) {
long seconds = TimeUnit.MILLISECONDS.toSeconds(user.getExpireTime().getTime() - now.getTime());
// If expired
- throw new ForbiddenException("You have been temporarily disabled,please try again " + HaloUtils.timeFormat(seconds) + " later").setErrorData(seconds);
+ throw new ForbiddenException("账号已被停用,请 " + HaloUtils.timeFormat(seconds) + " 后重试").setErrorData(seconds);
}
}
@@ -164,7 +164,7 @@ public class UserServiceImpl extends AbstractCrudService implemen
public User create(User user) {
// Check user
if (count() != 0) {
- throw new BadRequestException("This blog already exists a blogger");
+ throw new BadRequestException("当前博客已有用户");
}
User createdUser = super.create(user);
diff --git a/src/main/java/run/halo/app/utils/HaloUtils.java b/src/main/java/run/halo/app/utils/HaloUtils.java
index 21e0e41a4..93125eb49 100755
--- a/src/main/java/run/halo/app/utils/HaloUtils.java
+++ b/src/main/java/run/halo/app/utils/HaloUtils.java
@@ -1,31 +1,19 @@
package run.halo.app.utils;
-import cn.hutool.core.text.StrBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.io.*;
import java.net.InetAddress;
-import java.net.URL;
-import java.net.URLConnection;
import java.net.UnknownHostException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.Date;
import java.util.UUID;
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
/**
- *
- * 常用工具
- *
+ * Common utils
*
* @author ryanwang
* @date : 2017/12/22
@@ -165,187 +153,4 @@ public class HaloUtils {
}
return machineAddress.getHostAddress();
}
-
-// /**
-// * 获取备份文件信息
-// *
-// * @param dir dir
-// * @return List
-// */
-// public static List getBackUps(String dir) {
-// final StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home"));
-// srcPathStr.append("/halo/backup/");
-// srcPathStr.append(dir);
-// final File srcPath = new File(srcPathStr.toString());
-// final File[] files = srcPath.listFiles();
-// final List backupDtos = new ArrayList<>();
-// BackupDto backupDto;
-// // 遍历文件
-// if (null != files) {
-// for (File file : files) {
-// if (file.isFile()) {
-// if (StrUtil.equals(file.getName(), ".DS_Store")) {
-// continue;
-// }
-// backupDto = new BackupDto();
-// backupDto.setFileName(file.getName());
-// backupDto.setCreateAt(getCreateTime(file.getAbsolutePath()));
-// backupDto.setFileType(FileUtil.getType(file));
-// backupDto.setFileSize(parseSize(file.length()));
-// backupDto.setBackupType(dir);
-// backupDtos.add(backupDto);
-// }
-// }
-// }
-// return backupDtos;
-// }
-
-// /**
-// * 转换文件大小
-// *
-// * @param size size
-// * @return String
-// */
-// public static String parseSize(long size) {
-// if (size < CommonParamsEnum.BYTE.getValue()) {
-// return size + "B";
-// } else {
-// size = size / 1024;
-// }
-// if (size < CommonParamsEnum.BYTE.getValue()) {
-// return size + "KB";
-// } else {
-// size = size / 1024;
-// }
-// if (size < CommonParamsEnum.BYTE.getValue()) {
-// size = size * 100;
-// return size / 100 + "." + size % 100 + "MB";
-// } else {
-// size = size * 100 / 1024;
-// return size / 100 + "." + size % 100 + "GB";
-// }
-// }
-
- /**
- * 获取文件创建时间
- *
- * @param srcPath 文件绝对路径
- * @return 时间
- */
- public static Date getCreateTime(String srcPath) {
- try {
- BasicFileAttributes basicFileAttributes = Files.readAttributes(Paths.get(srcPath), BasicFileAttributes.class);
- return new Date(basicFileAttributes.creationTime().toMillis());
- } catch (IOException e) {
- throw new RuntimeException("Failed to open the " + srcPath + " file", e);
- }
- }
-
- /**
- * 获取文件长和宽
- *
- * @param file file
- * @return String
- */
- public static String getImageWh(File file) {
- try {
- final BufferedImage image = ImageIO.read(new FileInputStream(file));
- return image.getWidth() + "x" + image.getHeight();
- } catch (Exception e) {
- throw new RuntimeException("Failed to get read image file", e);
- }
- }
-
- /**
- * 导出为文件
- *
- * @param data 内容
- * @param filePath 保存路径
- * @param fileName 文件名
- */
- public static void postToFile(String data, String filePath, String fileName) throws IOException {
- FileWriter fileWriter = null;
- BufferedWriter bufferedWriter = null;
- try {
- final File file = new File(filePath);
- if (!file.exists()) {
- file.mkdirs();
- }
- fileWriter = new FileWriter(file.getAbsoluteFile() + "/" + fileName, true);
- bufferedWriter = new BufferedWriter(fileWriter);
- bufferedWriter.write(data);
- } catch (Exception e) {
- throw new RuntimeException("Failed to export file", e);
- } finally {
- if (null != bufferedWriter) {
- bufferedWriter.close();
- }
- if (null != fileWriter) {
- fileWriter.close();
- }
- }
- }
-
- /**
- * 百度主动推送
- *
- * @param blogUrl 博客地址
- * @param token 百度推送token
- * @param urls 文章路径
- * @return String
- */
- public static String baiduPost(String blogUrl, String token, String urls) {
- Assert.hasText(blogUrl, "blog url must not be blank");
- Assert.hasText(token, "token must not be blank");
- Assert.hasText(urls, "urls must not be blank");
-
- final StrBuilder url = new StrBuilder("http://data.zz.baidu.com/urls?site=");
- url.append(blogUrl);
- url.append("&token=");
- url.append(token);
-
- final StrBuilder result = new StrBuilder();
- PrintWriter out = null;
- BufferedReader in = null;
- try {
- // 建立URL之间的连接
- final URLConnection conn = new URL(url.toString()).openConnection();
- // 设置通用的请求属性
- conn.setRequestProperty("Host", "data.zz.baidu.com");
- conn.setRequestProperty("User-Agent", "curl/7.12.1");
- conn.setRequestProperty("Content-Length", "83");
- conn.setRequestProperty("Content-Type", "text/plain");
-
- // 发送POST请求必须设置如下两行
- conn.setDoInput(true);
- conn.setDoOutput(true);
-
- // 获取conn对应的输出流
- out = new PrintWriter(conn.getOutputStream());
- out.print(urls.trim());
- // 进行输出流的缓冲
- out.flush();
- // 通过BufferedReader输入流来读取Url的响应
- in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line;
- while ((line = in.readLine()) != null) {
- result.append(line);
- }
- } catch (Exception e) {
- throw new RuntimeException("Failed to push posts to baidu", e);
- } finally {
- try {
- if (null != out) {
- out.close();
- }
- if (null != in) {
- in.close();
- }
- } catch (IOException ex) {
- // Ignore this exception
- }
- }
- return result.toString();
- }
-
}