diff --git a/src/main/java/run/halo/app/controller/admin/api/ThemeController.java b/src/main/java/run/halo/app/controller/admin/api/ThemeController.java index 3cbd366f1..4734e1386 100644 --- a/src/main/java/run/halo/app/controller/admin/api/ThemeController.java +++ b/src/main/java/run/halo/app/controller/admin/api/ThemeController.java @@ -140,4 +140,9 @@ public class ThemeController { public void reload() { themeService.reload(); } + + @GetMapping(value = "activation/template/exists") + public BaseResponse exists(@RequestParam(value = "template") String template) { + return BaseResponse.ok(themeService.templateExists(template)); + } } diff --git a/src/main/java/run/halo/app/event/post/AbstractVisitEventListener.java b/src/main/java/run/halo/app/event/post/AbstractVisitEventListener.java index 5af630d9d..1724e2b66 100644 --- a/src/main/java/run/halo/app/event/post/AbstractVisitEventListener.java +++ b/src/main/java/run/halo/app/event/post/AbstractVisitEventListener.java @@ -1,8 +1,8 @@ package run.halo.app.event.post; -import cn.hutool.core.lang.Assert; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; +import org.springframework.util.Assert; import run.halo.app.service.base.BasePostService; import java.util.Map; 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 9dc1c6182..554499024 100644 --- a/src/main/java/run/halo/app/handler/file/AliYunFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/AliYunFileHandler.java @@ -1,13 +1,14 @@ package run.halo.app.handler.file; -import cn.hutool.core.lang.Assert; import com.aliyun.oss.OSS; import com.aliyun.oss.OSSClientBuilder; -import com.aliyun.oss.model.*; +import com.aliyun.oss.model.DeleteObjectsRequest; +import com.aliyun.oss.model.PutObjectResult; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; +import org.springframework.util.Assert; import org.springframework.web.multipart.MultipartFile; import run.halo.app.exception.FileOperationException; import run.halo.app.model.enums.AttachmentType; @@ -18,11 +19,11 @@ import run.halo.app.utils.FilenameUtils; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; -import java.util.Date; import java.util.Objects; /** * AliYun file handler. + * * @author MyFaith * @date 2019-04-04 00:06:13 */ @@ -81,7 +82,7 @@ public class AliYunFileHandler implements FileHandler { } return uploadResult; - } catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } finally { ossClient.shutdown(); diff --git a/src/main/java/run/halo/app/security/handler/DefaultAuthenticationFailureHandler.java b/src/main/java/run/halo/app/security/handler/DefaultAuthenticationFailureHandler.java index fa2aa4147..ada70d584 100644 --- a/src/main/java/run/halo/app/security/handler/DefaultAuthenticationFailureHandler.java +++ b/src/main/java/run/halo/app/security/handler/DefaultAuthenticationFailureHandler.java @@ -1,15 +1,14 @@ package run.halo.app.security.handler; -import run.halo.app.exception.HaloException; -import run.halo.app.model.support.BaseResponse; -import run.halo.app.utils.ExceptionUtils; -import run.halo.app.utils.JsonUtils; import cn.hutool.extra.servlet.ServletUtil; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; import org.springframework.util.Assert; import run.halo.app.exception.HaloException; +import run.halo.app.model.support.BaseResponse; +import run.halo.app.utils.ExceptionUtils; +import run.halo.app.utils.JsonUtils; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; diff --git a/src/main/java/run/halo/app/service/impl/JournalCommentServiceImpl.java b/src/main/java/run/halo/app/service/impl/JournalCommentServiceImpl.java index 40c580cac..5493b7968 100644 --- a/src/main/java/run/halo/app/service/impl/JournalCommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/JournalCommentServiceImpl.java @@ -1,11 +1,11 @@ package run.halo.app.service.impl; import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.lang.Assert; import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.stereotype.Service; +import org.springframework.util.Assert; import run.halo.app.exception.NotFoundException; import run.halo.app.model.dto.JournalDTO; import run.halo.app.model.entity.Journal; 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 94ddb0248..6e4aaed99 100644 --- a/src/main/java/run/halo/app/service/impl/RecoveryServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/RecoveryServiceImpl.java @@ -1,12 +1,12 @@ package run.halo.app.service.impl; -import cn.hutool.core.lang.Assert; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.FileCopyUtils; import org.springframework.web.multipart.MultipartFile; 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 db20bd359..579ab2b4c 100644 --- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java @@ -1,6 +1,5 @@ package run.halo.app.service.impl; -import cn.hutool.core.io.FileUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.eclipse.jgit.api.Git; @@ -28,7 +27,6 @@ import run.halo.app.model.support.HaloConst; import run.halo.app.model.support.ThemeFile; import run.halo.app.service.OptionService; import run.halo.app.service.ThemeService; -import run.halo.app.service.support.HaloMediaType; import run.halo.app.utils.FileUtils; import run.halo.app.utils.FilenameUtils; import run.halo.app.utils.HaloUtils; @@ -248,7 +246,7 @@ public class ThemeServiceImpl implements ThemeService { try { // Delete the folder - FileUtil.del(Paths.get(themeProperty.getThemePath())); + FileUtils.del(Paths.get(themeProperty.getThemePath())); // Delete theme cache eventPublisher.publishEvent(new ThemeUpdatedEvent(this)); @@ -329,6 +327,16 @@ public class ThemeServiceImpl implements ThemeService { return activatedTheme; } + /** + * Sets activated theme. + * + * @param activatedTheme activated theme + */ + private void setActivatedTheme(@Nullable ThemeProperty activatedTheme) { + this.activatedTheme = activatedTheme; + this.activatedThemeId = Optional.ofNullable(activatedTheme).map(ThemeProperty::getId).orElse(null); + } + @Override public ThemeProperty activateTheme(String themeId) { // Check existence of the theme @@ -513,16 +521,6 @@ public class ThemeServiceImpl implements ThemeService { return Files.createTempDirectory("halo"); } - /** - * Sets activated theme. - * - * @param activatedTheme activated theme - */ - private void setActivatedTheme(@Nullable ThemeProperty activatedTheme) { - this.activatedTheme = activatedTheme; - this.activatedThemeId = Optional.ofNullable(activatedTheme).map(ThemeProperty::getId).orElse(null); - } - /** * Lists theme files as tree view. * diff --git a/src/main/java/run/halo/app/utils/FileUtils.java b/src/main/java/run/halo/app/utils/FileUtils.java index 30780f693..d7aac7685 100644 --- a/src/main/java/run/halo/app/utils/FileUtils.java +++ b/src/main/java/run/halo/app/utils/FileUtils.java @@ -1,5 +1,6 @@ package run.halo.app.utils; +import cn.hutool.core.io.IORuntimeException; import lombok.extern.slf4j.Slf4j; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; @@ -259,4 +260,44 @@ public class FileUtils { log.warn("Failed to delete " + deletingPath); } } + + /** + * 删除文件或者文件夹 + * + * @param path path + * @return boolean + * @throws IORuntimeException IORuntimeException + */ + public static boolean del(Path path) throws IORuntimeException { + if (Files.notExists(path)) { + return true; + } + try { + if (Files.isDirectory(path)) { + Files.walkFileTree(path, new SimpleFileVisitor() { + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { + if (e == null) { + Files.delete(dir); + return FileVisitResult.CONTINUE; + } else { + throw e; + } + } + }); + } else { + Files.delete(path); + } + } catch (IOException e) { + throw new IORuntimeException(e); + } + return true; + } }